home *** CD-ROM | disk | FTP | other *** search
- (*-------------------------------------------------------*)
- (* DETECTTE.MOD *)
- (* Abwandlung des Demoprog. Nr.6 zum TopSpeed M2 zur *)
- (* Demonstration der Prozedur "AutoGraphInit". *)
-
- MODULE DetectTest;
-
- FROM Lib IMPORT RANDOM,RANDOMIZE;
- FROM Graph IMPORT Circle,Disc,GraphMode,
- TextMode, Width,Depth;
- IMPORT IO;
-
- FROM GraphDetect IMPORT AutoGraphInit;
-
- TYPE
- FunnyType = RECORD
- q : INTEGER; (* value *)
- d : INTEGER; (* rate of change *)
- min : INTEGER;
- max : INTEGER;
- END;
-
- PROCEDURE init(VAR v:FunnyType);
- BEGIN
- v.q := v.min;
- v.d := INTEGER(RANDOM(v.max-v.min));
- END init;
-
- PROCEDURE bounce(VAR v:FunnyType);
- (* Update v.q, 'bouncing' when it goes out of range *)
- BEGIN
- WITH v DO
- q := q + d;
- IF q < min THEN
- q := 2*min-q;
- d := -d;
- END;
- IF q > max THEN
- q := 2*max-q;
- d := -d;
- END;
- END;
- END bounce;
-
- VAR
- x,y : FunnyType;
- color,radius : CARDINAL;
- Result : BOOLEAN;
-
- BEGIN
- Result := AutoGraphInit(); (* Zuerst aufrufen ! *)
- IF Result THEN (* Hat geklappt ? *)
- RANDOMIZE;
- x.max := Width-1; x.min := 0;
- y.max := Depth-1; y.min := 0;
-
- IO.WrStr('Press space to continue, any other key to stop');
- IO.WrLn;
- WHILE NOT IO.KeyPressed() DO
- END;
-
- GraphMode;
- WHILE IO.RdKey() = ' ' DO (* Bißchen Zeichnen *)
- init(x);
- init(y);
-
- REPEAT
- color := RANDOM(16);
- UNTIL color MOD 5 <> 0; (* fill using 2 colors *)
-
- radius := 2 + RANDOM(5);
- WHILE NOT IO.KeyPressed() DO
- bounce(x);
- bounce(y);
- Disc(x.q, y.q, radius, color);
- Circle(x.q, y.q, radius, color MOD 4);
- END;
-
- Disc(0,0,Width+Depth, 0); (* clear screen *)
- END;
- TextMode;
- END;
- END DetectTest.
-