-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcentric-zoom.js
More file actions
90 lines (71 loc) · 2.05 KB
/
Copy pathconcentric-zoom.js
File metadata and controls
90 lines (71 loc) · 2.05 KB
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
const canvasSketch = require("canvas-sketch");
const settings = {
dimensions: [2048, 2048],
animate: true,
};
const NUM_CIRCLES = 24;
const BASE_RADIUS = 900;
const ZOOM_SPEED = 0.6;
const LINE_WIDTH = 3;
const palette = [
"#264653",
"#2a9d8f",
"#e9c46a",
"#f4a261",
"#e76f51",
"#606c38",
"#283618",
"#dda15e",
];
const sketch = () => {
return ({ context: ctx, width, height, time }) => {
ctx.fillStyle = "#0a0a0a";
ctx.fillRect(0, 0, width, height);
const cx = width / 2;
const cy = height / 2;
const cycle = (time * ZOOM_SPEED) % 1;
for (let i = 0; i < NUM_CIRCLES; i++) {
const t = (i + cycle) / NUM_CIRCLES;
const radius = BASE_RADIUS * t;
if (radius < 2) continue;
const alpha = Math.sin(t * Math.PI) * 0.8 + 0.2;
const colorIdx = i % palette.length;
const color = palette[colorIdx];
const wobble = Math.sin(time * 1.2 + i * 0.7) * 8 * t;
const wobbleY = Math.cos(time * 0.9 + i * 0.5) * 8 * t;
ctx.beginPath();
ctx.ellipse(
cx + wobble,
cy + wobbleY,
radius,
radius * (0.95 + 0.05 * Math.sin(time + i)),
(time * 0.1 + i * 0.05),
0,
Math.PI * 2
);
ctx.strokeStyle = color;
ctx.globalAlpha = alpha;
ctx.lineWidth = LINE_WIDTH + t * 4;
ctx.stroke();
}
ctx.globalAlpha = 1;
for (let ring = 0; ring < 3; ring++) {
const ringCycle = ((time * ZOOM_SPEED * (0.5 + ring * 0.3)) + ring * 0.33) % 1;
for (let i = 0; i < NUM_CIRCLES; i++) {
const t = (i + ringCycle) / NUM_CIRCLES;
const radius = BASE_RADIUS * 0.6 * t;
if (radius < 1) continue;
const alpha = Math.sin(t * Math.PI) * 0.3;
if (alpha <= 0) continue;
ctx.beginPath();
ctx.arc(cx, cy, radius, 0, Math.PI * 2);
ctx.strokeStyle = palette[(i + ring * 3) % palette.length];
ctx.globalAlpha = alpha;
ctx.lineWidth = 1 + t * 2;
ctx.stroke();
}
}
ctx.globalAlpha = 1;
};
};
canvasSketch(sketch, settings);