-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ts
47 lines (37 loc) · 1.11 KB
/
setup.ts
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
import Scene from "./scene";
import Canvas2DRenderer from './renderer/canvas2d-renderer'
import startString from "./saved-stated/start";
import Fps from "./utils/fps";
import { Input } from './utils/input'
import Renderer from "./renderer/renderer.interface";
let scene: Scene
let renderer: Renderer
let fps: Fps
let canvas: HTMLCanvasElement
let ctx: CanvasRenderingContext2D
export function start(_canvas: HTMLCanvasElement, width: number, height: number) {
const context = _canvas.getContext('2d')
if (!context) { return }
ctx = context
canvas = _canvas
setup(width, height)
render()
}
function setup(width: number, height: number) {
scene = new Scene(width, height)
scene.input = new Input(canvas)
scene.setSamples(3300);
scene.loadString(startString)
scene.sun.set(width / 3, height / 2.2)
scene.sun.velocity.set(5, 0)
renderer = new Canvas2DRenderer(ctx)
fps = new Fps(30)
scene.start()
}
function render() {
window.requestAnimationFrame(render)
scene.update()
renderer.draw(scene)
// TODO: - Show / hide fps on key press
// fps.showFps(ctx)
}