Think Pascal Graphics Commands
The following Think Pascal commands will be useful to you in writing
interactive graphics programs on the Macintosh. They are listed by type:
These commands will manipulate the various windows in Think
Commands to move current point:
- Open the drawing window (if not already open) and make it
the active window on the screen. Should be used when first draw to drawing
window and anytime shift from text to drawing window.
- Similarly for the text window.
- Closes all Think Pascal windows on the screen.
The drawing window remembers where the pen was last. This place in
the window is known as the current point (CP).
Commands to draw outlines of shapes:
- MoveTo(X_Coord, Y_Coord)
- Sets CP to (X_Coord, Y_Coord)
- Move(X_Diff, Y_Diff)
- Moves CP X_Diff to right and Y_Diff down.
- LineTo(X_Coord, Y_Coord)
- Draws line from CP to (X_Coord,
Y_Coord). CP is moved to new position.
- Line(X_Diff, Y_Diff)
- Draws line from CP X_Diff to right and
Y_Diff down. CP is moved to new position.
- DrawLine(Start_X, Start_Y, End_X, End_Y)
- Draws line from
(Start_X, Start_Y) to
(End_X, End_Y) leaving CP at (End_X, End_Y).
More commands to draw shapes:
- FrameRect(top, left, bottom, right)
- Draws outline of rectangle whose
highest point is at top, leftmost at left, lowest at
bottom and rightmost at right
- FrameOval(top, left, bottom, right)
- Similar to above but draws an oval
inscribed in the rectangle.
- FrameArc(top, left, bottom, right, start_angle, num_degrees)
- Draws that part of an oval ranging from start_angle to
start_angle + num_degrees (0 degrees is at top).
- FrameRoundRect(top, left, bottom, right, oval_width, oval_ht)
- Draws rectangle with rounded corners. The corners are quarter
ovals determined by oval_width and oval_ht.
Paint, Erase, and Invert can also be prefixed to Oval, Arc, and RoundRect
for similar effects.
- PaintRect(top, left, bottom, right)
- Draw outline of rectangle and
fill it with the current pen pattern.
- EraseRect(top, left, bottom, right)
- Paints rectangle with the
background color (usually white). The net effect is to erase the
- InvertRect(top, left, bottom, right)
- Reverse all pixels in the
rectangle (i.e. all formerly white dots are painted black and
Writing words on the screen:
Note that Write and Writedraw can both be used to print integers similarly
- Prints text to the Text Window and
moves cursor to next line.
- Prints integer in the Text Window and
moves cursor to next line.
- Writeln(integer : d )
- Prints integer in the Text
Window using at least d spaces and then moves cursor to next
- Prints text to the Text Window but does
not move cursor to next line.
- Prints text to the Drawing Window,
starting at the CP. The CP is left at the lower right corner of the last
Command to change pattern of pen:
Command to change colors drawn on screen:
- Changes pen pattern to New_pat if
New_pat is one of black, white, dkGray, gray, ltGray.
Notes: In the three commands above the type of New_pat is a
built-in Mac type, Pattern. The type of new_color is longint.
It is only necessary to know their types if you need to pass them as
parameters to other procedures.
- Changes color of any new objects drawn to
new_color where new_color is one of blackColor, whiteColor,
redColor, greenColor, blueColor, cyanColor, magentaColor, and
- Changes background color of all areas which will be
"erased" to new_color.
Procedures to create and test points and rectangles:
- Rect, Point
- implemented as records - Rect has fields left, top, right,
bottom : integer, Point has fields h, v : integer
- PROCEDURE SetPt(VAR pt : Point; h,v : INTEGER)
- Make point, pt,with coords (h,v)
- PROCEDURE SetRect(VAR r : Rect; left, top, right, bottom : INTEGER)
- Make rectangle with coords (left,top) and (right,bottom)
- PROCEDURE Pt2Rect( pt1, pt2 : Point; dstRect : Rect);
rectangle with pt1 and pt2 as corners
- PROCEDURE PtInRect(pt:Point; r : Rect) : BOOLEAN;
- Determine if pt is in the rectangle r.
Must still use ShowDrawing or ShowText to display the window on top of
- Set Drawing Window to fit
- Set Text Window to fit WindowRect