77 lines
1.6 KiB
HTML
Executable File
77 lines
1.6 KiB
HTML
Executable File
<DOCTYPE! html>
|
|
<html>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js"></script>
|
|
|
|
|
|
<script>
|
|
class dot{
|
|
constructor(x, y){
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
}
|
|
|
|
class circle{
|
|
constructor(cx, cy, r, a){
|
|
this.cx = cx;
|
|
this.cy = cy;
|
|
this.r = r;
|
|
this.a = a;
|
|
}
|
|
}
|
|
|
|
let time = 0;
|
|
let wave = [];
|
|
|
|
let slider;
|
|
|
|
function setup() {
|
|
createCanvas(900, 800);
|
|
slider = createSlider(1, 50, 5);
|
|
}
|
|
|
|
function draw() {
|
|
background(41);
|
|
translate(250, height/2);
|
|
|
|
let x = 0;
|
|
let y = 0;
|
|
|
|
for (let i = 0; i < slider.value(); i++) {
|
|
let prevx = x;
|
|
let prevy = y;
|
|
|
|
let n = i * 2 + 1;
|
|
let radius = 100 * (4 / (n * PI));
|
|
x += radius * cos(n * time);
|
|
y += radius * sin(n * time);
|
|
|
|
stroke(255, 100);
|
|
noFill();
|
|
ellipse(prevx, prevy, radius * 2);
|
|
|
|
//fill(255);
|
|
stroke(255);
|
|
line(prevx, prevy, x, y);
|
|
//ellipse(x, y, 8);
|
|
}
|
|
wave.unshift(y);
|
|
|
|
translate(200, 0);
|
|
line(x - 200, y, 0, wave[0]);
|
|
beginShape();
|
|
noFill();
|
|
for (let i = 0; i < wave.length; i++) {
|
|
vertex(i, wave[i]);
|
|
}
|
|
endShape();
|
|
|
|
time += 0.02;
|
|
|
|
if (wave.length > 450) {
|
|
wave.pop();
|
|
}
|
|
}
|
|
</script>
|
|
</html> |