home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l076 / 1.ddi / BOUNCE.TRU < prev    next >
Encoding:
Text File  |  1988-08-27  |  1.6 KB  |  67 lines

  1. ! Bouncing Bars.
  2. !
  3. DIM qx1(20), qy1(20), qx2(20), qy2(20)
  4. RANDOMIZE
  5.  
  6. LET x1 = rnd                      !random points for ends of line segments
  7. LET y1 = rnd
  8. LET x2 = rnd
  9. LET y2 = rnd
  10. LET c = maxnum                    !c = clock; when to clear screen
  11.  
  12. SET mode "graphics"
  13. LET fore$ = "white"               !set colors
  14. SET BACK "red"
  15. SET COLOR fore$
  16.  
  17. DO                                !loop drawing lines
  18.  
  19.    IF c>=200 then                 !from time to time, start new pattern
  20.       LET c = 0
  21.       LET xv1 = rnd/20            !by changing end point velocities
  22.       LET xv2 = rnd/20
  23.       LET yv1 = rnd/20
  24.       LET yv2 = rnd/20
  25.    END IF
  26.  
  27.    LET qp = mod(qp,ubound(qx1))+1      !oldest line segment on screen
  28.  
  29.    SET COLOR 0
  30.    PLOT qx1(qp),qy1(qp); qx2(qp),qy2(qp)    !erase oldest segment
  31.  
  32.    LET qx1(qp) = x1               !remember newest segment
  33.    LET qx2(qp) = x2
  34.    LET qy1(qp) = y1
  35.    LET qy2(qp) = y2
  36.    SET COLOR fore$                !draw newest segment
  37.    PLOT x1,y1; x2,y2
  38.  
  39.    CALL move(x1,xv1)              !compute new point positions...
  40.    CALL move(x2,xv2)              !...based on old positions
  41.    CALL move(y1,yv1)              !and velocities
  42.    CALL move(y2,yv2)
  43.    LET c = c+1
  44. LOOP
  45. END
  46.  
  47. !
  48. !  Move
  49. !
  50. !  Compute new point position 'x' based on old value of 'x'
  51. !  and the point velocity 'v'.
  52. !
  53. !  If the new position goes off the edge of the screen,
  54. !  "bounce" that point back toward the center.
  55. !
  56. SUB move(x,v)
  57.     LET x = x+v
  58.     IF x>1 then
  59.        LET x = 2-x
  60.     ELSE IF x < 0 then
  61.        LET x = -x
  62.     ELSE
  63.        EXIT SUB
  64.     END IF
  65.     LET v = -v
  66. END SUB
  67.