-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
52 lines (46 loc) · 1.2 KB
/
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
51
52
let cnv;
let radius = 15;
let vertices = 0;
let inc;
let waveHeight = 10;
let waveFreq = 0;
let wave = 0;
let period = 1;
let polygonNum = 30;
function setup() {
// put setup code here
cnv = createCanvas(innerWidth, innerHeight);
cnv.parent('p5Sketch');
inc = PI / 30;
}
function draw() {
// put drawing code here
background(0);
// fill(255, 0, 0);
noFill();
stroke(255);
strokeWeight(2);
vertices = document.getElementById('vertices').value;
period = document.getElementById('freq').value;
waveHeight = document.getElementById('height').value;
polygonNum = document.getElementById('number').value;
for (var i = 0; i < polygonNum; i++) {
waveFreq = map(i, 0, polygonNum, 0, TWO_PI * period);
let y = (height/2) + (sin(wave + waveFreq) * waveHeight);
Polygon(vertices, radius * i, 5 * i , width/2, y);
}
wave += inc;
}
function Polygon(vert, r, offset, posX, posY) {
beginShape(POINTS);
for (var i = 0; i < vert; i++) {
let angle = map(i, 0, vert, 0 + offset, TWO_PI + offset);
let x = cos(angle) * r + posX;
let y = sin(angle) * (r / 2) + posY;
vertex(x, y);
}
endShape(CLOSE);
}
function windowResize() {
resizeCanvas(innerWidth, innerHeight);
}