home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 101.img / QB45-1.ZIP / BALLPSET.BAS next >
BASIC Source File  |  1987-09-23  |  3KB  |  104 lines

  1. DECLARE FUNCTION GetArraySize (WLeft, WRight, WTop, WBottom)
  2.  
  3. SCREEN 2
  4. CLS
  5.  
  6. ' Define a viewport and draw a border around it:
  7. VIEW (20, 10)-(620, 190), , 1
  8.  
  9. CONST PI = 3.141592653589#
  10.  
  11. ' Redefine the coordinates of the viewport with logical
  12. ' coordinates:
  13. WINDOW (-3.15, -.14)-(3.56, 1.01)
  14.  
  15. ' Arrays in program are now dynamic:
  16. ' $DYNAMIC
  17.  
  18. ' Calculate the logical coordinates for the top and bottom of a
  19. ' rectangle large enough to hold the image that will be drawn
  20. ' with CIRCLE and PAINT:
  21. WLeft = -.21
  22. WRight = .21
  23. WTop = .07
  24. WBottom = -.07
  25.  
  26. ' Call the GetArraySize function, passing it the rectangle's
  27. ' logical coordinates:
  28. ArraySize% = GetArraySize(WLeft, WRight, WTop, WBottom)
  29.  
  30. DIM Array(1 TO ArraySize%) AS INTEGER
  31.  
  32. ' Draw and paint the circle:
  33. CIRCLE (0, 0), .18
  34. PAINT (0, 0)
  35.  
  36. ' Store the rectangle in Array:
  37. GET (WLeft, WTop)-(WRight, WBottom), Array
  38. CLS
  39.  
  40. ' Draw a box and fill it with a pattern:
  41. LINE (-3, .8)-(3.4, .2), , B
  42. Pattern$ = CHR$(126) + CHR$(0) + CHR$(126) + CHR$(126)
  43. PAINT (0, .5), Pattern$
  44.  
  45. LOCATE 21, 29
  46. PRINT "Press any key to end"
  47.  
  48. ' Initialize loop variables:
  49. StepSize = .02
  50. StartLoop = -PI
  51. Decay = 1
  52.  
  53. DO
  54.    EndLoop = -StartLoop
  55.    FOR X = StartLoop TO EndLoop STEP StepSize
  56.  
  57.       ' Each time the ball "bounces" (hits the bottom of the
  58.       ' viewport), the Decay variable gets smaller, making the
  59.       ' height of the next bounce smaller:
  60.       Y = ABS(COS(X)) * Decay - .14
  61.       IF Y < -.13 THEN Decay = Decay * .9
  62.  
  63.       ' Stop if a key pressed or if Decay is less than .01:
  64.       Esc$ = INKEY$
  65.       IF Esc$ <> "" OR Decay < .01 THEN EXIT FOR
  66.  
  67.       ' Put the image on the screen.  The StepSize offset is
  68.       ' smaller than the border around the circle, so each time
  69.       ' the image moves, it erases any traces left from the
  70.       ' previous PUT (it also erases anything else on the
  71.       ' screen):
  72.       PUT (X, Y), Array, PSET
  73.    NEXT X
  74.  
  75.    ' Reverse direction:
  76.    StepSize = -StepSize
  77.    StartLoop = -StartLoop
  78. LOOP UNTIL Esc$ <> "" OR Decay < .01
  79.  
  80. Pause$ = INPUT$(1)
  81. END
  82. REM $STATIC
  83. REM $DYNAMIC
  84. FUNCTION GetArraySize (WLeft, WRight, WTop, WBottom) STATIC
  85.  
  86.    ' Map the logical coordinates passed to this function to
  87.    ' their physical-coordinate equivalents:
  88.    VLeft = PMAP(WLeft, 0)
  89.    VRight = PMAP(WRight, 0)
  90.    VTop = PMAP(WTop, 1)
  91.    VBottom = PMAP(WBottom, 1)
  92.  
  93.    ' Calculate the height and width in pixels of the
  94.    ' enclosing rectangle:
  95.    RectHeight = ABS(VBottom - VTop) + 1
  96.    RectWidth = ABS(VRight - VLeft) + 1
  97.  
  98.    ' Calculate size in bytes of array:
  99.    ByteSize = 4 + RectHeight * INT((RectWidth + 7) / 8)
  100.  
  101.    ' Array is integer, so divide bytes by two:
  102.    GetArraySize = ByteSize \ 2 + 1
  103. END FUNCTION
  104.