Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
timoisalive committed Jan 11, 2023
1 parent d6e3652 commit d6f9c62
Show file tree
Hide file tree
Showing 6 changed files with 7,320 additions and 21,437 deletions.
63 changes: 48 additions & 15 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
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={styles.container}>
<Text>Open up App.tsx to start working on your app!</Text>
<StatusBar style="auto" />
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<GLView
style={{ backgroundColor: "#ffe0e0", width: 300, height: 300 }}
onContextCreate={setGL}
/>
</View>
);
)
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Loading

0 comments on commit d6f9c62

Please sign in to comment.