-
Notifications
You must be signed in to change notification settings - Fork 9
/
Shapes.hs
105 lines (84 loc) · 2.95 KB
/
Shapes.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
module CSE230.Shapes where
import CSE230.List
import CSE230.Graphics
import Htdp
-------------------------------------------------------------------------------
main :: IO ()
-------------------------------------------------------------------------------
main = do
mkRainbow
mkChess1
mkChess2
mkTriangle1
mkTriangle2
mkCarpet
-------------------------------------------------------------------------------
-- | Rainbow with 'map'
-------------------------------------------------------------------------------
mkRainbow :: IO ()
mkRainbow = save "img/rainbow.png" rainbow
rainbow :: Image
rainbow = foldr1 f xs
where
xs = map g [1..7]
f = error "fill this in"
g = error "fill this in"
-------------------------------------------------------------------------------
-- | ChessBoard with 'clone'
-------------------------------------------------------------------------------
mkChess1 :: IO ()
mkChess1 = save "img/chess1.png" chessBoard1
chessBoard1 :: Image
chessBoard1 = aboves (clone 4 row)
where
row = besides (clone 4 gridSquare)
gridSquare :: Image
gridSquare = aboves [ besides [ whSq, blSq ]
, besides [ blSq, whSq ] ]
where
whSq = square 50 solid bgCol
blSq = square 50 solid fgCol
-------------------------------------------------------------------------------
-- | ChessBoard with `iter`
-------------------------------------------------------------------------------
mkChess2 :: IO ()
mkChess2 = save "img/chess2.png" chessBoard2
chessBoard2 :: Image
chessBoard2 = iter 2 f base
where
f = error "fill this in"
base = gridSquare
-------------------------------------------------------------------------------
-- | Sierpinski Triangle with recursion
-------------------------------------------------------------------------------
mkTriangle1 :: IO ()
mkTriangle1 = save "img/triangle1.png" sierpinskiTriangle1
sierpinskiTriangle1 :: Image
sierpinskiTriangle1 = triRec 8
triRec :: Int -> Image
triRec 0 = blueTriangle
triRec n = error "fill this in"
blueTriangle :: Image
blueTriangle = triangle 5 solid fgCol
-------------------------------------------------------------------------------
-- | Sierpinski Triangle with `iter`
-------------------------------------------------------------------------------
mkTriangle2 :: IO ()
mkTriangle2 = save "img/triangle2.png" sierpinskiTriangle2
sierpinskiTriangle2 :: Image
sierpinskiTriangle2 = iter 8 f base
where
f = error "fill this in"
base = blueTriangle
-------------------------------------------------------------------------------
-- | Sierpinski Carpet with `iter`
-------------------------------------------------------------------------------
mkCarpet :: IO ()
mkCarpet = save "img/carpet.png" sierpinskiCarpet
sierpinskiCarpet :: Image
sierpinskiCarpet = iter 4 f base
where
f = error "fill this in"
base = blueSquare
blueSquare :: Image
blueSquare = square 4 solid fgCol