Think Pascal Graphics Commands

September 1997

The following Think Pascal commands will be useful to you in writing interactive graphics programs on the Macintosh. They are listed by type:

Window Commands:

These commands will manipulate the various windows in Think Pascal.

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.

Commands to move current point:

The drawing window remembers where the pen was last. This place in the window is known as the current point (CP).

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).

Commands to draw outlines of 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.

More commands to draw shapes:

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 rectangle.

InvertRect(top, left, bottom, right)
Reverse all pixels in the rectangle (i.e. all formerly white dots are painted black and vice-versa).

Paint, Erase, and Invert can also be prefixed to Oval, Arc, and RoundRect for similar effects.

Writing words on the screen:

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 line.

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 character drawn.

Note that Write and Writedraw can both be used to print integers similarly to Writeln.

Command to change pattern of pen:

Changes pen pattern to New_pat if New_pat is one of black, white, dkGray, gray, ltGray.

Command to change colors drawn on screen:

Changes color of any new objects drawn to new_color where new_color is one of blackColor, whiteColor, redColor, greenColor, blueColor, cyanColor, magentaColor, and yellowColor.

Changes background color of all areas which will be "erased" to new_color.

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.

Graphics types:

Rect, Point
implemented as records - Rect has fields left, top, right, bottom : integer, Point has fields h, v : integer

Procedures to create and test points and rectangles:

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) as corners.

PROCEDURE Pt2Rect( pt1, pt2 : Point; dstRect : Rect);
Make rectangle with pt1 and pt2 as corners

PROCEDURE PtInRect(pt:Point; r : Rect) : BOOLEAN;
Determine if pt is in the rectangle r.

Sizing Windows:

Set Drawing Window to fit WindowRect

Set Text Window to fit WindowRect

Must still use ShowDrawing or ShowText to display the window on top of screen.

Back to:

  • CS 135 home page
  • Kim Bruce's home page
  • CS Department home page