-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ring.js
79 lines (70 loc) · 1.58 KB
/
Ring.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class Ring {
constructor(posX, posY, diameter) {
this.x = posX;
this.y = posY;
this.diameter = diameter;
this.radius = this.diameter / 2;
this.capacity = 2 * floor(random(3, 12));
this.angle = 360 / this.capacity;
this.shapes = [];
this.forms = [];
this.clockwise = randomSelectTwo();
this.inc = (floor(random(3)) + 1) / 100;
this.speed = this.clockwise ? this.inc : -this.inc;
this.counter = 0;
}
allocateShapes() {
for (let i = 0; i < this.capacity; i++) {
this.shapes.push(new Shape(0, 0));
}
}
allocateForms() {
for (let i = 0; i < this.capacity; i++) {
this.forms.push(new Form(0, 0));
}
}
render() {
noFill();
stroke(PALETTE[0]);
push();
translate(width / 2, height / 2);
ellipse(this.x, this.y, this.diameter);
pop();
}
renderShapes() {
push();
this.shapes.forEach((shape, index) => {
push();
translate(width / 2, height / 2);
rotate(this.angle * index);
this.animate();
translate(0, this.radius);
shape.render();
pop();
});
pop();
}
renderForms() {
this.forms.forEach((form, index) => {
push();
translate(form.x, form.y);
rotate(this.angle * index);
this.animate();
translate(0, this.radius);
applyTransformation(form.transform, form.counter);
form.render();
form.counter += form.inc;
pop();
});
}
animate() {
rotate((this.counter += this.speed));
}
grow(inc) {
this.diameter += inc;
this.radius += inc / 2;
}
update() {
// TODO
}
}