Created
August 12, 2011 23:47
-
-
Save wesbos/1143276 to your computer and use it in GitHub Desktop.
This file contains 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
# setup our application with its own namespace | |
App = {} | |
### | |
Init | |
### | |
App.init = -> | |
App.canvas = document.createElement 'canvas' #create the canvas element | |
App.canvas.height = 400 | |
App.canvas.width = 800 #size it up | |
document.getElementsByTagName('article')[0].appendChild(App.canvas) #append it into the DOM | |
App.ctx = App.canvas.getContext("2d") # Store the context | |
# set some preferences for our line drawing. | |
App.ctx.fillStyle = "solid" | |
App.ctx.strokeStyle = "#bada55" | |
App.ctx.lineWidth = 5 | |
App.ctx.lineCap = "round" | |
# Draw Function | |
App.draw = (x,y,type) -> | |
if type is "dragstart" | |
App.ctx.beginPath() | |
App.ctx.moveTo(x,y) | |
else if type is "drag" | |
App.ctx.lineTo(x,y) | |
App.ctx.stroke() | |
else | |
App.ctx.closePath() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment