flock-0
2012. 06. 23.

An old sketch. Inspired by a work of Rob Hodgins. Once a Java applet, now runs smoothly within an HTML canvas element, how cool is that? However, do not try this on mobile.

» launch flock-0

```p5        = processing
followers = []

class Follower
constructor: (@x, @y) ->
@p    = [[@x, @y]]
@pvx  = @pvy = 0
@ease = random 0.01, 0.05
@elas = random 0.95, 0.99
@b    = random 200

follow: (tx, ty) ->
@p.pop() if @p.length > 2

@x += @pvx = @pvx * @elas + (random(-30, 30) + tx - @x) * @ease
@y += @pvy = @pvy * @elas + (random(-30, 30) + ty - @y) * @ease

if random() < 0.001
@x += random(-300, 300)
@y += random(-300, 300)

@p.unshift [@x, @y]

draw: ->
stroke @b + (@p[0][1] - @p[1][1]) * 2,
@b,
@b + (@p[0][0] - @p[1][0]) * 2

beginShape()
for p in @p
vertex p[0], p[1]
endShape()

setup = ->
size \$(window).width(), \$(window).height()
frameRate 60
background 255
noFill()
spawn()

spawn = ->
for i in [0...300]
followers.push new Follower(random(p5.width), random(p5.height))

draw = ->
background 100, 50, 50
for f in followers
f.follow(p5.mouseX, p5.mouseY)
f.draw()```
» capture | close