Skip to content

Instantly share code, notes, and snippets.

@sebastiandeutsch
Created October 10, 2012 08:41
Show Gist options
  • Save sebastiandeutsch/3864137 to your computer and use it in GitHub Desktop.
Save sebastiandeutsch/3864137 to your computer and use it in GitHub Desktop.
window.Kata ?= {}
window.Kata.Controller = class Controller
constructor: (@canvas, particleCount) ->
@context = @canvas.getContext '2d'
@particles = []
for i in [0...particleCount]
@particles.push new Kata.Particle(@context)
window.requestAnimFrame =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
( callback ) ->
window.setTimeout(callback, 1000 / 60)
# shim layer with setTimeout fallback
# @requestAnimFrame = getAnimFrameFunction
@render()
render: =>
console.log @requestAnimFrame
# clear canvas
@context.fillStyle = '#000000'
@context.fillRect 0, 0, @context.canvas.width, @context.canvas.height
for particle in @particles
particle.update()
particle.draw()
requestAnimFrame(@render)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment