-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
53 lines (43 loc) · 1.26 KB
/
App.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
import { ExpoWebGLRenderingContext, GLView } from "expo-gl"
import { useEffect, useState } from "react"
import { View } from "react-native"
import { Renderer } from "./Renderer"
export default function App() {
const [initialized, setInitialized] = useState(false)
const [gl, setGL] = useState<ExpoWebGLRenderingContext>()
const [renderer] = useState(Renderer)
const updateAndRender = () => {
renderer.addParticle(
Math.floor(Math.random() * 300),
Math.floor(Math.random() * 300),
Math.floor(Math.random() * 16777215)
)
renderer.addStaticParticle(
Math.floor(Math.random() * 300),
Math.floor(Math.random() * 300),
Math.floor(Math.random() * 16777215)
)
renderer.render()
}
useEffect(() => {
if (gl) {
renderer.initialize(gl)
setInitialized(true)
}
}, [gl])
useEffect(() => {
if (!initialized) return () => {}
const timer = setInterval(() => {
updateAndRender()
}, 1000 / 60)
return () => clearInterval(timer)
}, [initialized])
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<GLView
style={{ backgroundColor: "#ffe0e0", width: 300, height: 300 }}
onContextCreate={setGL}
/>
</View>
)
}