home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / mlpmodul.sit / MacLogimoPlus Documentation / sample code / ckurve2.mod next >
Encoding:
Text File  |  1990-06-14  |  2.9 KB  |  98 lines  |  [TEXT/PMED]

  1. MODULE ckurve2;      (* Franz Kronseder & Peter Fink /ETHZ/15.12.84 *)
  2.                      (* last modified 05.09.85 *)
  3. FROM SYSTEM IMPORT CODE;
  4. FROM Terminal IMPORT WriteString, Read, WriteLn;
  5. FROM InTerminal IMPORT ReadC, InDone, InEsc;
  6. FROM QuickDraw IMPORT MoveTo,LineTo,
  7.      Rect,GrafPtr,EraseRect,GetPort;
  8. VAR xpos, ypos, dummy: INTEGER;
  9.   angle: CARDINAL;
  10.   length: CARDINAL;
  11.   Figur: CHAR;   (* C = Buchstabe C, D = Drache *)
  12.   xmin, xmax, ymin, ymax: INTEGER;
  13.  
  14. CONST delta = 2;
  15. TYPE PlaceTypes = (right, left);
  16. VAR  RunMode :  (FindMax, DrawIt);
  17.      
  18. PROCEDURE InqDisplayPosition (VAR origx,origy,sizex,sizey:INTEGER);
  19.  VAR screenPort:GrafPtr;
  20.  BEGIN GetPort(screenPort);
  21.   WITH screenPort^.portRect
  22.    DO origx:=left; origy:=top;
  23.       sizex:=right-left; sizey:=bottom-top;
  24.    END;(*with*)                 
  25.  END InqDisplayPosition ;
  26.  
  27. PROCEDURE ClearScreen;
  28.  VAR thePort:GrafPtr; theRect:Rect;
  29.  BEGIN GetPort(thePort); EraseRect(thePort^.portRect); MoveTo(0,0);
  30.  END ClearScreen;
  31.  
  32. (*$S-*)
  33. PROCEDURE CBase(length: CARDINAL; angle : CARDINAL; place: PlaceTypes);
  34. BEGIN
  35.   IF length=0 THEN
  36.     CASE angle OF
  37.   0,1: xpos := xpos+delta;
  38.  |4,5: xpos := xpos-delta;
  39.  |2,3: ypos := ypos-delta;
  40.  |6,7: ypos := ypos+delta;
  41.     END;
  42.     IF RunMode = FindMax THEN
  43.       IF xpos<xmin THEN xmin := xpos
  44.       ELSIF xpos > xmax THEN xmax := xpos END;
  45.       IF ypos < ymin THEN ymin := ypos
  46.       ELSIF ypos > ymax THEN ymax := ypos END
  47.     ELSE (* RunMode = DrawIt*)
  48.       LineTo (xpos, ypos)
  49.     END
  50.   ELSIF (place = right) OR (Figur = 'C') THEN
  51.     CBase (length -1, (angle+1) MOD 8, right);
  52.     CBase (length -1, (angle+7) MOD 8, left);
  53.   ELSE (* place = left, and Figur = 'D' *)
  54.     CBase (length-1, (angle+7) MOD 8, right);
  55.     CBase (length-1, (angle+1) MOD 8, left)
  56.   END;
  57. END CBase;
  58. (*$S+*)
  59.  
  60. BEGIN
  61.  ClearScreen; 
  62.  LOOP
  63.   MoveTo(0,10);
  64.   WriteString(' ***  MODULA-Programm  CKurve2.MOD ***'); WriteLn;
  65.   MoveTo(5,300);
  66.   LOOP
  67.     WriteString (' Rekursionstiefe (range 1..14 / 0=EXIT ): ');
  68.     ReadC (length); IF InDone OR InEsc THEN EXIT END;
  69.     WriteString (' ungueltige Zahl..'); WriteLn;
  70.   END;
  71.   WriteLn;
  72.   IF InEsc OR (length = 0) THEN EXIT END;
  73.  
  74.   REPEAT
  75.    WriteString (' C-Kurve oder Drachenkurve ?  ');
  76.    WriteString(' C/D :');
  77.    Read (Figur); Figur := CAP (Figur);
  78.   UNTIL ((Figur='C') OR (Figur='D')) OR (Figur = '0');
  79.    IF (Figur='0' )THEN EXIT END;
  80.  
  81.   ClearScreen;
  82.   xmax := 0; xmin := 0; ymax := 0; ymin := 0;
  83.   xpos := 0; ypos := 0;
  84.   RunMode :=  FindMax;
  85.   CBase (length, 0, right);
  86.   InqDisplayPosition (dummy, dummy, xpos, ypos);
  87.   IF xmax-xmin < xpos 
  88.    THEN (* es hat Platz *)    xpos := 0 + xpos DIV 2  - (xmin + xmax) DIV 2
  89.    ELSE                       xpos := - xmin
  90.   END;
  91.   IF ymax - ymin < ypos 
  92.    THEN   ypos := 0 + ypos DIV 2 - (ymin + ymax) DIV 2
  93.    ELSE   ypos := - ymin
  94.   END;
  95.   MoveTo (xpos, ypos);  RunMode := DrawIt;  CBase (length, 0,right);
  96.  END; (* loop *)
  97. END ckurve2.
  98.