-
Notifications
You must be signed in to change notification settings - Fork 0
/
oscillate.html
86 lines (82 loc) · 2.1 KB
/
oscillate.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Space+Mono:wght@700&display=swap"
rel="stylesheet"
/>
<style>
body {
margin: 0;
padding: 0;
font-family: "Space Mono", monospace;
font-size: 15vw;
background: black;
}
main {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
}
main > span {
position: relative;
}
main > span > * {
position: absolute;
top: 0;
left: 0;
}
main > span > *:first-child {
position: relative;
}
</style>
</head>
<body>
<script type="module">
import { patch } from "../index.js";
import { time } from "../utils.js";
import S from "https://cdn.skypack.dev/s-js";
const text = "OSCILLATE";
const iterations = 20;
const colorRange = 180;
const colorOffset = 1;
const speed = 0.002;
const height = 50;
const spread = 5;
const range = (n) => [...Array(n).keys()];
S.root(() => {
const Trail = (char, i) => {
return range(iterations).map((j) => {
const p = j / iterations;
const h = (colorOffset + p) * colorRange;
const l = p * 100;
const transform = S(() => {
const y = Math.sin(time() * speed + p * spread + i) * height;
return `translateY(${y}%)`;
});
return {
tag: "span",
children: char,
style: {
color: `hsl(${h}deg, 50%, ${l}%)`,
transform,
},
};
});
};
const Main = {
tag: "main",
children: text.split("").map((char, i) => ({
tag: "span",
children: Trail(char, i),
})),
};
patch(document.body, Main);
});
</script>
</body>
</html>