-
Notifications
You must be signed in to change notification settings - Fork 0
/
mothWings.js
49 lines (35 loc) · 1.03 KB
/
mothWings.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
// Based on https://www.youtube.com/watch?v=O_0fRV4MTZo
let yOffset = 0;
function setup() {
createCanvas(200, 200);
stroke(255);
strokeWeight(1);
fill(255, 50);
}
function drawWingPoint(a, xOffset, isRight) {
const n = noise(xOffset, yOffset);
const r = sin(2*a) * map(n, 0, 1, 50, 125); // use perlin noise plus a rose
const x = r * cos(a);
// Multiplying by sine of a factor of the frame count makes it flap.
const y = sin(frameCount / 0.00001) * r * sin(a);
vertex(x, y);
return xOffset + (isRight ? 0.1 : -0.1);
}
function draw() {
background(51);
translate(width/2, height/2);
rotate(PI / 2); // hack to make the moth right side up
const incr = PI / 100;
beginShape();
// right wing
let xOffset = 0;
for (let a = -PI/2; a < PI/2; a += incr) {
xOffset = drawWingPoint(a, xOffset, true);
}
// left wing
for (let a = PI/2; a < 3*PI/2; a += incr) {
xOffset = drawWingPoint(a, xOffset, false);
}
endShape();
yOffset += 0.1;
}