aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-10-22 14:29:18 +0000
committers-ol <s-ol@users.noreply.github.com>2018-10-22 14:29:18 +0000
commit2df5a153b7240c399370fb472e5e89f84ec48d2f (patch)
tree9df11823c5a6ac1a5afb026e5bcb901927279d4c
parentCanvasApp whammy.js webm exporting (diff)
downloadmmm-2df5a153b7240c399370fb472e5e89f84ec48d2f.tar.gz
mmm-2df5a153b7240c399370fb472e5e89f84ec48d2f.zip
finish koch
-rw-r--r--app/koch.moon76
m---------dist0
-rw-r--r--lib/canvasapp.client.moon8
3 files changed, 64 insertions, 20 deletions
diff --git a/app/koch.moon b/app/koch.moon
index 3a0ef29..0fea944 100644
--- a/app/koch.moon
+++ b/app/koch.moon
@@ -9,7 +9,7 @@ on_client ->
height: 600
length: math.pi * 2
- new: (@iterations=3, @scale=.5) =>
+ new: (@iterations=3) =>
super true
hue = Math.random!
@background = {1 - hue, .3, .3}
@@ -18,47 +18,87 @@ on_client ->
with val = hsl { hue, .7, .9 - .5 * (key / @iterations)} do rawset tbl, key, val
a_sixth = math.pi / 3
+ a_third = 2 * a_sixth
cossin = (a) -> (math.cos a), math.sin a
triangle: (color) =>
@ctx.fillStyle = color
@ctx\beginPath!
@ctx\moveTo cossin 0
- @ctx\lineTo cossin 2*a_sixth
- @ctx\lineTo cossin 4*a_sixth
+ @ctx\lineTo cossin a_third
+ @ctx\lineTo cossin 2*a_third
@ctx\fill!
- update: (...) =>
- super ...
-
- @scale = 0.8 + 0.2 * math.cos @time
+ update: (dt) =>
+ super dt * 1.6
draw: =>
@ctx.fillStyle = hsl @background
@ctx\fillRect 0, 0, @width, @height
@ctx\translate @width/2, @height/2
- scale = .3 * math.min @width, @height
- @ctx\scale scale, scale
+ s = .3 * math.min @width, @height
+ @ctx\scale s, s
+
+ _scale = 0.8 + 0.2 * math.sin math.pi + @time
+
+ ttime = @time - math.pi/2
+ transfer, flipped = 0
+ if ttime > 0 and ttime < math.pi
+ transfer = .5 - .5 * math.cos ttime
+ flipped = true
- draw = (i, e=1) ->
+ draw = (i, pop) ->
@triangle @shades[i]
- return unless i > 0
+ extra = not pop and flipped
+ return unless i > (if extra then -1 else 0)
+
+ scale = _scale
+ if (pop and i < 1) or (not pop and i < 0)
+ scale = transfer
@ctx\save!
- @ctx\rotate -3*a_sixth
- @ctx\scale @scale, @scale
+ @ctx\rotate -(a_sixth + a_third)
+ @ctx\scale scale, scale
- for o=-1,e,2
+ for o=1,2
+ @ctx\rotate a_third
@ctx\save!
- @ctx\rotate o * 2 * a_sixth
- @ctx\translate .5 + .5/@scale, 0
- draw i - 1
+ @ctx\translate .5 + .5/scale, 0
+ draw i - 1, pop
@ctx\restore!
@ctx\restore!
@ctx\rotate a_sixth/2
- draw @iterations, 3
+ @ctx\translate -transfer, 0
+ @ctx\rotate a_sixth * transfer
+
+ @triangle @shades[3 - transfer]
+
+ @ctx\save!
+ @ctx\rotate a_sixth
+ @ctx\scale _scale, _scale
+
+ @ctx\save!
+ @ctx\translate .5 + .5/_scale, 0
+ draw 2 - transfer
+ @ctx\restore!
+
+ @ctx\rotate a_third
+
+ @ctx\save!
+ @ctx\translate .5 + .5/_scale, 0
+ draw 2 - transfer
+ @ctx\restore!
+
+ @ctx\rotate a_third
+
+ @ctx\save!
+ @ctx\translate .5 + .5/_scale, 0
+ draw 2 + transfer, true
+ @ctx\restore!
+
+ @ctx\restore!
append KochDemo!.node
diff --git a/dist b/dist
-Subproject 0475a7f1f0d17a2a3104860215c960b7ca036a0
+Subproject 3316238d9f30a897545e26458ef9f5bd324747c
diff --git a/lib/canvasapp.client.moon b/lib/canvasapp.client.moon
index ed1cfb7..62aaceb 100644
--- a/lib/canvasapp.client.moon
+++ b/lib/canvasapp.client.moon
@@ -46,6 +46,10 @@ class CanvasApp
update: (dt) =>
@time += dt
+ if @length and @time > @length
+ @time -= @length
+ true
+
render: (fps=60) =>
assert @length, 'cannot render CanvasApp without length set'
@paused = true
@@ -54,13 +58,13 @@ class CanvasApp
writer = js.new window.Whammy.Video, fps
doFrame = ->
- @update 1/fps
+ done = @update 1/fps
@ctx\resetTransform!
@draw!
writer\add @canvas
- if @time >= @length
+ if done or @time >= @length
blob = writer\compile!
name = "#{@@__name}_#{fps}fps.webm"
@node.lastChild\appendChild a name, download: name, href: window.URL\createObjectURL blob