From 72829c68ec50c432b38fefcb28613c75657fb2bb Mon Sep 17 00:00:00 2001 From: s-ol Date: Tue, 23 Oct 2018 00:36:24 +1100 Subject: CanvasApp whammy.js webm exporting --- app/init.moon | 4 +-- app/koch.moon | 64 ++++++++++++++++++++++++++++++++++++++++++++++ app/quasihilbert.moon | 71 --------------------------------------------------- app/twisted.moon | 6 ++--- 4 files changed, 68 insertions(+), 77 deletions(-) create mode 100644 app/koch.moon delete mode 100644 app/quasihilbert.moon (limited to 'app') diff --git a/app/init.moon b/app/init.moon index e97d6cc..0cf846a 100644 --- a/app/init.moon +++ b/app/init.moon @@ -33,9 +33,9 @@ experiments = desc: 'Playground for Functional Tags' render: -> require '.tags' }, - quasihilbert: { + koch: { desc: "lil' fractal thing", - render: -> require '.quasihilbert' + render: -> require '.koch' }, destify = (name, route) -> diff --git a/app/koch.moon b/app/koch.moon new file mode 100644 index 0000000..3a0ef29 --- /dev/null +++ b/app/koch.moon @@ -0,0 +1,64 @@ +on_client -> + Math = window.Math + + import CanvasApp from require 'lib.canvasapp' + import hsl from require 'lib.color' + + class KochDemo extends CanvasApp + width: 600 + height: 600 + length: math.pi * 2 + + new: (@iterations=3, @scale=.5) => + super true + hue = Math.random! + @background = {1 - hue, .3, .3} + + @shades = setmetatable {}, __index: (tbl, key) -> + with val = hsl { hue, .7, .9 - .5 * (key / @iterations)} do rawset tbl, key, val + + a_sixth = math.pi / 3 + 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\fill! + + update: (...) => + super ... + + @scale = 0.8 + 0.2 * math.cos @time + + 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 + + draw = (i, e=1) -> + @triangle @shades[i] + + return unless i > 0 + + @ctx\save! + @ctx\rotate -3*a_sixth + @ctx\scale @scale, @scale + + for o=-1,e,2 + @ctx\save! + @ctx\rotate o * 2 * a_sixth + @ctx\translate .5 + .5/@scale, 0 + draw i - 1 + @ctx\restore! + + @ctx\restore! + + @ctx\rotate a_sixth/2 + draw @iterations, 3 + + append KochDemo!.node diff --git a/app/quasihilbert.moon b/app/quasihilbert.moon deleted file mode 100644 index 92b7c2e..0000000 --- a/app/quasihilbert.moon +++ /dev/null @@ -1,71 +0,0 @@ -on_client -> - Math = window.Math - - import CanvasApp from require 'lib.canvasapp' - import hsl from require 'lib.color' - - class TwistedDemo extends CanvasApp - width: 600 - height: 600 - length: math.pi * 2 - - new: (@iterations=3, @scale=.5) => - super! - hue = Math.random! - @background = {1 - hue, .3, .3} - - @shades = setmetatable {}, __index: (tbl, key) -> - with val = hsl { hue, .7, .9 - .5 * (key / @iterations)} do rawset tbl, key, val - - a_sixth = math.pi / 3 - 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\fill! - - update: (...) => - super ... - - @scale = 0.8 + 0.2 * math.cos @time - - 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 - - draw = (i, e=1) -> - @triangle @shades[i] - - return unless i > 0 - - @ctx\save! - @ctx\rotate -3*a_sixth - @ctx\scale @scale, @scale - - for o=-1,e,2 - @ctx\save! - @ctx\rotate o * 2 * a_sixth - @ctx\translate .5 + .5/@scale, 0 - draw i - 1 - @ctx\restore! - - @ctx\restore! - - @ctx\rotate a_sixth/2 - draw @iterations, 3 - - twisted = TwistedDemo! - document.body\appendChild twisted.canvas - -- window\setTimeout twisted\start, 500 - - { :location } = window - if location.search and location.search\find 'render' - twisted\render! - diff --git a/app/twisted.moon b/app/twisted.moon index 325d408..0ab30b1 100644 --- a/app/twisted.moon +++ b/app/twisted.moon @@ -9,7 +9,7 @@ on_client -> height: 400 length: math.pi * 4 new: => - super! + super true @background = {Math.random!, Math.random!/3+.2, Math.random!/4} hue = Math.random! @shades = setmetatable {}, __index: (key) => @@ -35,6 +35,4 @@ on_client -> draw i draw 1 - twisted = TwistedDemo! - document.body\appendChild twisted.canvas - twisted\start! + document.body\appendChild TwistedDemo!.node -- cgit v1.2.3