-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrectangles.tsx
More file actions
70 lines (65 loc) · 1.93 KB
/
rectangles.tsx
File metadata and controls
70 lines (65 loc) · 1.93 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
import { Component, createSignal, For } from 'solid-js'
import { Canvas, Rectangle } from 'src'
import { Drag } from 'src/controllers/Drag'
const App: Component = () => {
const [counter, setCounter] = createSignal(0)
setInterval(() => setCounter(c => c + 1), 100)
const [selected, setSelected] = createSignal(false)
const [position, setPosition] = createSignal({ x: 200, y: 100 })
const [moveOrigin, setMoveOrigin] = createSignal(false)
const [origin, setOrigin] = createSignal({ x: 0, y: 0 })
return (
<>
<Canvas
style={{ width: '100vw', height: '100vh' }}
onMouseDown={e => {
if (e.target.length === 0) {
setSelected(false)
setMoveOrigin(true)
}
}}
onMouseMove={e => {
if (selected()) {
setPosition(pos => ({ x: pos.x + e.delta.x, y: pos.y + e.delta.y }))
} else if (moveOrigin()) {
setOrigin(pos => ({ x: pos.x + e.delta.x, y: pos.y + e.delta.y }))
}
}}
onMouseUp={() => {
setSelected(false)
setMoveOrigin(false)
}}
alpha
stats
draggable
>
<For
each={new Array(100).fill('').map(v => ({
position: {
x: Math.random() * (window.innerWidth + 200) - 100,
y: Math.random() * (window.innerHeight + 200) - 100,
},
fill: {
r: Math.random() * 215,
g: Math.random() * 215,
b: Math.random() * 215,
},
skewY: Math.random() * 90,
}))}
>
{data => (
<Rectangle
{...data}
dimensions={{ width: 100, height: 100 }}
lineWidth={20}
stroke="transparent"
controllers={[Drag()]}
composite="hard-light"
/>
)}
</For>
</Canvas>
</>
)
}
export default App