home *** CD-ROM | disk | FTP | other *** search
- ! Bouncing Bars.
- !
- DIM qx1(20), qy1(20), qx2(20), qy2(20)
- RANDOMIZE
-
- LET x1 = rnd !random points for ends of line segments
- LET y1 = rnd
- LET x2 = rnd
- LET y2 = rnd
- LET c = maxnum !c = clock; when to clear screen
-
- SET mode "graphics"
- LET fore$ = "white" !set colors
- SET BACK "red"
- SET COLOR fore$
-
- DO !loop drawing lines
-
- IF c>=200 then !from time to time, start new pattern
- LET c = 0
- LET xv1 = rnd/20 !by changing end point velocities
- LET xv2 = rnd/20
- LET yv1 = rnd/20
- LET yv2 = rnd/20
- END IF
-
- LET qp = mod(qp,ubound(qx1))+1 !oldest line segment on screen
-
- SET COLOR 0
- PLOT qx1(qp),qy1(qp); qx2(qp),qy2(qp) !erase oldest segment
-
- LET qx1(qp) = x1 !remember newest segment
- LET qx2(qp) = x2
- LET qy1(qp) = y1
- LET qy2(qp) = y2
- SET COLOR fore$ !draw newest segment
- PLOT x1,y1; x2,y2
-
- CALL move(x1,xv1) !compute new point positions...
- CALL move(x2,xv2) !...based on old positions
- CALL move(y1,yv1) !and velocities
- CALL move(y2,yv2)
- LET c = c+1
- LOOP
- END
-
- !
- ! Move
- !
- ! Compute new point position 'x' based on old value of 'x'
- ! and the point velocity 'v'.
- !
- ! If the new position goes off the edge of the screen,
- ! "bounce" that point back toward the center.
- !
- SUB move(x,v)
- LET x = x+v
- IF x>1 then
- LET x = 2-x
- ELSE IF x < 0 then
- LET x = -x
- ELSE
- EXIT SUB
- END IF
- LET v = -v
- END SUB
-