diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2018-05-02 12:45:13 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2018-05-02 12:48:28 +0000 |
| commit | 30cc9b08c843e83219d6ede53cff2a06d4316915 (patch) | |
| tree | 53e303f02f69c4bc8d0dc782b0574241a3506932 /app/canvasapp.moon | |
| download | mmm-30cc9b08c843e83219d6ede53cff2a06d4316915.tar.gz mmm-30cc9b08c843e83219d6ede53cff2a06d4316915.zip | |
initial commit
Diffstat (limited to 'app/canvasapp.moon')
| -rw-r--r-- | app/canvasapp.moon | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/canvasapp.moon b/app/canvasapp.moon new file mode 100644 index 0000000..f05bfec --- /dev/null +++ b/app/canvasapp.moon @@ -0,0 +1,34 @@ +window = js.global + +class CanvasApp + width: 500 + height: 400 + new: => + @canvas = window.document\createElement 'canvas' + @canvas.width, @canvas.height = @width, @height + @ctx = @canvas\getContext '2d' + @time = 0 + + @canvas.tabIndex = 0 + @canvas\addEventListener 'click', (_, e) -> @click and @click e.offsetX, e.offsetY, e.button + @canvas\addEventListener 'keydown', (_, e) -> @keydown and @keydown e.key, e.code + + lastMillis = window.performance\now! + t = @ + animationFrame = (_, millis) -> + if not @paused + @update (millis - lastMillis) / 1000 + @ctx\resetTransform! + @draw! + window\setTimeout (-> + window\requestAnimationFrame animationFrame + ), 0 + lastMillis = millis + window\requestAnimationFrame animationFrame + + update: (dt) => + @time += dt + +{ + :CanvasApp +} |
