Sample Graphics Commands
A Selection of Graphics Commands
The drawing window coordinates start in the top left corner. The horizontal coordinate
x increases as we move to the left up to the size of the drawing window. The vertical
coordinate y increases as we move down. The sizes of the drawing windows of different shapes are specified in the SWindows toolkit. BigSquarePair makes a 400x400 drawing window.
PaintRect
(x1, y1, x2, y2)
Paint the rectangle with corners (x1,y1) and (x2,y2)
PaintOval
(x1, y1, x2, y2) Paint the oval inscribed in that rectangle
PaintCircle
(x, y, radius) Paint a circle with center (x, y) and given radius
The verb Paint
may be replaced by:
Frame
Draws the border of the shape (e.g. FrameRect
)
Erase
Erases the area inside the shape (e.g. EraseOval
)
Invert
Inverts the colors inside the shape, black becomes white, while becomes black, colors
flip to other colors. (e.g. InvertCircle
)
DrawLine
(x1, y1, x2, y2) Draw a line between the points (x1,y1) and (x2,y2)
MoveTo
(x, y) Move the cursor into a given position, without drawing
Move
(dx, dy) Move the cursor dx distance horizontally and dy vertically
from its current position
LineTo
(x, y) like MoveTo but draw as you go
Line
(dx, dy) Like line but draw as you go.
SetForeColor
(r, g, b) Change the drawing color 0 r, g, b 255.
SetPenSize
(x, y) Make the pen a rectangle of width x and height y
(default is 1 by 1)
Use #include text.h to write text strings in the graphics window. Use MoveTo first.
ShowString
("Some text"); The text will be left justified.
ShowString
("Some text", Center); The text will be centered
These are probably all you'll need this quarter but you can read the files: graphics.h and text.h if you want to know more.
Last Updated: September 28, 1997 11:45 am by
Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #161CN,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is:
http://www.ccs.neu.edu/home/fell/COM1100/HW/OnYourOwn.html