Skip to content
This repository was archived by the owner on Oct 23, 2018. It is now read-only.

Commit ce3dd07

Browse files
committed
Fix #107 - explicitly discard contexts
1 parent 970cea5 commit ce3dd07

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

exercises/chapter9/src/Example/LSystem.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ main = void $ unsafePartial do
5151
interpret state F = do
5252
let x = state.x + Math.cos state.theta * 1.5
5353
y = state.y + Math.sin state.theta * 1.5
54-
moveTo ctx state.x state.y
55-
lineTo ctx x y
54+
_ <- moveTo ctx state.x state.y
55+
_ <- lineTo ctx x y
5656
pure { x, y, theta: state.theta }
5757

5858
initialState :: State
5959
initialState = { x: 120.0, y: 200.0, theta: 0.0 }
6060

61-
setStrokeStyle "#000000" ctx
61+
_ <- setStrokeStyle "#000000" ctx
6262

6363
strokePath ctx $ lsystem initial productions interpret 5 initialState

exercises/chapter9/src/Example/Random.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ main = void $ unsafePartial do
1717
Just canvas <- getCanvasElementById "canvas"
1818
ctx <- getContext2D canvas
1919

20-
setFillStyle "#FF0000" ctx
21-
setStrokeStyle "#000000" ctx
20+
_ <- setFillStyle "#FF0000" ctx
21+
_ <- setStrokeStyle "#000000" ctx
2222

2323
for_ (1 .. 100) \_ -> do
2424
x <- random
@@ -33,5 +33,5 @@ main = void $ unsafePartial do
3333
, end : Math.pi * 2.0
3434
}
3535

36-
fillPath ctx path
36+
_ <- fillPath ctx path
3737
strokePath ctx path

exercises/chapter9/src/Example/Rectangle.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ main = void $ unsafePartial do
1313
Just canvas <- getCanvasElementById "canvas"
1414
ctx <- getContext2D canvas
1515

16-
setFillStyle "#0000FF" ctx
16+
_ <- setFillStyle "#0000FF" ctx
1717

1818
fillPath ctx $ rect ctx
1919
{ x: 250.0

exercises/chapter9/src/Example/Refs.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ import Graphics.Canvas (Context2D, CANVAS, getContext2D, getCanvasElementById,
1616
import Math as Math
1717
import Partial.Unsafe (unsafePartial)
1818

19-
render :: forall eff. Int -> Context2D -> Eff (canvas :: CANVAS | eff) Context2D
20-
render count ctx = do
21-
setFillStyle "#FFFFFF" ctx
19+
render :: forall eff. Int -> Context2D -> Eff (canvas :: CANVAS | eff) Unit
20+
render count ctx = void do
21+
_ <- setFillStyle "#FFFFFF" ctx
2222

23-
fillPath ctx $ rect ctx
23+
_ <- fillPath ctx $ rect ctx
2424
{ x: 0.0
2525
, y: 0.0
2626
, w: 600.0
2727
, h: 600.0
2828
}
2929

30-
setFillStyle "#00FF00" ctx
30+
_ <- setFillStyle "#00FF00" ctx
3131

3232
withContext ctx do
3333
let scaleX = Math.sin (toNumber count * Math.pi / 4.0) + 1.5
3434
let scaleY = Math.sin (toNumber count * Math.pi / 6.0) + 1.5
3535

36-
translate { translateX: 300.0, translateY: 300.0 } ctx
37-
rotate (toNumber count * Math.pi / 18.0) ctx
38-
scale { scaleX: scaleX, scaleY: scaleY } ctx
39-
translate { translateX: -100.0, translateY: -100.0 } ctx
36+
_ <- translate { translateX: 300.0, translateY: 300.0 } ctx
37+
_ <- rotate (toNumber count * Math.pi / 18.0) ctx
38+
_ <- scale { scaleX: scaleX, scaleY: scaleY } ctx
39+
_ <- translate { translateX: -100.0, translateY: -100.0 } ctx
4040

4141
fillPath ctx $ rect ctx
4242
{ x: 0.0

exercises/chapter9/src/Example/Shapes.purs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ main = void $ unsafePartial do
2626
Just canvas <- getCanvasElementById "canvas"
2727
ctx <- getContext2D canvas
2828

29-
setFillStyle "#0000FF" ctx
29+
_ <- setFillStyle "#0000FF" ctx
3030

31-
fillPath ctx $ rect ctx $ translate (-200.0) (-200.0)
31+
_ <- fillPath ctx $ rect ctx $ translate (-200.0) (-200.0)
3232
{ x: 250.0
3333
, y: 250.0
3434
, w: 100.0
3535
, h: 100.0
3636
}
3737

38-
setFillStyle "#00FF00" ctx
38+
_ <- setFillStyle "#00FF00" ctx
3939

40-
fillPath ctx $ arc ctx $ translate 200.0 200.0
40+
_ <- fillPath ctx $ arc ctx $ translate 200.0 200.0
4141
{ x: 300.0
4242
, y: 300.0
4343
, r: 50.0
4444
, start: Math.pi * 5.0 / 8.0
4545
, end: Math.pi * 2.0
4646
}
4747

48-
setFillStyle "#FF0000" ctx
48+
_ <- setFillStyle "#FF0000" ctx
4949

5050
fillPath ctx $ do
51-
moveTo ctx 300.0 260.0
52-
lineTo ctx 260.0 340.0
53-
lineTo ctx 340.0 340.0
51+
_ <- moveTo ctx 300.0 260.0
52+
_ <- lineTo ctx 260.0 340.0
53+
_ <- lineTo ctx 340.0 340.0
5454
closePath ctx

0 commit comments

Comments
 (0)