Skip to content

Commit

Permalink
Make initial colour a parameter of 'initContext'.
Browse files Browse the repository at this point in the history
  • Loading branch information
epost committed May 10, 2015
1 parent 0647d1e commit b1da9a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/Canvas.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ foreign import data DOM :: !

type Context2DEff = Eff (dom :: DOM) Context2D

type ColorString = String

foreign import get2DContext
"""
Expand All @@ -20,15 +21,17 @@ foreign import get2DContext

foreign import initContext
"""
function initContext(context) {
return function() {
context.beginPath();
context.lineWidth = 2;
context.strokeStyle = 'purple';
return context;
};
function initContext(color) {
return function initContext(context) {
return function() {
context.beginPath();
context.lineWidth = 2;
context.strokeStyle = color;
return context;
};
}
}
""" :: forall eff. Context2D -> Context2DEff
""" :: forall eff. ColorString -> Context2D -> Context2DEff

foreign import beginStroke
"""
Expand Down
2 changes: 1 addition & 1 deletion src/CanvasCompiler.purs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ colorToCanvasStyle col = case col of
renderTurtleProgOnCanvas :: String -> TurtleProg Unit -> Context2DEff
renderTurtleProgOnCanvas canvasId prog =
get2DContext canvasId >>=
initContext >>=
initContext (colorToCanvasStyle Purple) >>=
moveTo 0 0 >>=
beginStroke >>=
compileTurtleProg prog >>=
Expand Down

0 comments on commit b1da9a6

Please sign in to comment.