-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbongocat.ts
112 lines (95 loc) · 2.87 KB
/
bongocat.ts
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
// Inspired By
// https://codepen.io/abeatrize/pen/LJqYey
// Bongo Cat originally created by @StrayRogue and @DitzyFlama
const ID = "bongo-cat";
const s = (selector: string) => `#${ID} ${selector}`;
const notes = document.querySelectorAll(".note");
for (let note of notes) {
note?.parentElement?.appendChild(note.cloneNode(true));
note?.parentElement?.appendChild(note.cloneNode(true));
}
const music = { note: s(".music .note") };
const cat = {
pawRight: {
up: s(".paw-right .up"),
down: s(".paw-right .down"),
},
pawLeft: {
up: s(".paw-left .up"),
down: s(".paw-left .down"),
},
};
const style = getComputedStyle(document.documentElement);
const green = style.getPropertyValue("--green");
const pink = style.getPropertyValue("--pink");
const blue = style.getPropertyValue("--blue");
const orange = style.getPropertyValue("--orange");
const cyan = style.getPropertyValue("--cyan");
gsap.set(music.note, { scale: 0, autoAlpha: 1 });
const animatePawState = (selector: string) =>
gsap.fromTo(
selector,
{ autoAlpha: 0 },
{
autoAlpha: 1,
duration: 0.01,
repeatDelay: 0.19,
yoyo: true,
repeat: -1,
}
);
const tl = gsap.timeline();
tl.add(animatePawState(cat.pawLeft.up), "start")
.add(animatePawState(cat.pawRight.down), "start")
.add(animatePawState(cat.pawLeft.down), "start+=0.19")
.add(animatePawState(cat.pawRight.up), "start+=0.19")
.timeScale(1.6);
gsap.from(".terminal-code line", {
drawSVG: "0%",
duration: 0.1,
stagger: 0.1,
ease: "none",
repeat: -1,
});
// typing for pipe function doesn't seem to be working for usage when partially applied?
const noteElFn: Function = gsap.utils.pipe(gsap.utils.toArray, gsap.utils.shuffle);
const noteEls: HTMLElement[] = noteElFn(music.note);
const numNotes = noteEls.length / 3;
const notesG1 = noteEls.splice(0, numNotes);
const notesG2 = noteEls.splice(0, numNotes);
const notesG3 = noteEls;
const colorizer = gsap.utils.random([green, pink, blue, orange, cyan, "#a3a4ec", "#67b5c0", "#fd7c6e"], true);
const rotator = gsap.utils.random(-50, 50, 1, true);
const dir = (amt: number) => `${gsap.utils.random(["-", "+"])}=${amt}`;
const animateNotes = (els: HTMLElement[]): GSAPTween => {
els.forEach((el) => {
gsap.set(el, {
stroke: colorizer(),
rotation: rotator(),
x: gsap.utils.random(-25, 25, 1),
});
});
return gsap.fromTo(
els,
{
autoAlpha: 1,
y: 0,
scale: 0,
},
{
duration: 2,
autoAlpha: 0,
scale: 1,
ease: "none",
stagger: {
from: "random",
each: 0.5,
},
rotation: dir(gsap.utils.random(20, 30, 1)),
x: dir(gsap.utils.random(40, 60, 1)),
y: gsap.utils.random(-200, -220, 1),
onComplete: () => animateNotes(els),
}
);
};
tl.add(animateNotes(notesG1)).add(animateNotes(notesG2), ">0.05").add(animateNotes(notesG3), ">0.25");