ART.PAS 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. Program ArtExample;
  2. {
  3. ART DEMONSTRATION PROGRAM Version 1.00A
  4. This program demonstrates the use of color graphics
  5. using TURBO PASCAL on the IBM PC and true compatibles
  6. with a color graphics adapter.
  7. INSTRUCTIONS
  8. 1. Compile and run this program using the TURBO.COM
  9. compiler.
  10. 2. Type <ESC> to exit the program, any other key to
  11. regenerate the screen.
  12. }
  13. const
  14. MemorySize = 150;
  15. var
  16. X1, X2, Y1, Y2,
  17. CurrentLine,
  18. ColorCount,
  19. IncrementCount,
  20. DeltaX1, DeltaY1, DeltaX2, DeltaY2,
  21. I, Color: integer;
  22. Ch: char;
  23. Line: array [1..MemorySize] of record
  24. LX1, LY1: integer;
  25. LX2, LY2: integer;
  26. LColor: integer;
  27. end;
  28. procedure Check;
  29. var
  30. ch: char;
  31. begin
  32. writeln('This program will only work if you have the color graphics adapter installed');
  33. write('Continue Y/N ');
  34. repeat
  35. read (Kbd,Ch)
  36. until Upcase(Ch) in ['Y','N', #27];
  37. if Upcase(Ch) in ['N', #27] then
  38. Halt;
  39. end;
  40. procedure Init;
  41. begin
  42. for I := 1 to MemorySize do
  43. with Line[I] do
  44. begin
  45. LX1 := 0;
  46. LX2 := 0;
  47. LY1 := 0;
  48. LY2 := 0;
  49. end;
  50. X1 := 0;
  51. Y1 := 0;
  52. X2 := 0;
  53. Y2 := 0;
  54. CurrentLine := 1;
  55. ColorCount := 0;
  56. IncrementCount := 0;
  57. Ch := ' ';
  58. GraphColorMode;
  59. Palette(2);
  60. Color := 2;
  61. gotoxy(1,25);
  62. write('Press any key to regenerate, ESC to stop');
  63. end;
  64. procedure AdjustX(var X,DeltaX: integer);
  65. var
  66. TestX: integer;
  67. begin
  68. TestX := X+DeltaX;
  69. if (TestX<1) or (TestX>320) then
  70. begin
  71. TestX := X;
  72. DeltaX := -DeltaX;
  73. end;
  74. X := TestX;
  75. end;
  76. procedure AdjustY(var Y,DeltaY: integer);
  77. var
  78. TestY: integer;
  79. begin
  80. TestY := Y+DeltaY;
  81. if (TestY<1) or (TestY>190) then
  82. begin
  83. TestY := Y;
  84. DeltaY := -DeltaY;
  85. end;
  86. Y := TestY;
  87. end;
  88. procedure SelectNewColor;
  89. begin
  90. Color := Random(3)+1;
  91. ColorCount := 5*(1+Random(10));
  92. end;
  93. procedure SelectNewDeltaValues;
  94. begin
  95. DeltaX1 := Random(7)-3;
  96. DeltaX2 := Random(7)-3;
  97. DeltaY1 := Random(7)-3;
  98. DeltaY2 := Random(7)-3;
  99. IncrementCount := 4*(1+Random(9));
  100. end;
  101. procedure SaveCurrentLine;
  102. begin
  103. with Line[CurrentLine] do
  104. begin
  105. LX1 := X1;
  106. LY1 := Y1;
  107. LX2 := X2;
  108. LY2 := Y2;
  109. LColor := Color;
  110. end;
  111. end;
  112. procedure Regenerate;
  113. var
  114. I: integer;
  115. begin
  116. NoSound;
  117. GraphColorMode;
  118. Palette(2);
  119. for I := 1 to MemorySize do
  120. with Line[I] do
  121. Draw(LX1,LY1,LX2,LY2,LColor);
  122. gotoxy(1,25);
  123. write('Press any key to continue, ESC to stop');
  124. read(Kbd,Ch);
  125. end;
  126. procedure WanderingLines;
  127. begin
  128. repeat
  129. repeat
  130. with Line[CurrentLine] do
  131. Draw(LX1,LY1,LX2,LY2,0);
  132. if ColorCount=0 then SelectNewColor;
  133. if IncrementCount=0 then SelectNewDeltaValues;
  134. AdjustX(X1,DeltaX1);
  135. AdjustY(Y1,DeltaY1);
  136. AdjustX(X2,DeltaX2);
  137. AdjustY(Y2,DeltaY2);
  138. Draw(X1,Y1,X2,Y2,Color);
  139. SaveCurrentLine;
  140. CurrentLine := Succ(CurrentLine);
  141. if CurrentLine>MemorySize then CurrentLine := 1;
  142. ColorCount := Pred(ColorCount);
  143. IncrementCount := Pred(IncrementCount);
  144. until KeyPressed;
  145. read(Kbd,Ch);
  146. if Ch <> #27 then
  147. begin
  148. Regenerate;
  149. gotoxy(1,25);
  150. write('Press any key to regenerate, ESC to stop');
  151. end;
  152. until Ch = #27;
  153. end;
  154. begin
  155. ClrScr;
  156. Check;
  157. Init;
  158. WanderingLines;
  159. TextMode;
  160. end.
  161.