-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
50 lines (42 loc) · 940 Bytes
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
angle = 0;
wave = [];
let input, button, greeting;
function setup() {
createCanvas(windowWidth, windowHeight);
title = createElement('h1','Fourier Series');
title.position(560,1)
n_value = createElement('h2', 'Enter N value: ');
n_value.position(20, 65);
input = createInput();
input.position(20, 125);
}
function draw() {
background(255);
translate(200,360);
x = 0;
y = 0;
for(let i=0; i<input.value(); i++){
prevx = x;
prevy = y;
let n = 2*i + 1;
let radius = 5 * ( 4 / n * PI) ;
x += radius * cos(n * angle);
y += radius * sin(n * angle);
noFill();
stroke(0,120);
ellipse(prevx,prevy,radius * 2)
line(prevx,prevy,x,y);
// ellipse(x, y, 8);
}
wave.unshift(y)
translate(150,0);
line(x-150,y,0,wave[0])
stroke(0)
beginShape();
noFill();
for(let i = 0; i<wave.length; i++){
vertex(i,wave[i]);
}
endShape();
angle += 0.03;
}