-
Notifications
You must be signed in to change notification settings - Fork 83
/
Main.hs
64 lines (50 loc) · 1.74 KB
/
Main.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
-- A nifty animated fractal of a tree, superimposed on a background
-- of three red rectangles.
import Graphics.Gloss
main :: IO ()
main
= animate (InWindow "Zen" (800, 600) (5, 5))
(greyN 0.2)
frame
-- Produce one frame of the animation.
frame :: Float -> Picture
frame timeS
= Pictures
-- the red rectangles
[ Translate 0 150 backRec
, Translate 0 0 backRec
, Translate 0 (-150) backRec
-- the tree
, Translate 0 (-150) $ treeFrac 7 timeS
]
-- One of the red backing rectangles, with a white outline.
backRec :: Picture
backRec
= Pictures
[ Color red (rectangleSolid 400 100)
, Color white (rectangleWire 400 100) ]
-- The color for the outline of the tree's branches.
treeOutline :: Color
treeOutline = makeColor 0.3 0.3 1.0 1.0
-- The color for the shading of the tree's branches.
-- The Alpha here is set to 0.5 so the branches are partly transparent.
treeColor :: Color
treeColor = makeColor 0.0 1.0 0.0 0.5
-- The tree fractal.
-- The position of the branches changes depending on the animation time
-- as well as the iteration number of the fractal.
treeFrac :: Int -> Float -> Picture
treeFrac 0 _ = Blank
treeFrac n timeS
= Pictures
[ Color treeColor $ rectangleUpperSolid 20 300
, Color treeOutline $ rectangleUpperWire 20 300
, Translate 0 30
$ Rotate (200 * sin timeS / (fromIntegral n) )
$ Scale 0.9 0.9
$ treeFrac (n-1) timeS
, Translate 0 70
$ Rotate (-200 * sin timeS / (fromIntegral n))
$ Scale 0.8 0.8
$ treeFrac (n-1) timeS
]