window.requestAnimFrame = (->
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.setTimeout callback, 1000 / 60
PI_BY_180 = Math.PI / 180
canvas = document.getElementById 'c'
ctx = canvas.getContext '2d'
canvas.addEventListener 'mousemove', onMouseMove
for i in [10...W/2] by 10
display_list.push new Particle(i)
mx = e.offsetX || e.pageX
my = e.offsetY || e.pageY
if !last_time then last_time = (new Date).getTime()
current_time = (new Date).getTime()
dt = (current_time - last_time) / 1000
for child in display_list
continue if typeof child.draw isnt 'function'
ctx.translate child.x, child.y unless isNaN child.x or isNaN child.y
ctx.scale child.scale_x, child.scale_y unless isNaN child.scale_x or isNaN child.scale_y
ctx.globalAlpha = child.alpha unless isNaN child.alpha
for child in display_list
child.update() if typeof child.update is 'function'
constructor: (@radius = 1) ->
@theta = ~~(Math.random() * 360)
@speed_theta = 0.5 + Math.random() * @radius * 0.005
@alpha = @radius / (W / 2)
if Math.random() > 0.5 then @dir = 1 else @dir = -1
@scale_x = @scale_y = 0.5
ctx.arc 0, 0, @radius*0.04, 0, Math.PI*2, true
@scale_x += @dir * 0.06 * time
@scale_y += @dir * 0.06 * time
@theta += @speed_theta * time
@x = cx + @radius * Math.cos @theta * PI_BY_180
@y = cy + @radius * Math.sin @theta * PI_BY_180
@scale_x = @scale_y = 0.5
@color = colors[~~(Math.random() * colors.length)]
@ox = @x = ~~(Math.random() * W)
@oy = @y = 100 + ~~(Math.random() * 5)