home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / basic / tsrbas20.zip / WEBB.BAS < prev   
BASIC Source File  |  1991-04-03  |  5KB  |  180 lines

  1. 1000 ' Webb.bas, Version 2.0, Graphics Demo Program
  2. 1010 '
  3. 1020 print "Press ctrl-c to stop..."
  4. 1030 '
  5. 1040 ' Get graphics configuration and see if a
  6. 1050 ' graphics adapter is available
  7. 1060 '
  8. 1070 config xmax, ymax, colors, adapter, cmode
  9. 1080 if adapter = lookup ("mda")
  10. 1090    then
  11. 1100       print "No graphics adapter, or msherc not loaded."
  12. 1110       end
  13. 1120 end if
  14. 1130 '
  15. 1140 ' Select highest resolution graphics mode based 
  16. 1150 ' on type of graphics adapter
  17. 1160 '
  18. 1170 if adapter = lookup ("cga") then mode lookup ("hres2")
  19. 1180 if adapter = lookup ("ega") then mode lookup ("hres16")
  20. 1190 if adapter = lookup ("vga") then mode lookup ("vres16")
  21. 1200 if adapter = lookup ("hgc") then mode lookup ("herc")
  22. 1210 config xmax, ymax, colors, adapter, cmode
  23. 1220 type lookup ("graphics")
  24. 1230 on error goto 2710
  25. 1240 '
  26. 1250 ' Randomly generate coordinates of two points that will
  27. 1260 ' independently bounce around the screen. A line will
  28. 1270 ' be drawn between the two points to produce the desired
  29. 1280 ' visual effect.
  30. 1290 '
  31. 1300 randomize
  32. 1310 x1 = int (rnd () * xmax)
  33. 1320 x2 = int (rnd () * xmax)
  34. 1330 y1 = int (rnd () * ymax)
  35. 1340 y2 = int (rnd () * ymax)
  36. 1350 '
  37. 1360 ' Randomly generate deltas for subsequent points
  38. 1370 '
  39. 1380 dx1 = int (rnd () * 6) + 3
  40. 1390 dx2 = int (rnd () * 6) + 3
  41. 1400 dy1 = int (rnd () * 6) + 3
  42. 1410 dy2 = int (rnd () * 6) + 3
  43. 1420 '
  44. 1430 ' Initialize viewport so that min and max just
  45. 1440 ' barely fit inside screen
  46. 1450 '
  47. 1460 xmin1 = dx1
  48. 1470 xmin2 = dx2
  49. 1480 ymin1 = dy1
  50. 1490 ymin2 = dy2
  51. 1500 xmax1 = xmax - dx1
  52. 1510 xmax2 = xmax - dx2
  53. 1520 ymax1 = ymax - dy1
  54. 1530 ymax2 = ymax - dy2
  55. 1540 '
  56. 1550 ' Initialize two additional points based on the
  57. 1560 ' original points. These points will follow in the
  58. 1570 ' footsteps of the original points, erasing the lines
  59. 1580 ' between the original points.
  60. 1590 '
  61. 1600 x3 = x1
  62. 1610 x4 = x2
  63. 1620 y3 = y1
  64. 1630 y4 = y2
  65. 1640 '
  66. 1650 ' Initialize the deltas for the two points that
  67. 1660 ' will erase lines.
  68. 1670 '
  69. 1680 dx3 = dx1
  70. 1690 dx4 = dx2
  71. 1700 dy3 = dy1
  72. 1710 dy4 = dy2
  73. 1720 '
  74. 1730 ' Initialize cnt, which is used to select a new color,
  75. 1740 ' this_color, which keeps track of the current color, and
  76. 1750 ' countdown, which is the number of lines to draw before
  77. 1760 ' starting to erase any lines.
  78. 1770 '
  79. 1780 cnt = 0
  80. 1790 this_color = 1
  81. 1800 countdown = 100
  82. 1810 '
  83. 1820 ' If a point reaches a boundary then flip its delta. When
  84. 1830 ' looked at in one dimension at a time a point is just oscillating
  85. 1840 ' back and forth between its maxima and minima.
  86. 1850 '
  87. 1860 if x1 >= xmax1 or x1 <= xmin1
  88. 1870    then
  89. 1880       dx1 = -dx1
  90. 1890 end if
  91. 1900 if x2 >= xmax2 or x2 <= xmin2
  92. 1910    then
  93. 1920       dx2 = -dx2
  94. 1930 end if
  95. 1940 if y1 >= ymax1 or y1 <= ymin1
  96. 1950    then
  97. 1960       dy1 = -dy1
  98. 1970 end if
  99. 1980 if y2 >= ymax2 or y2 <= ymin2
  100. 1990    then
  101. 2000       dy2 = -dy2
  102. 2010 end if
  103. 2020 '
  104. 2030 ' Adjust a point by its delta, which is a signed
  105. 2040 ' number and may result in the point moving toward
  106. 2050 ' its maxima or toward its minima
  107. 2060 '
  108. 2070 x1 = x1 + dx1
  109. 2080 x2 = x2 + dx2
  110. 2090 y1 = y1 + dy1
  111. 2100 y2 = y2 + dy2
  112. 2110 '
  113. 2120 ' Connect the two points
  114. 2130 '
  115. 2140 moveto x1, y1
  116. 2150 lineto x2, y2
  117. 2160 '
  118. 2170 ' If the countdown timer has expired then start
  119. 2180 ' erasing lines. Otherwise jump back to beginning
  120. 2190 ' and draw the next line.
  121. 2200 '
  122. 2210 if countdown 
  123. 2220    then
  124. 2230       countdown = countdown - 1
  125. 2240       goto 1860
  126. 2250 end if
  127. 2260 '
  128. 2270 ' After the countdown timer expires, points 3
  129. 2280 ' and 4 follow exactly in the footsteps of points
  130. 2290 ' 1 and 2, erasing lines as they go.
  131. 2300 '
  132. 2310 if x3 >= xmax1 or x3 <= xmin1
  133. 2320    then
  134. 2330       dx3 = -dx3
  135. 2340 end if
  136. 2350 if x4 >= xmax2 or x4 <= xmin2
  137. 2360    then
  138. 2370       dx4 = -dx4
  139. 2380 end if
  140. 2390 if y3 >= ymax1 or y3 <= ymin1
  141. 2400    then
  142. 2410       dy3 = -dy3
  143. 2420 end if
  144. 2430 if y4 >= ymax2 or y4 <= ymin2
  145. 2440    then
  146. 2450       dy4 = -dy4
  147. 2460 end if
  148. 2470 x3 = x3 + dx3
  149. 2480 x4 = x4 + dx4
  150. 2490 y3 = y3 + dy3
  151. 2500 y4 = y4 + dy4
  152. 2510 color 0, 0
  153. 2520 moveto x3, y3
  154. 2530 lineto x4, y4
  155. 2540 '
  156. 2550 ' Select a new color, on devices capable of
  157. 2560 ' supporting multiple colors. Jump around this
  158. 2570 ' block of code if you do not want to change colors.
  159. 2580 '
  160. 2590 cnt = cnt + 1
  161. 2600 if cnt = 300
  162. 2610    then
  163. 2620       cnt = 0
  164. 2630       this_color = this_color + 1
  165. 2640       if this_color > colors
  166. 2650          then
  167. 2660             this_color = 1
  168. 2670       end if
  169. 2680 end if
  170. 2690 color this_color, 0
  171. 2700 goto 1860
  172. 2710 '
  173. 2720 ' Error Handler - This is designed to catch
  174. 2730 ' the control-c interrupt.
  175. 2740 '
  176. 2750 mode lookup ("default")
  177. 2760 type lookup ("direct")
  178. 2770 print erm()
  179. 2780 end
  180.