DrawingWindows are used for displaying graphical information to the user. For example, the code in ps3, ps12 and p13 all make use of the DrawingWindow feature. You can open as many DrawingWindows as you want. Open one with something like:
window = DrawingWindow(400,400,0,10,0,20,"MyWindow")
This will make a new window with a drawable area of 400x400, and set the coordinate frame of the window to run from x=0 to x=10 and y=0 to y=20. It will also title the window MyWindow. There are several methods one can now use to draw on the window:
- window.drawPoint(x,y[,color]) will draw a point on the window at location x,y. NOTE: the brackets around color do not mean a list, they mean optional. One can optionally specify the color of the point as a third argument, otherwise it will be blue. Colors are specified as strings, i.e. "blue" or "red"
- window.drawRect((x1,y1),(x2,y2)[,color]) will draw a rectangle on the window with one corner at x1,y1 and the other corner at x2,y2 (both are specified as tuples). The color works the same way as drawPoint, except the default is black
- window.drawLineSeg(x1, y1, x2, y2[,color, width]) will draw a line segment on the window from the point x1,y1 to the point x2,y2. default color is black and default width is 1.
- window.drawLine((a,b,c)[,color]) will draw a line on the window with parameters a, b and c as in the specification for a line in standard form, a*x+b*y+c=0.
All of these methods return an integer specifying the internal id of the item drawn on the window. This is useful for deleting certain things without clearing the whole window. for example, if you draw a line segment and want to delete it later, use code like the following:
id = window.drawLineSeg(0,0,10,10)
...
window.delete(id)
If what you want is to clear the whole window, call clear:
window.clear()