From b1da9a6a8c3ae7eb5a8c3dc254139fc484309118 Mon Sep 17 00:00:00 2001 From: Erik Post Date: Sun, 10 May 2015 12:56:10 +0200 Subject: [PATCH] Make initial colour a parameter of 'initContext'. --- src/Canvas.purs | 19 +++++++++++-------- src/CanvasCompiler.purs | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Canvas.purs b/src/Canvas.purs index cfb9863..7487fe0 100644 --- a/src/Canvas.purs +++ b/src/Canvas.purs @@ -8,6 +8,7 @@ foreign import data DOM :: ! type Context2DEff = Eff (dom :: DOM) Context2D +type ColorString = String foreign import get2DContext """ @@ -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 """ diff --git a/src/CanvasCompiler.purs b/src/CanvasCompiler.purs index 382c772..6874a25 100644 --- a/src/CanvasCompiler.purs +++ b/src/CanvasCompiler.purs @@ -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 >>=