Skip to content

Instantly share code, notes, and snippets.

@dmitryshelomanov
Created February 12, 2019 20:08

Revisions

  1. Shelomanov Dmitry created this gist Feb 12, 2019.
    39 changes: 39 additions & 0 deletions test.re
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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();