brownianmotion with rectangle
Author |
Message |
rcmp1234
|
Posted: 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! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
fishtastic
![](http://compsci.ca/v3/uploads/user_avatars/2112433479479e80d9034af.png)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
BigBear
|
Posted: 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.
Turing: | drawfillbox (10 + row, 10 + column, 30 + row, 30 + column, 4) %4 is just the color
|
So now your code should look like this Turing: |
loop
var row := 13
var column := 40
loop
exit when column < 1 or column > 80
or row < 1 or row > 25
cls
drawfillbox (10 + row, 10 + column, 30 + row, 30 + column, 4)
randint (row, row - 1, row + 1)
randint (column, column - 1, column + 1)
end loop
end loop
|
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 Turing: | var x : int %changed name of row
var y : int %changed name of column
for i : 1 .. 1000 %rectangle will move 100 times
randint (x, 1, maxx) %creates random x location
randint (y, 1, maxy) %creates random y location
cls %clear the screen so no trail on rectangle and looks neater
drawfillbox (10 + x, 10 + y, 30 + x, 30 + y, 4) %draws box using random integers
delay (1000) %delays to be able to see where box is
end for |
Can be modified to make box less jumpy and move around randomly instead of magically teleport. |
|
|
|
|
![](images/spacer.gif) |
|
|