-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathday_1.js
174 lines (145 loc) · 2.91 KB
/
day_1.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// (c) 2023 Joseph HENRY
// This code is licensed under MIT license (see LICENSE for details)
function setLineDash(list) {
drawingContext.setLineDash(list);
}
function easeInOutQuint(x) {
return x < 0.5 ? 16 * x * x * x * x * x : 1 - pow(-2 * x + 2, 5) / 2;
}
function easeInOutQuad(x) {
return x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2;
}
function bezierWithHandles(x1, y1, x2, y2, x3, y3, x4, y4) {
noFill();
stroke("#2f4858");
strokeWeight(2);
bezier(x1, y1, x2, y2, x3, y3, x4, y4);
setLineDash([4, 2, 4]);
strokeWeight(2);
stroke("#df8b4a");
line(x1, y1, x2, y2);
line(x3, y3, x4, y4);
setLineDash([]);
strokeWeight(10);
stroke("#4a5577");
point(x1, y1);
point(x4, y4);
strokeWeight(4);
stroke("#b15f83");
fill("#dfe0df");
circle(x2, y2, 6);
circle(x3, y3, 6);
}
function infiniteLoop(x, y, radius, space, roundFactor) {
push();
translate(x, y);
const cy = space / 2 + radius;
const cyDist = cy * 2 * roundFactor;
const bxOff = 0;
// Circle dashed contour
setLineDash([2, 4]);
stroke("#9eb0a2");
fill("#92BCD744");
circle(0, -cy, radius * 2);
circle(0, cy, radius * 2);
setLineDash([]);
// Middle
bezierWithHandles(
bxOff - radius,
cy,
bxOff - radius,
cy - cyDist,
radius,
-cy + cyDist,
radius,
-cy
);
bezierWithHandles(
bxOff + radius,
cy,
bxOff + radius,
cy - cyDist,
-radius,
-cy + cyDist,
-radius,
-cy
);
const loopRadius = radius * roundFactor;
// Bottom loop
bezierWithHandles(
bxOff + radius,
cy,
bxOff + radius,
cy + loopRadius,
bxOff + loopRadius,
cy + radius,
bxOff,
cy + radius
);
bezierWithHandles(
bxOff - radius,
cy,
bxOff - radius,
cy + loopRadius,
bxOff - loopRadius,
cy + radius,
bxOff,
cy + radius
);
// Top loop
bezierWithHandles(
radius,
-cy,
radius,
-cy - loopRadius,
loopRadius,
-cy - radius,
0,
-cy - radius
);
bezierWithHandles(
-radius,
-cy,
-radius,
-cy - loopRadius,
-loopRadius,
-cy - radius,
0,
-cy - radius
);
// Circle center points
strokeWeight(5);
stroke("#4a5577");
point(0, -cy);
point(0, cy);
pop();
}
let timeValue = 0;
function setup() {
createCanvas(400, 400);
}
function draw() {
background("#dfe0df");
translate(width / 2, height / 2);
const offset = (cos(timeValue * 2) + 1) / 2.0;
const offsetNext = (cos(timeValue * 2 + QUARTER_PI) + 1) / 2.0;
const rotateFactor = Math.floor(timeValue) + easeInOutQuint(timeValue % 1);
scale(1 + offset * 0.2);
rotate(rotateFactor * QUARTER_PI);
infiniteLoop(
0,
0,
50 + offsetNext * 10,
easeInOutQuad(offsetNext) * 80,
easeInOutQuint(offset)
);
rotate(HALF_PI);
infiniteLoop(
0,
0,
50 + offset * 10,
easeInOutQuad(offset) * offset * 60,
easeInOutQuint(offset)
);
timeValue += 0.01;
}