home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 3.ddi / BALLPSET.BA$ / BALLPSET.bin
Encoding:
Text File  |  1990-06-24  |  2.6 KB  |  100 lines

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