Computer Science Canada brownianmotion with rectangle |
Author: | rcmp1234 [ Tue Mar 04, 2008 4:43 pm ] |
Post subject: | brownianmotion with rectangle |
Hi, this is the BrownianMotion program for row:1..25 put repeat (" ", 80).. end for loop var row:=13 var column:=40 loop exit when column<1 or column>80 or row <1 or row>25 locate (row, column) put "*" delay (100) locate (row, column) put " ".. randint (row, row-1, row+1) randint (column, column-1, column+1) end loop end loop How do I modify the Brownianmotion program so that a rectangle is moving around on the window instead of an asterisk? Any help would be appreciated Thanks! |
Author: | fishtastic [ Tue Mar 04, 2008 7:30 pm ] |
Post subject: | RE:brownianmotion with rectangle |
erase locate change put "*" to drawfillbox change row & column to x and y of the rectangle |
Author: | BigBear [ Wed Mar 05, 2008 9:34 am ] | ||||||||
Post subject: | Re: brownianmotion with rectangle | ||||||||
I am guessing you do not fully understand the code. So you creating random integers and puting a * on the screen. So just change the put "*" part to
Then you can just use your random integers where you draw it (x1, y1, x2, y2) You already have random intergers row and column so row can be used for x1 and x2 and column can be used for y1, y2.
So now your code should look like this
However the rectangle is only moving within the bottom left corner. It is redrawing it (moving it) based on coordinates (where on the screen) which are made from random integers. So change the random integers it is making by changing the range of possible numbers. Since drawfillbox uses pixels to create coordinates we can create a random integer between 1 and maxx and 1 and maxy THe final program should look like this
Can be modified to make box less jumpy and move around randomly instead of magically teleport. |