home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 3.ddi / BALLXOR.BA$ / BALLXOR.bin
Encoding:
Text File  |  1990-06-24  |  2.4 KB  |  99 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 = -.18
  21. WRight = .18
  22. WTop = .05
  23. WBottom = -.05
  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.       Y = ABS(COS(X)) * Decay - .14
  55.  
  56.       ' The first PUT statement places the image
  57.       ' on the screen:
  58.       PUT (X, Y), Array, XOR
  59.  
  60.       ' Use an empty FOR...NEXT loop to delay
  61.       ' the program and reduce image flicker:
  62.       FOR I = 1 TO 5: NEXT I
  63.  
  64.       IF Y < -.13 THEN Decay = Decay * .9
  65.       Esc$ = INKEY$
  66.       IF Esc$ <> "" OR Decay < .01 THEN EXIT FOR
  67.  
  68.       ' The second PUT statement erases the image and
  69.       ' restores the background:
  70.       PUT (X, Y), Array, XOR
  71.    NEXT X
  72.  
  73.    StepSize = -StepSize
  74.    StartLoop = -StartLoop
  75. LOOP UNTIL Esc$ <> "" OR Decay < .01
  76.  
  77. END
  78.  
  79. FUNCTION GetArraySize (WLeft, WRight, WTop, WBottom) STATIC
  80.  
  81.    ' Map the view coordinates passed to this function to
  82.    ' their physical-coordinate equivalents:
  83.    VLeft = PMAP(WLeft, 0)
  84.    VRight = PMAP(WRight, 0)
  85.    VTop = PMAP(WTop, 1)
  86.    VBottom = PMAP(WBottom, 1)
  87. ' Calculate the height and width in pixels
  88.    ' of the enclosing rectangle:
  89.    RectHeight = ABS(VBottom - VTop) + 1
  90.    RectWidth = ABS(VRight - VLeft) + 1
  91.  
  92.    ' Calculate size in bytes of array:
  93.    ByteSize = 4 + RectHeight * INT((RectWidth + 7) / 8)
  94.  
  95.    ' Array is integer, so divide bytes by two:
  96.    GetArraySize = ByteSize \ 2 + 1
  97. END FUNCTION
  98.  
  99.