Graphics Library Short Manual
Once you download the graphics library, and
load it into STk, a graphics window
will appear. This is the canvas in which you will draw graphical objects.
The following calls will return a single number, an ID for that particular
graphical object (line, oval, rectangle, text, etc.)
If you save those IDs, you can change the color of the object, bind a
mouse action with it, and so on.
- (draw-line x1 y1 x2 y2)
draws a line from (x1,y1) to (x2,y2).
- (draw-oval x1 y1 x2 y2)
draws an oval from (x1,y1) to (x2,y2).
- (fill-oval x1 y1 x2 y2)
draws a filled oval from (x1,y1) to (x2,y2).
- (draw-rectangle x1 y1 x2 y2)
draws a rectangle from (x1,y1) to (x2,y2).
- (fill-rectangle x1 y1 x2 y2)
draws a filled rectangle.
- (draw-text string x y . options)
puts text string at (x,y), centered.
The only option available is 'corner to anchor the text
at the lower left corner.
- (draw-triangle x1 y1 x2 y2 x3 y3)
draws a triangle of three points
- (fill-triangle x1 y1 x2 y2 x3 y3 color)
draws a filled triangle with the specified color
- available colors are:
"red" "white" "green" "blue" "black" "yellow" "cyan"
"magenta" "orange" "purple" "brown" "pink" "salmon"
"" (clear -- transparent) and a lot more
For example,
(define r1 (fill-rectangle 10 10 100 100))
draws a rectangle with upper left coordinate at (10, 10) and lower right
coordinate at (100, 100) and fills the rectangle with BLACK color (default)
(set-color! r1 "yellow") will change the color of the rectangle to YELLOW
We will not worry about mouse binding since it is really not part of the
curriculum. (This is for those who might want to do more fun stuff.)
Neither is the coloring and/or drawing stuff on the canvas.
When the canvas is really full of stuff, you might want to erase everything.
(clear-graphics!) will clear the canvas.
(delete! r1) will delete the rectangle object from the canvas.
For more information, take a look at the top part of the file