-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
40 lines (34 loc) · 867 Bytes
/
index.js
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
import React from 'react'
import display from '../core/paint'
import Canvas from '../react/Canvas'
import useClock from '../react/useClock'
import program from '../programs/003-feedback'
const stopAt = 1500
const tickMs = 100
const displayOptions = {
scale: 100,
border: 15,
arrowSize: 0.08,
colorIntensity: 1e5
}
const initWorld = program()
const Simulation = ({children}) => {
const [world, setWorld] = React.useState(initWorld)
const clock = useClock(() => setWorld(program(world)), tickMs, true)
if (world.time >= stopAt) clock.stop()
global.world = world
global.clock = clock
return children(world)
}
const Container = () => {
return (
<div>
<Simulation>
{world => (
<Canvas state={world} paint={display} options={displayOptions} />
)}
</Simulation>
</div>
)
}
export default Container