Created
January 11, 2012 11:06
-
-
Save si14/1594182 to your computer and use it in GitHub Desktop.
Light class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class window.Light | |
# constructor for class | |
constructor: (@posx, @posy) -> | |
@state = Math.floor(Math.random() * 2) | |
@speed = Math.floor(Math.random() * 16) | |
setInterval(@changeState, 1000 * @speed + 5000) | |
# method to draw light | |
draw: => | |
ctx.drawImage(img[@state], size[0] + @posx * size[0] - 18, size[1] + @posy * size[1] - 18) | |
# method to change state | |
changeState: => | |
if @state then @state = 0 else @state = 1 | |
#redraw() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
window.Light = (function() { | |
function Light(posx, posy) { | |
this.posx = posx; | |
this.posy = posy; | |
this.changeState = __bind(this.changeState, this); | |
this.draw = __bind(this.draw, this); | |
this.state = Math.floor(Math.random() * 2); | |
this.speed = Math.floor(Math.random() * 16); | |
setInterval(this.changeState, 1000 * this.speed + 5000); | |
} | |
Light.prototype.draw = function() { | |
return ctx.drawImage(img[this.state], size[0] + this.posx * size[0] - 18, size[1] + this.p$ | |
}; | |
Light.prototype.changeState = function() { | |
if (this.state) { | |
return this.state = 0; | |
} else { | |
return this.state = 1; | |
} | |
}; | |
return Light; | |
})(); | |
}).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
window.Light = (function() { | |
function Light(posx, posy) { | |
this.posx = posx; | |
this.posy = posy; | |
this.state = Math.floor(Math.random() * 2); | |
this.speed = Math.floor(Math.random() * 16); | |
setInterval(this.changeState, 1000 * this.speed + 5000); | |
} | |
Light.prototype.draw = function() { | |
return ctx.drawImage(img[this.state], size[0] + this.posx * size[0] - 18, size[1] + this.posy * size[1] - 18); | |
}; | |
Light.prototype.changeState = function() { | |
if (this.state) { | |
return this.state = 0; | |
} else { | |
return this.state = 1; | |
} | |
}; | |
return Light; | |
})(); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment