Last active
March 19, 2020 16:13
-
-
Save shritesh/7e7d31488c04ba118c3e15d5e65607d5 to your computer and use it in GitHub Desktop.
Revisions
-
shritesh revised this gist
Mar 19, 2020 . 1 changed file with 9 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,6 @@ type p5; type sketch; type button; @@ -16,6 +13,8 @@ type state = [@bs.module] [@bs.new] external createP5: (sketch => unit) => p5 = "p5"; [@bs.send] external createCanvas: (sketch, int, int) => unit = "createCanvas"; [@bs.send] external noCanvas: sketch => unit = "noCanvas"; [@bs.set] external onSetup: (sketch, unit => unit) => unit = "setup"; [@bs.set] external onDraw: (sketch, unit => unit) => unit = "draw"; [@bs.send] external millis: sketch => int = "millis"; [@bs.send] external createButton: (sketch, string) => button = "createButton"; [@bs.send] external html: (button, string) => unit = "html"; @@ -36,17 +35,14 @@ let makeSketch = s => { | _ => () }; s->onSetup(() => { s->noCanvas; let btn = s->createButton("Start"); btn->mousePressed(btnPressed); appState := NotStarted(btn); }); s->onDraw(() => switch (appState^) { | Running(btn, time) => let seconds = float(millis(s) - time) /. 1000.0; @@ -55,7 +51,8 @@ let makeSketch = s => { btn->html(str ++ " Seconds"); | _ => () } ); }; createP5(makeSketch); -
shritesh revised this gist
Mar 14, 2020 . 1 changed file with 9 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -26,37 +26,35 @@ external mousePressed: (button, unit => unit) => unit = "mousePressed"; let makeSketch = s => { let appState = ref(Initializing); let btnPressed = () => switch (appState^) { | NotStarted(btn) => appState := Running(btn, millis(s)) | Running(btn, time) => appState := Stopped(btn, time) | Stopped(btn, _) => appState := NotStarted(btn); btn->html("Start"); | _ => () }; s.setup = ( () => { s->noCanvas; let btn = s->createButton("Start"); btn->mousePressed(btnPressed); appState := NotStarted(btn); } ); s.draw = ( () => switch (appState^) { | Running(btn, time) => let seconds = float(millis(s) - time) /. 1000.0; let str = s->nfc(seconds, 2); btn->html(str ++ " Seconds"); | _ => () } ); }; -
shritesh renamed this gist
Mar 10, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
shritesh created this gist
Mar 10, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ type p5; type sketch = { mutable setup: unit => unit, mutable draw: unit => unit, }; type button; type state = | Initializing | NotStarted(button) | Running(button, int) | Stopped(button, int); [@bs.module] [@bs.new] external createP5: (sketch => unit) => p5 = "p5"; [@bs.send] external createCanvas: (sketch, int, int) => unit = "createCanvas"; [@bs.send] external noCanvas: sketch => unit = "noCanvas"; [@bs.send] external millis: sketch => int = "millis"; [@bs.send] external createButton: (sketch, string) => button = "createButton"; [@bs.send] external html: (button, string) => unit = "html"; [@bs.send] external mousePressed: (button, unit => unit) => unit = "mousePressed"; [@bs.send] external nfc: (sketch, float, int) => string = "nfc"; let makeSketch = s => { let appState = ref(Initializing); let btnPressed = () => { switch (appState^) { | NotStarted(btn) => appState := Running(btn, millis(s)) | Running(btn, time) => appState := Stopped(btn, time) | Stopped(btn, _) => appState := NotStarted(btn); html(btn, "Start"); | _ => () }; }; s.setup = ( () => { noCanvas(s); let btn = createButton(s, "Start"); mousePressed(btn, btnPressed); appState := NotStarted(btn); } ); s.draw = ( () => { switch (appState^) { | Running(btn, time) => let seconds = float(millis(s) - time) /. 1000.0; let str = nfc(s, seconds, 2); html(btn, str ++ " Seconds"); | _ => () }; } ); }; createP5(makeSketch);