diff options
author | Camil Staps | 2015-08-19 09:44:03 +0200 |
---|---|---|
committer | Camil Staps | 2015-08-19 09:44:03 +0200 |
commit | a9c3ec3ac1a98ed0910f5591efcc78ba3bdc6464 (patch) | |
tree | f807eb91bb324e02faacad15fec149f152b03cec /objectio/drawingframe.icl | |
parent | Chapter 5 examples & tests (diff) |
Comments & cleanup
Diffstat (limited to 'objectio/drawingframe.icl')
-rw-r--r-- | objectio/drawingframe.icl | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/objectio/drawingframe.icl b/objectio/drawingframe.icl index eaae9ac..00e2862 100644 --- a/objectio/drawingframe.icl +++ b/objectio/drawingframe.icl @@ -5,6 +5,11 @@ module drawingframe // // 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 @@ -12,7 +17,7 @@ import StdEnv, StdIO Start :: *World -> *World Start world = startIO SDI Void (snd o openWindow Void testwindow) [ProcessClose closeProcess] world -testwindow = Window "Test Drawing" NilLS [ +testwindow = Window "Test Drawing (chapter 5)" NilLS [ WindowViewSize size, WindowClose (noLS closeProcess), WindowLook True (\_ _ . example o (setPenColour Red) o (setPenBack Green)), @@ -24,15 +29,15 @@ where 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 } +//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) @@ -44,9 +49,24 @@ where //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 {x=50,y=50} "Pop" +//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} @@ -95,6 +115,12 @@ curve = { curve_oval = { oval_rx=5, oval_ry=3 }, // 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 |