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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
module drawingframe
// ********************************************************************************
// Clean tutorial example program.
//
// This program defines a framework in which one can test drawing functions.
// The program relies on a function, example, of type *Picture -> *Picture.
//
// Below, multiple functions `example` are given. Most of them are based on
// examples from chapter 5, Drawing, of the ObjectIO tutorial at
// http://clean.cs.ru.nl/download/supported/ObjectIO.1.2/doc/tutorial.pdf. You can
// comment out the function you want to test.
// ********************************************************************************
import StdEnv, StdIO
Start :: *World -> *World
Start world = startIO SDI Void (snd o openWindow Void testwindow) [ProcessClose closeProcess] world
testwindow = Window "Test Drawing (chapter 5)" NilLS [
WindowViewSize size,
WindowClose (noLS closeProcess),
WindowLook True (\_ _ . example o (setPenColour Red) o (setPenBack Green)),
WindowViewDomain {corner1=origin,corner2=maxdomain}
]
where
size = {w=850,h=100}
origin = {x=(-20),y=(-20)}
maxdomain = {x=origin.x+size.w,y=origin.y+size.h}
// Rainbow
example pict = foldr id pict [fill {corner1={x=x1 * w,y=0},corner2={x=x1 * w + w,y=h}} o (setPenColour (rainbow (toReal x1 / 5.0))) \\ x1 <- [0..160]]
where
w = 5
h = 100
rainbow :: a -> Colour | toReal a
rainbow i = let i` = toReal i
f = 0.3 in RGB { r = toInt (sin (f * i` + 0.0) * 127.0) + 128, // http://krazydad.com/tutorials/makecolors.php
g = toInt (sin (f * i` + PI / 1.5) * 127.0) + 128,
b = toInt (sin (f * i` + PI / 0.75) * 127.0) + 128 }
// Points
//example = drawPointAt zero o (setPenSize 1)
//example = drawPointAt zero o (setPenSize 2)
//example = drawPointAt zero o (setPenSize 3)
// Lines
//example = drawLine zero {x=50,y=50} o (setPenSize 1)
//example = drawLine zero {x=50,y=50} o (setPenSize 2)
//example = drawLine zero {x=50,y=50} o (setPenSize 3)
// Crossbox (chap. 6)
//example = seq (map draw (lines {zero & corner2 = {x=810,y=60}}))
//where
// lines {corner1=a,corner2=b} = [{line_end1=p1,line_end2=p2} \\ (p1,p2) <- [(a,c),(a,d),(a,b),(b,c),(b,d),(c,d)]]
// where
// c = {b & y=a.y}
// d = {a & y=b.y}
// Text
//example = draw "p" o (draw "o") o (drawAt zero "P") //@todo Pen is not moved
//example = drawAt zero "zero" o (drawAt {zero & y=5} "five") o (drawAt {zero & y=10} "ten")
//example = drawAt zero "zero" o (drawAt {zero & y=10} "ten")
//example = drawAt zero "zero"
//example picture
// # ((ok,font),picture) = openFont {fName="FreeMono",fStyles=[],fSize=20} picture
// | not ok = abort "Couldn't open font"
// # picture = setPenFont font picture
// = drawAt zero "zero" picture
// Ovals
//example = drawAt zero {oval_rx=5, oval_ry=3}
//example = drawAt zero {oval_rx=5, oval_ry=5}
//example = drawAt zero {oval_rx=3, oval_ry=5}
//example = drawAt zero {oval_rx=5, oval_ry=5} o (setPenSize 1)
//example = drawAt zero {oval_rx=5, oval_ry=5} o (setPenSize 2)
//example = drawAt zero {oval_rx=5, oval_ry=5} o (setPenSize 3)
//example = fillAt zero {oval_rx=5, oval_ry=3}
//example = fillAt zero {oval_rx=5, oval_ry=5}
//example = fillAt zero {oval_rx=3, oval_ry=5}
// Curves
curve = { curve_oval = { oval_rx=5, oval_ry=3 },
curve_from = PI / 6.0,
curve_to = 1.5 * PI,
curve_clockwise = True }
//example = undrawAt zero curve
//example = drawAt zero { curve & curve_clockwise = False } o (setPenSize 3)
//example = fillAt zero curve
//example = fillAt {x=50,y=50} { curve & curve_clockwise = False }
// Rectangles
//example = draw {zero & corner2={x=10,y=6}}
//example = draw {zero & corner2={x=10,y=10}}
//example = draw {zero & corner1={x=10,y=6}}
//example = draw {zero & corner2={x=10,y=10}} o (setPenSize 1)
//example = draw {zero & corner2={x=10,y=10}} o (setPenSize 2)
//example = draw {zero & corner2={x=10,y=10}} o (setPenSize 3)
//example = fill {zero & corner2={x=10,y=6}}
//example = fill {zero & corner2={x=10,y=10}}
//example = fill {zero & corner1={x=10,y=6}}
// Boxes
//example = draw {box_w = 20, box_h = 10} o (setPenSize 3)
//example = undrawAt {x=10,y=10} {box_w = -10, box_h = -20}
//example = fill {box_w = 20, box_h = 10}
//example = unfillAt {x=10,y=10} {box_w = -10, box_h = -20}
// Polygons
//example = undrawAt zero {polygon_shape=[{vx=8,vy=0},{vx=(-4),vy=8}]}
//example = drawAt zero {polygon_shape=[{vx=8,vy=0},{vx=0,vy=8},{vx=(-8),vy=0}]} o (setPenSize 3)
//example = fillAt zero {polygon_shape=[{vx=8,vy=0},{vx=(-8),vy=8},{vx=8,vy=0}]}
//example = unfillAt zero {polygon_shape=[{vx=8,vy=0},{vx=(-8),vy=8},{vx=8,vy=0}]}
// Bitmaps
//@todo
// XOR mode
//@todo
// Hilite mode
//example = hilite {corner1={x=0,y=2},corner2={x=24,y=(-10)}} o (drawAt zero "Pop")
// Clipping mode
//@todo
|