Skip to content

Commit

Permalink
Move some ugly Canvas rendering code into a helper function.
Browse files Browse the repository at this point in the history
  • Loading branch information
epost committed Oct 28, 2014
1 parent 683e555 commit b7dc826
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/BrowserMain.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import Debug.Trace


main :: Context2DEff
main =
get2DContext "turtleCanvas" >>=
initContext >>=
beginStroke >>=
moveTo 0 0 >>=
compileTurtleProg stars >>=
endStroke
main = renderTurtleProgOnCanvas "turtleCanvas" $ do
star
penUp
forward 40
left 100
penDown
color Red
star

star = do
right 144
Expand All @@ -29,12 +30,3 @@ star = do
forward 100
right 144
forward 100

stars = do
star
penUp
forward 40
left 100
penDown
color Red
star
9 changes: 9 additions & 0 deletions src/CanvasCompiler.purs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,12 @@ colorToCanvasStyle col = case col of
Purple -> "purple"
Black -> "black"
CustomColor str -> str

renderTurtleProgOnCanvas :: String -> TurtleProg Unit -> Context2DEff
renderTurtleProgOnCanvas canvasId prog =
get2DContext canvasId >>=
initContext >>=
beginStroke >>=
moveTo 0 0 >>=
compileTurtleProg prog >>=
endStroke

0 comments on commit b7dc826

Please sign in to comment.