• Keine Ergebnisse gefunden

GINIT: Graphics Initialization 4

The Native QuickDraw Coordinate System 4

Cartesian Coordinate System 5

QuickDraw Coordinate System 5

The Basis of QuickDraw 6

Range of Coordinates 7

A Handy Tool 7

Line Drawing 8

Window Pen Characteristics 9

Pen Size and Shape 1 1

Rounded Corner Rectangles 22

Arcs and Wedges 22

Relative Line Drawing 23

Scaling to User Coordinates 24

Rotate to Coordinates 24

Integer Trig Functions 25

Drawing to Other Windows 26

Finding Out What's There 26

Demo Programs 27

Graphic Results Page 6 - 1 June 3, 1984

. Overview

This chapter discusses how to produce graphics images on the Macintosh. It is intended to introduce you, through examples, to each of the features of the Mac FORTH graphics package. We will use the analogy of drawing with a pen on a piece of paper for clarity.

Preparat ions

It's a good idea to complete this chapter in one sitting. If you have read straight through the preceding chapters you may want to take a break, then come back to this chapter.

As you go through this chapter, let your imagination run free. Explore. Be creative! Our examples are intended to trigger your own examples. Of all the wonderful things that Macintosh graphics is, perhaps the most important feature is that it's fun to use!

QuickDraw": A Solid Base

QuickDraw is the underlying graphics package from which the Macintosh User Interface (ie; menus, windows, etc.) is constructed. Written by Bill Atkinson at Apple, QuickDraw represents many major innovations in graphics software technology.

QuickDraw lives up to its name! It's very fast. You can do good quality animation, fast interactive graphics, and complex yet speedy text displays using the full features of QuickDraw. Using QuickDraw, you can divide the Macintosh screen into a number of individual windows. Within each window you can draw:

- Straight lines of any length and width.

- Text characters in a number of proportionai and fixed spaced fonts, with variations that include boldface, italics, underline, shadow, and out 1 ine.

- A variety of shapes, either solid or hollow, including: rectangles with or without rounded corners, ovals, arcs, and wedges.

- Any other arbitrary shape or collection of shapes, again either solid or hollow.

- A picture consisting of any combination of the above items, with just a single operation.

Graphic Results Page 6 - 2 June 3, 1984

In addition, QuickDraw has some other abilities that you won't find in many other graphics packages. These features take care of most of the

"housekeeping" -- the trivial but time-consuming and bothersome overhead that's necessary to keep things in order:

- The ability to define many distinct windows on the screen, each with its own complete drawing environment -- its own coordinate system, drawing location, character set, location on the screen, and so on. You can easily switch from one such window to another.

- Full and complete "clipping" to arbitrary areas, so that drawing will occur only where you want. You don't have to worry about accidentally drawing over something else on the screen, or drawing off the screen and destroying memory.

MacFORTH provides you with direct access to most of the features of QuickDraw. Upon this strong foundation we have built a two dimensional graphics package capable of translating pictures and images which are expressed in natural user coordinates (ie; feet, miles, furlongs, centimeters) into actual images on the screen. The images that you create may be offset, rotated and scaled with respect to the window in which you are drawing.

Your Wi ndow ~ Your Canvas

All drawing occurs within the content region of a window. The content region of a window is the area inside the window excluding the title bar and any control bars. Each window is a complete and separate drawing environment that defines how and where graphic operations will have their effect. Each window has it's own coordinate system, drawing pattern, background pattern, pen size and location, and character font size and style. You may instantly switch between windows for graphic output.

The MacFORTH Window

In the following examples, you will use the MacFORTH window for graphics output. Although both interactive transactions with MacFORTH and graphics output will occur on the same window, we will later discuss how to do each in separate windows.

Now, resize the MacFORTH window to take up most of the available desktop space. (If you don't understand how to do this, run the Guided Tour to Macintosh and review the preceding chapters).

Graphic Results Page 6 - 3 June 3, 1984

GINIT: Graphics Initialization Execute

GIHIT

This will restore the state of the graphics system to it's default state. If, during the remainder of this chapter, you become confused as to what is going on (e.g. drawing in white ink on a white background) use GINIT to restore the system to a known state - black ink on white background. Vou will notice that the cursor moves immediately to the upper left corner of the window.

The Native QuickDraw Coordinate System

GINIT also resets coordinate interpretation to QuickDraw native mode, and places the pen at 0,0. Let's move the origin to the center of the screen and display the XIV axis. Execute

CENTER XV AX I S

QuickDraw native coordinates are different from the normal cartesian coordinates that that you learned in school:

Cartesian Coordinate Sytem

Higher'V' 1\

I I

1(0,0)

Lower 'X (---)

Higher 'X'

I I I

\1

lower 'V'

As you can see, in the Cartesian coordinate system, increasing V values progress illL increasing X va lues progress to the right.

Graphic Results Page 6 - 4 June 3, 1984

Look carefully at the XV axis that we've put up on the screen. The '+' sign for

Note that in native QuickDraw coordinates, increasingly higher V values progress down, and lower V values progress.YQ. X coordinates are the same in taught in school to think about coordinate systems.

Graphic Results Page 6 - 5 June 3, 1984

Execute the fo11owing example:

10 10 MOUE.TO 50 50 DRAU.TO

This will move the pen to 10, 10 and draw a line to 50, 50. Notice the line slopes downward.

MOVE.TO expects two values on the stack (the x and y coordinate of a poinO, and moves the starting point for drawing to that position. If you think of drawing lines with a pen, MOVE.TO simulates lifting the pen off of the paper and moving it to the specified location.

DRAW.TO expects two values on the stack (the x and y coordinate of a pOinO, and draws a line from the current point to the specified point. The new location becomes the starting point for the next operation. If you think of drawing lines with a pen, DRAW.TO simulates keeping the pen down as you move it to the specified location.

The Basis of QuickDraw

Without discussing the mathematics behind QuickDraw's relationship to the physical layout of graphics memory systems, it may be a little difficult to understand why this coordinate system was chosen.

Most major innovation is the result of relaxing traditionally accepted constraints and discovering whole new ways of looking at the problem.

Consider "Reverse Polish Notation". By removing the constraint of jumbled operators and operands, far simpler and more elegant code may be produced by always having operators follow operands and keeping intermediate values on a stack.

By relaxing the Cartesian Y coordinate constraint, Bill Atkinson was able to construct a mathematically pure model capable of expressing a two dimensional coordinate system on bit mapped graphics screens. Much of the startiing performance of the QuickDraw package is the result of the far simpler arithmetic relationships between pOints in graphics memory and QuickDraw native coordinates rather than Cartesian coordinates.

Don't panic. You don't have to learn a new method of drawing points if you don't want to. MacFORTH allows you to express pOints in the Cartesian coordinate system if you prefer.

Graphic Results Page 6 - 6 June 3, 1984

Try the following example: within the window will be displayed; all others are not. Execute:

CARTESIAH OH

described as "undefined". Refer to the "Scaling to User Coordinates" section of this chapter for how to deal with larger numbers.

A Handy Tool

Enter the following definition to save yourself some typing:

: CLEAH (---) PAGE CEHTER CARTESIAH OH MYAMIS

When writing and testing MacFORTH programs, any repetitive sequence should be defined and given a name. From now on we'll just use CLEAN to clean up the display and redraw the xyaxis. Try it out now, execute:

CLEAH

Graphic Results Page 6 - 7 June 3, 1984