In preparation for our next exciting project,
I set up this dot that bounced off the walls.
Then I decided to randomly change the colour at each bounce -
this was the result!
Perhaps you should try for yourself before reading on -
you'll need the new word
will draw a dot at x=10, y=20 in the current colour.
Graphics 640,480 SeedRnd MilliSecs() x=Rand(320) y=Rand(240) dx=1 dy=1 Repeat Plot x,y x=x+dx If x<0 Then x=Rand(0,1):dx=1:change_colour() End If If x>320 Then x=320:dx=-1 y=y+dy If y<0 Then y=Rand(0,1):dy=1:change_colour() End If If y>240 Then y=240:dy=-1 Until KeyHit(1) End Function change_colour() Color Rand(255),Rand(255),Rand(255) End Function
Notice that I haven't used the Back Buffer here cos I'm just trying to develop the "bouncing" idea - a bit of flicker won't matter. Notice also that I'm only using the top left quarter of the screen - you'll see why later.
We start with a random point (x,y) and set up the increments dx and dy.
After plotting the point we add dx to x and check whether x is now outside the "box". If it is, we take appropriate action then we do the same for y. The rand(0,1) is necessary to add a little randomness to the path otherwise the dot will just retrace the same path and will probably leave gaps.
So where is this heading?
What is this "next exciting project" mentioned at the top?
Well, we're going to use that "travelling dot" to specify the top-left corner of a 320x240 grab from an image.
Now you see why I restricted (x,y) to the top-left corner - our grab image will not run off the edge of the main image.
Then we're going to display that grab in the top left corner so it will be like we have a camera scanning over the image.
... SetBuffer BackBuffer() ... SetBuffer ImageBuffer(img) ...
Another little bonus for you - when you have finished,
TileBlock in your program.
Ex. 5: Use this image in a new program to produce a fullscreen 640x480 scanning effect. My solution.