HILBERT.MOD 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. (******************************************************************************)
  2. (* HILBERT.MOD *)
  3. (* *)
  4. (* MetaWINDOW pretty graphics program *)
  5. (* Transcribed from HILBERT.C METAGRAPHICS SOFTWARE CORPORATION (c) 1987-1989 *)
  6. (* *)
  7. (* PSW 06/28/91 08:30am *)
  8. (******************************************************************************)
  9. MODULE Hilbert;
  10. (*
  11. * Graphix
  12. * Release 3.7
  13. * (c) Copyright 1986-1992 PMI
  14. * Green Bay, Wisconsin
  15. * (414) 468-6040
  16. * All rights reserved
  17. *
  18. *)
  19. IMPORT GrQry;
  20. IMPORT IO;
  21. IMPORT Lib;
  22. IMPORT GrConst;
  23. IMPORT Meta;
  24. VAR
  25. GrafixCard,
  26. CommPort,
  27. xa, ya,
  28. x, y,
  29. ox, oy,
  30. i, j,
  31. h, h0,
  32. penColr,
  33. maxColr,
  34. cnt: INTEGER;
  35. vR, R1, R2: GrConst.rect;
  36. PROCEDURE a(i: INTEGER); FORWARD;
  37. PROCEDURE b(i: INTEGER); FORWARD;
  38. PROCEDURE c(i: INTEGER); FORWARD;
  39. PROCEDURE d(i: INTEGER); FORWARD;
  40. PROCEDURE IncPen();
  41. BEGIN
  42. IF (maxColr > 1) THEN
  43. penColr := penColr + 1;
  44. IF (penColr > maxColr) THEN
  45. penColr := 1;
  46. END;
  47. Meta.PenColor(penColr);
  48. END
  49. END IncPen;
  50. PROCEDURE PlotRect();
  51. BEGIN
  52. IncPen();
  53. Meta.PaintOval(R1);
  54. END PlotRect;
  55. PROCEDURE Plt();
  56. BEGIN
  57. Meta.MoveTo(ox, oy);
  58. Meta.LineTo(x, y);
  59. IncPen();
  60. ox := x;
  61. oy := y;
  62. END Plt;
  63. PROCEDURE a(i: INTEGER);
  64. BEGIN
  65. IF (i > 0) THEN
  66. d(i-1); x := x-h; Plt();
  67. a(i-1); y := y-h; Plt();
  68. a(i-1); x := x+h; Plt();
  69. b(i-1);
  70. END
  71. END a;
  72. PROCEDURE b(i: INTEGER);
  73. BEGIN
  74. IF (i > 0) THEN
  75. c(i-1); y := y+h; Plt();
  76. b(i-1); x := x+h; Plt();
  77. b(i-1); y := y-h; Plt();
  78. a(i-1);
  79. END
  80. END b;
  81. PROCEDURE c(i: INTEGER);
  82. BEGIN
  83. IF (i > 0) THEN
  84. b(i-1); x := x+h; Plt();
  85. c(i-1); y := y+h; Plt();
  86. c(i-1); x := x-h; Plt();
  87. d(i-1);
  88. END;
  89. END c;
  90. PROCEDURE d(i: INTEGER);
  91. BEGIN
  92. IF (i > 0) THEN
  93. a(i-1); y := y-h; Plt();
  94. d(i-1); x := x-h; Plt();
  95. d(i-1); y := y+h; Plt();
  96. c(i-1);
  97. END;
  98. END d;
  99. BEGIN
  100. (* init the system *)
  101. GrQry.GrQuery(GrafixCard, CommPort);
  102. i := Meta.InitGrafix(-GrafixCard);
  103. IF (i # 0) THEN
  104. (* Display reason for no go *)
  105. GrQry.GrInitErr(GrafixCard, CommPort, i);
  106. END;
  107. (* switch to graphics page *)
  108. Meta.SetDisplay(GrConst.GrafPg0);
  109. (* find number of colors supported *)
  110. maxColr := Meta.QueryColors();
  111. (* set virtual coordinate system *)
  112. Meta.SetRect(vR, 0, 0, 256, 256);
  113. Meta.VirtualRect(vR);
  114. LOOP
  115. IF (maxColr > 1) THEN
  116. Meta.RasterOp(GrConst.zREPz)
  117. ELSE
  118. Meta.RasterOp(GrConst.zXORz);
  119. Meta.PenColor(GrConst.White)
  120. END;
  121. (* do that hilbert thing *)
  122. Meta.EraseRect(vR);
  123. FOR cnt := 0 TO 4 DO
  124. i := 0;
  125. h0 := 256;
  126. h := h0;
  127. xa := h DIV 2;
  128. ya := xa;
  129. WHILE (h > 4) DO
  130. i := i+1;
  131. h := h DIV 2;
  132. xa := xa + (h DIV 2);
  133. ya := ya + (h DIV 2);
  134. x := xa;
  135. y := ya;
  136. ox := xa;
  137. oy := ya;
  138. a(i)
  139. END;
  140. (* stop if key pressed *)
  141. IF (IO.KeyPressed()) THEN
  142. EXIT
  143. END
  144. END;
  145. (* ye old bouncing box gizmo *)
  146. Meta.RasterOp(GrConst.zREPz);
  147. FOR cnt := 4 TO 0 BY -1 DO
  148. (* make a pseudorandom number *)
  149. i := INTEGER(Lib.RANDOM(30)) + 12;
  150. IF (cnt MOD 2) # 0 THEN
  151. xa := i DIV 2;
  152. ya := i DIV 3
  153. ELSE
  154. xa := i DIV 3;
  155. ya := i DIV 2
  156. END;
  157. Meta.SetRect(R1, 0, 0, i-6, i-6);
  158. FOR j := 256 TO 0 BY -1 DO
  159. PlotRect();
  160. IF ((R1.Xmax > vR.Xmax) OR (R1.Xmin < vR.Xmin)) THEN (* flip x delta *)
  161. xa := INTEGER(BITSET(xa) / BITSET(-1))
  162. END;
  163. IF ((R1.Ymax > vR.Ymax) OR (R1.Ymin < vR.Ymin)) THEN (* flip y delta *)
  164. ya := INTEGER(BITSET(ya) / BITSET(-1))
  165. END;
  166. Meta.OffsetRect(R1,xa,ya);
  167. IF (IO.KeyPressed()) THEN
  168. EXIT
  169. END
  170. END
  171. END;
  172. Meta.EraseRect(vR); (* tunnel thing *)
  173. Meta.RasterOp(GrConst.zREPz);
  174. FOR cnt := 0 TO 16 DO
  175. Meta.SetRect(R1, 124,124,132,132);
  176. Meta.SetRect(R2, 124,124,132,132);
  177. Meta.PenColor(GrConst.White);
  178. FOR i := 0 TO 32 DO
  179. IncPen();
  180. Meta.FrameRect(R1);
  181. Meta.InsetRect(R1,-4,-4)
  182. END;
  183. Meta.PenColor(GrConst.Black);
  184. FOR i := 0 TO 32 DO
  185. Meta.FrameRect(R2);
  186. Meta.InsetRect(R2,-4,-4)
  187. END;
  188. IF IO.KeyPressed() THEN
  189. EXIT
  190. END
  191. END;
  192. Meta.PenColor(GrConst.White);
  193. IF (IO.KeyPressed()) THEN
  194. EXIT
  195. END
  196. END; (* only exits from kbhit *)
  197. GrQry.GrQuit('', 0);
  198. END Hilbert.