Skip to content

Instantly share code, notes, and snippets.

@jahpd
Last active August 6, 2016 22:11
Show Gist options
  • Save jahpd/f72c7b70d38113b3ac4a77d43eb42438 to your computer and use it in GitHub Desktop.
Save jahpd/f72c7b70d38113b3ac4a77d43eb42438 to your computer and use it in GitHub Desktop.
class Mbezier
constructor: ->
update: (fn) ->
for param in ['points', 'colors']
if not this[param] then this[param] = {}
if param is 'points' then k = 'xy'
if param is 'colors' then k = 'rgba'
for c in k.split('')
this[param][c] = fn(param, c)
o = []
n = 13
v = 0.0001
sin = (val, scale) -> 2 * (Math.sin(@noise(val) * @PI) - 1) * scale
@setup = ->
@createCanvas 480, 360
for i in [0..n-1]
o[i] = new Mbezier()
o[i].update (param, l)->
if l is 'x' then r = @random(@width)
if l is 'y' then r = @random(@height)
if l is 'r' or l is 'g' or r is 'b' or r is 'a' then r = @random(255)
{offset: Math.random(), val: r}
@draw = ->
@background 0
for oo in o
@stroke oo.colors.r.val, oo.colors.g.val, oo.colors.b.val
@noFill()
@bezier oo.points.x.val[0], oo.points.y.val[0], oo.points.x.val[1], oo.points.y.val[1], oo.points.x.val[2], oo.points.y.val[2], oo.points.x.val[3], oo.points.y.val[3]
oo.update (param, l)->
offset = oo[param][l].offset + v
if l is 'x' then r = sin(oo[param][l].offset, @width)
if l is 'y' then r = sin(oo[param][l].offset, @height)
if l is 'r' or l is 'g' or r is 'b' or r is 'a' then r = sin(oo[param][l].offset, 255)
{offset: offset, val: r}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment