trail-0
2012. 10. 14.

Press enter key to clear the screen.

```p5        = processing
num_bikes = 20
bikes     = []
crange    =
hue: [0.0, 1.0],
sat: [0.4, 1.0],
bri: [0.5, 1.0]

# Penner equation :)
easeInOut = (t, b, c, d) ->
if (t /= d / 2) < 1
c / 2 * pow(t, 3) + b
else
return c / 2 * (pow(t - 2, 3) + 2) + b

class Bike
constructor: ->
@init()

init: ->
@x = random(0, p5.width)
@y = random(0, p5.height)
@r = random(- PI, PI)
@t = @d = 0
@v = random(1, 10)
@c = color random(crange.hue...),
random(crange.sat...),
random(crange.bri...)
@w = random(6, 12)
@p = random(1, 10)
@td = [10, 100]

move: ->
@x += @v * cos(@r)
@y += @v * sin(@r)

stroke @c, 0.05
for w in [1..@w]
strokeWeight w
point @x, @y

if random(100) < @p
@turn()

if @t < @d
@r = easeInOut(@t, @rs, @re, @d)
@t += 1

if @x > p5.width or @x < 0 or @y < 0 or @y > p5.height
@init()

turn: ->
@rs = @r
@re = random(-PI, PI)
@t  = 0
@d  = random(@td...)

setup = ->
size       \$(window).width(), \$(window).height()
frameRate  60
colorMode  HSB, 1.0
background 0

for t in [0...num_bikes]
bikes.push new Bike()

draw = ->
for b in bikes
b.move()

keyPressed = ->
if keyCode() == ENTER || keyCode() == RETURN
background 0
crange =
hue: _([random(1.0), random(1.0)]).sort(),
sat: _([random(1.0), random(1.0)]).sort(),
bri: _([random(1.0), random(1.0)]).sort()
for b in bikes
b.init()```
» capture | close