Skip to content

Instantly share code, notes, and snippets.

@sebastiandeutsch
Created October 10, 2012 08:41
Show Gist options
  • Save sebastiandeutsch/3864133 to your computer and use it in GitHub Desktop.
Save sebastiandeutsch/3864133 to your computer and use it in GitHub Desktop.
window.Kata ?= {}
window.Kata.Particle = class Particle
constructor: (@context, @vector, @position) ->
@vector =
x: Math.random() * 4 - 2
y: Math.random() * 4 - 2
@position =
x: @context.canvas.width/2
y: @context.canvas.height/2
update: ->
@position.x += @vector.x
@position.y += @vector.y
# update vectors
if @position.x > @context.canvas.width - 10 or @position.x < 0
@vector.x *= -1
if @position.y > @context.canvas.height - 10 or @position.y < 0
@vector.y *= -1
draw: ->
@context.fillStyle = '#00ffff'
@context.fillRect @position.x, @position.y, 10, 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment