Created
February 12, 2019 20:08
-
-
Save dmitryshelomanov/65945690de5f2f30238e626f34396aa3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Webapi.Dom; | |
open Webapi.Canvas.CanvasElement; | |
open Point; | |
open App; | |
open Draw; | |
let worldMaxSize = 400.0; | |
let tick = (world) => { | |
world | |
|> viewPopulation | |
|> Js_array.forEach(shape => | |
switch (shape) { | |
| Circle(circle) => | |
circle.point = add(vector2(0.1, 0.1), circle.point) | |
} | |
); | |
}; | |
let main = () => { | |
let canvas = | |
Belt.Option.(document |> Document.getElementById("app") |> getExn); | |
let ctx = getContext2d(canvas); | |
let world = | |
create( | |
~boundaries={width: 400.0, height: 400.0}, | |
~population=[| | |
makeCircle(~r=20.0, ~point=vector2(10.0, 10.0), ()), | |
makeCircle(~r=5.0, ~point=vector2(100.0, 100.0), ()), | |
|], | |
ctx, | |
); | |
render(world, tick); | |
}; | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment