added practicum files, updated gitignore
[fp1415.git] / files / practicum / TestFigure.icl
1 module TestFigure
2
3 /** Example library to demonstrate the use of Existential Types.
4 The library implements a simple set of drawing objects.
5
6 Create a new project. Set the Environment to "Object IO".
7 Set "Project Options" to "No Console".
8
9 Have fun.
10
11 Peter Achten
12 April 14 2008.
13 */
14 import StdEnv, Figure
15
16 Start :: *World -> *World
17 Start world = drawFigure figure6 world
18
19 figure0 = mkFigures
20 [ rectangle a b
21 , ellips a b
22 , text "Hello" (movePoint {vx=(b.x-a.x)/5,vy=(b.y-a.y)/2} a)
23 ]
24 where
25 a = {x=20, y=20 }
26 b = {x=180,y=180}
27
28 figure1 = mkFigures
29 [ ellips a (movePoint {vx=r,vy=r} a) \\ r <- [10,20..400]]
30 where
31 a = {x=20,y=20}
32
33 figure2 = mkFigures
34 [ text (toString c) {x=r,y=r} \\ c <- ['a'..'z'] & r <- [0,25..]]
35
36 figure3 = mkFigures [figure0,figure1,figure2]
37
38 figure4 = mkFigures
39 [ line c (movePoint {vx=toInt (r*(cos angle)),vy=toInt (r*(sin angle))} c)
40 \\ angle <- [0.0,2.0*PI/360.0..2.0*PI]
41 ]
42 where
43 c = {x=200,y=200}
44 r = 180.0
45
46 figure5 = mkFigures
47 [ text (toString cc) (movePoint {vx=toInt (radius*(cos angle)),vy=toInt (radius*(sin angle))} c)
48 \\ angle <- [0.0,2.0*PI/(toReal nrchars)..2.0*PI]
49 & cc <- chars
50 ]
51 where
52 c = {x=200,y=200}
53 radius = 180.0
54 chars = ['A'..'Z']
55 nrchars = length chars
56
57 figure5` = mkFigures
58 [ mkFigures [pencolour colour, text (toString cc) (movePoint {vx=toInt (radius*(cos angle)),vy=toInt (radius*(sin angle))} c)]
59 \\ angle <- [0.0,2.0*PI/(toReal nrchars)..2.0*PI]
60 & cc <- chars
61 & colour <- [ RGB { r = begin.r + (eind.r-begin.r)*i/nrchars
62 , g = begin.g + (eind.g-begin.g)*i/nrchars
63 , b = begin.b + (eind.b-begin.b)*i/nrchars
64 }
65 \\ i <- [1..nrchars]
66 ]
67 ]
68 where
69 c = {x=200,y=200}
70 radius = 180.0
71 chars = ['A'..'Z']
72 nrchars = length chars
73 begin = {r=255, g= 20, b=200}
74 eind = {r=0, g=234, b=100}
75
76 figure6 = mkFigures (
77 [ pensize 3 ] ++
78 [ move {vx=(edges-1)*(toInt (2.0 * radius)),vy=toInt (1.5 * radius)}
79 ( mkFigures [ line {x=toInt (cos ( i *2.0*PI/(toReal edges))*radius), y=toInt (sin ( i *2.0*PI/(toReal edges))*radius)}
80 {x=toInt (cos ((i+1.0)*2.0*PI/(toReal edges))*radius), y=toInt (sin ((i+1.0)*2.0*PI/(toReal edges))*radius)}
81 \\ i <- map toReal [1..edges]
82 ]
83 )
84 \\ edges <- [2..8]
85 ])
86 where
87 radius = 80.0