-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCubics.tsx
124 lines (117 loc) · 2.8 KB
/
Cubics.tsx
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
import { Component, createMemo, createSignal, For, on, Show } from 'solid-js'
import { Bezier, Canvas, Group, Quadratic, QuadraticPoints } from 'src'
const RandomBezier = (props: { counter: number; scale: number }) => {
const getPoints = () => {
const points = []
let i = 0
const amount = 10
const variation = 500
while (i <= amount) {
const point =
i === 0 || i === amount
? {
x: (i * window.innerWidth) / amount,
y: window.innerHeight,
}
: {
x: (i * window.innerWidth) / amount,
y:
i % 2 === 0
? window.innerHeight / 2 +
Math.random() * variation -
variation / 2
: window.innerHeight / 3 -
(window.innerHeight / 3) * props.scale +
Math.random() * variation,
}
const control =
i === 0 || i === amount
? {
x: 0,
y: -50,
}
: {
x: -50,
y: 0,
}
points.push({
point,
control,
})
i++
}
return points
}
const points = createMemo(
on(
() => props.counter,
() => getPoints(),
),
)
const randomFill = createMemo(
on(
() => props.counter,
() => {
return {
r: Math.random() * 200,
g: Math.random() * 200,
b: Math.random() * 200,
}
},
),
)
return (
<Bezier
points={points()!}
style={{
lineWidth: 0,
composite: 'hard-light',
stroke: 'transparent',
fill: randomFill(),
}}
close
/>
)
}
const App: Component = () => {
const [counter, setCounter] = createSignal(0)
const [debug, setDebug] = createSignal(false)
const increment = () => setCounter(c => c + 1)
window.addEventListener('keydown', event => {
if (event.code === 'Space') increment()
})
window.addEventListener('resize', event => {
increment()
})
const amount = 20
const randomFill = createMemo(
on(counter, () => {
return `rgb(${Math.random() * 200}, ${Math.random() * 200}, ${
Math.random() * 200
})`
}),
)
return (
<>
<Canvas
style={{ width: '100%', height: '100%', background: randomFill() }}
alpha
stats
onMouseDown={increment}
debug={debug()}
>
<Group transform={{ position: { x: 0, y: 0 } }}>
<For each={new Array(amount).fill('')}>
{(_, i) => (
<RandomBezier
counter={counter()}
scale={(amount - i()) / amount}
/>
)}
</For>
</Group>
</Canvas>
</>
)
}
export default App