Permalink
Browse files

Extract line rendering data to Line class

  • Loading branch information...
1 parent ba2e5b7 commit 2c03fcba534329bcb8c025f2a58eb6b5ed0a9364 @cfcosta committed Sep 5, 2012
Showing with 9 additions and 12 deletions.
  1. +9 −1 src/javascripts/geometry.coffee
  2. +0 −11 src/javascripts/graphics.coffee
View
10 src/javascripts/geometry.coffee
@@ -5,7 +5,15 @@ class window.Line
constructor: (@start, @finish, @width, @color) ->
draw: (canvas) ->
- canvas.line(@start.x, @start.y, @finish.x, @finish.y, @width, @color)
+ oldStrokeStyle = canvas.context.strokeStyle
+ canvas.context.strokeStyle = @color
+ canvas.context.lineWidth = @width
+ canvas.context.beginPath()
+ canvas.context.moveTo @start.x, @start.y
+ canvas.context.lineTo @finish.x, @finish.y
+ canvas.context.stroke()
+ canvas.context.closePath()
+ canvas.context.strokeStyle = oldStrokeStyle
class window.Triangle
constructor: (@point1, @point2, @point3, @color) ->
View
11 src/javascripts/graphics.coffee
@@ -21,14 +21,3 @@ class window.Canvas
step: (fun) ->
window.webkitRequestAnimationFrame fun
- line: (x1, y1, x2, y2, width, color) ->
- oldStrokeStyle = @context.strokeStyle
- @context.strokeStyle = color
- @context.lineWidth = width
- @context.beginPath()
- @context.moveTo x1, y1
- @context.lineTo x2, y2
- @context.stroke()
- @context.closePath()
- @context.strokeStyle = oldStrokeStyle
-

0 comments on commit 2c03fcb

Please sign in to comment.