home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-01-19 | 3.8 KB | 134 lines | [TEXT/MPS ] |
- Program SillyBalls;
- {
- purpose To demonstrate a simple color App using Color QuickDraw.
- It draws colored balls in a color window, then uses colored
- text inverted in the ball. The ball location and color is Random.
-
- This program was written by Bo3b Johnson, 1/88.
-
- The inverted Bob text was a RIck Blair special concept,
- kept for obvious aesthetic reasons.
-
- You can build the program with this junk:
- pascal SillyBalls.p
- Link SillyBalls.p.o ∂
- "yourDisk:MPW:Libraries:"Interface.o ∂
- "yourDisk:MPW:Libraries:"Runtime.o ∂
- "yourDisk:MPW:PLibraries:"Paslib.o ∂
- -o SillyBalls
- SillyBalls
-
- }
-
- USES Memtypes,QuickDraw,OSIntf,ToolIntf;
-
- CONST
- BallWidth = 20;
- BallHeight = 20;
- BobSize = 8; { Size of text in each ball. }
-
- VAR
- mainPtr: WindowPtr;
- windRect: Rect;
-
-
- { Initialize everything for the program, make sure we can run. }
-
- Procedure Initialize;
-
- VAR
- error: OSErr;
- theWorld: SysEnvRec;
-
- BEGIN
- { Test the computer to be sure we can do color. If not we would crash, which
- would be bad. If we can’t run, just beep and exit. }
- error := SysEnvirons(1, theWorld);
- IF NOT theWorld.hasColorQD THEN BEGIN
- SysBeep (50);
- ExitToShell; { If no color QD, we must leave. }
- END;
-
- { Initialize all the needed managers. }
- InitGraf(@thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(NIL);
- InitCursor;
-
- { To make the Random sequences truly random, we need to make the seed start
- at a different number. An easy way to do this is to put the current time
- and date into the seed. Since it is always incrementing the starting seed
- will always be different. Don’t for each call of Random, or the sequence
- will no longer be random. Only needed once, here in the init. }
- GetDateTime (RandSeed);
-
- { Make a new window for drawing in, and it must be a color window. The window is
- full screen size, made smaller to make it more visible. }
- windRect := screenBits.bounds;
- InsetRect (windRect, 50, 50);
- MainPtr := NewCWindow(NIL, windRect, 'Bo3b Land', TRUE, documentProc,
- Pointer(-1), FALSE, 0);
-
- SetPort(MainPtr); { set window to current graf port }
- TextSize(BobSize); { smaller font for drawing. }
- END; { Initialize }
-
-
- { NewBall: make another ball in the window at a random location and color. }
-
- Procedure NewBall;
-
- VAR
- ballColor: RGBColor;
- ballRect: Rect;
- newLeft,
- newTop: LongInt;
-
- BEGIN
- { Make a random new color for the ball. }
- WITH ballColor DO BEGIN
- red := Random; green := Random; blue := Random;
- END;
-
- { Set that color as the new color to use in drawing. }
- RGBForeColor (ballColor);
-
- { Make a Random new location for the ball, that is normalized to the window size.
- This makes the Integer from Random into a number that is 0..windRect.bottom
- and 0..windRect.right. They are normalized so that we don't spend most of our
- time drawing in places outside of the window. }
- newTop := Random; newLeft := Random;
- newTop := ((newTop+32767) * windRect.bottom) DIV 65536;
- newLeft := ((newLeft+32767) * windRect.right) DIV 65536;
- SetRect(ballRect, newLeft, newTop, newLeft+BallWidth, newTop+BallHeight);
-
- { Move pen to the new location, and paint the colored ball. }
- MoveTo(newLeft, newTop);
- PaintOval (ballRect);
-
- { Move the pen to the middle of the new ball position, for the text }
- MoveTo(ballRect.Left + BallWidth DIV 2 - BobSize,
- ballRect.Top + BallHeight DIV 2 + BobSize DIV 2 -1);
-
- { Invert the color and draw the text there. This won’t look quite right in 1 bit
- mode, since the foreground and background colors will be the same. Color
- QuickDraw special cases this to not invert the color, to avoid invisible
- drawing. }
- InvertColor(ballColor);
- RGBForeColor(ballColor);
- DrawString('Bob');
- END; { NewBall }
-
-
- BEGIN { Main body of program SillyBalls }
- Initialize;
-
- Repeat
- NewBall;
- Until Button;
-
- END. { SillyBalls }
-