Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 brownianmotion with rectangle
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rcmp1234




PostPosted: 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!
Sponsor
Sponsor
Sponsor
sponsor
fishtastic




PostPosted: 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
BigBear




PostPosted: 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
Turing:
drawfillbox (x1, y1, x2, y2, color)

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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: