summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2015-08-14 10:57:29 +0200
committerCamil Staps2015-08-14 10:57:29 +0200
commit4c6a047b665d7eef3a4f95b155d2eae4e2a7ecf2 (patch)
tree25293a0c08f81d990cb6ba11d4ec7f52dccdc210
parentMakefile only run targets (diff)
Chapter 5 examples & tests
-rw-r--r--objectio/drawingframe.icl80
1 files changed, 76 insertions, 4 deletions
diff --git a/objectio/drawingframe.icl b/objectio/drawingframe.icl
index 1f6c8db..eaae9ac 100644
--- a/objectio/drawingframe.icl
+++ b/objectio/drawingframe.icl
@@ -15,14 +15,86 @@ Start world = startIO SDI Void (snd o openWindow Void testwindow) [ProcessClose
testwindow = Window "Test Drawing" NilLS [
WindowViewSize size,
WindowClose (noLS closeProcess),
- WindowLook True (\_ _->example),
+ WindowLook True (\_ _ . example o (setPenColour Red) o (setPenBack Green)),
WindowViewDomain {corner1=origin,corner2=maxdomain}
]
where
- size = {w=200,h=50}
+ size = {w=850,h=100}
origin = {x=(-20),y=(-20)}
maxdomain = {x=origin.x+size.w,y=origin.y+size.h}
-// Here, example draws the string "Pop" at zero
-example = drawAt zero "Pop"
+// 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)
+
+// Text
+//example = draw "p" o (draw "o") o (drawAt zero "P") //@todo Pen is not moved
+//example = drawAt {x=50,y=50} "Pop"
+
+// 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
+
+// ...
+//@todo