-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathday_21.js
58 lines (49 loc) · 1.12 KB
/
day_21.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
53
54
55
56
57
58
// (c) 2021 Joseph HENRY
// This code is licensed under MIT license (see LICENSE for details)
// Min and max values of x
const MIN_VALUE = 10;
const MAX_VALUE = 200;
/**
* Main draw function, the offset controls the animation
*/
function DRAW(x, offset) {
// Normalized value from 0 to 1 for a call with x
const norma = map(x, MIN_VALUE, MAX_VALUE, 0, 1);
push();
rotate(norma * TWO_PI + offset + cos(x / 100 + offset) * HALF_PI);
strokeWeight(x / 20);
noFill();
stroke(255, 80);
ellipse(0, 0, x, x * 2);
stroke(255, 153, 0, (1 - norma) * 255);
strokeWeight(norma * 50);
point(x, norma * x + cos(offset) * 50);
rotate(PI);
point(x, norma * x + sin(offset) * 50);
pop();
}
/**
* From : https://genuary2021.github.io/prompts#jan15
*/
function f(x, offset) {
if (x < MIN_VALUE) return;
DRAW(x, offset);
f(1 * x / 4, offset);
f(2 * x / 4, offset);
f(3 * x / 4, offset);
}
let offset = 0;
function setup() {
createCanvas(500, 500);
}
function draw() {
background("#003344");
translate(width / 2, height / 2);
f(MAX_VALUE, offset);
offset += 0.02;
}