-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathday_4.js
66 lines (49 loc) · 1.24 KB
/
day_4.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
59
60
61
62
63
64
65
// (c) 2021 Joseph HENRY
// This code is licensed under MIT license (see LICENSE for details)
/**
* Bubble shape (like conversation icon)
*/
function bubble(x, y, size, rotation) {
noFill();
stroke(255);
strokeWeight(5);
push();
translate(x, y);
rotate(rotation);
arc(0, 0, size, size, HALF_PI, 0);
const half = size / 2;
line(half, 0, half, half);
line(0, half, half, half);
pop();
}
/**
* Rotating bubbles with gap
*/
function bubbles(x, y, size, rotation, offset) {
const gap = (cos(offset) + 2) * 20;
let i = 0;
for (let radius = size; radius > 0; radius -= gap) {
const rotationOffset = sin(offset * 2 + i * 0.1) * TWO_PI;
bubble(x, y, radius, rotation + rotationOffset);
i++;
}
}
// Size of the bubbles
const size = 150;
const gap = 10;
// Animation offset
let offset = 0;
function setup() {
createCanvas(500, 500);
}
function draw() {
background("#003344");
translate(width / 2, height / 2);
const bOffset = gap + size / 2;
// Symmetry is here!
bubbles(-bOffset, -bOffset, size, 0, offset);
bubbles(bOffset, -bOffset, size, HALF_PI, offset);
bubbles(-bOffset, bOffset, size, -HALF_PI, offset);
bubbles(bOffset, bOffset, size, PI, offset);
offset += 0.01;
}