-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSmileys.tsx
108 lines (102 loc) · 2.46 KB
/
Smileys.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
import {
Component,
createEffect,
createMemo,
createSignal,
For,
on,
} from 'solid-js'
import { Arc, Bezier, Canvas, createClock, Group } from 'src'
import { Drag } from 'src/controllers/Drag'
const Smiley = (props: { counter: number }) => {
const randomPosition = {
x: Math.random() * (window.innerWidth + 100) - 50,
y: Math.random() * (window.innerHeight + 100) - 50,
}
const delta = Math.random() * 10 + 20
const x = createMemo(
on(
() => props.counter,
() =>
randomPosition.x +
Math.sin(performance.now() / (20 * delta) + delta) * 20,
),
)
const y = createMemo(
on(
() => props.counter,
() =>
randomPosition.y +
Math.cos(performance.now() / (20 * delta) + delta) * 20,
),
)
const color = createMemo(() => ({ h: Math.random() * 360, s: 50, l: 50 }))
return (
<Arc
transform={{
position: {
get x() {
return x()
},
get y() {
return y()
},
},
}}
style={{
radius: 70,
fill: color(),
stroke: false,
}}
controllers={[Drag()]}
>
<Group transform={{ position: { x: 0, y: 35 } }}>
<Arc
transform={{ position: { x: 40, y: 0 } }}
style={{ radius: 10, fill: 'black', stroke: false }}
/>
<Arc
transform={{ position: { x: 80, y: 0 } }}
style={{ radius: 10, fill: 'black', stroke: false }}
/>
</Group>
<Group transform={{ position: { x: 20, y: 80 } }}>
<Bezier
style={{
lineWidth: 15,
lineCap: 'round',
stroke: 'black',
fill: false,
}}
points={[
{ point: { x: 10, y: 0 }, control: { x: 0, y: 20 } },
{ point: { x: 50, y: 40 }, control: { x: -20, y: 0 } },
{ point: { x: 90, y: 0 }, control: { x: 0, y: 20 } },
]}
/>
</Group>
</Arc>
)
}
const App: Component = () => {
const fill = `rgb(${Math.random() * 200}, ${Math.random() * 200}, ${
Math.random() * 200
})`
const clock = createClock()
clock.start()
return (
<>
<Canvas
clock={clock.clock()}
style={{ width: '100%', height: '100%', fill }}
alpha
stats
>
<For each={new Array(500).fill('')}>
{() => <Smiley counter={clock.clock()} />}
</For>
</Canvas>
</>
)
}
export default App