Weird Looping squares
Author |
Message |
x-ecutioner
|
Posted: Sat Nov 08, 2008 8:35 pm Post subject: Weird Looping squares |
|
|
hi this script basically loops drawing squares, it creates an initial random co-ordinate and then determines the others. The issue is, occasionally, certain squares exceed the 500 by 500 square they are in and because of that or some strange reason the loop never exits.
code: |
%Document Properties
View.Set ("graphics: max,max")
View.Set ("position:middle, middle")
View.Set ("offscreen")
%determine how many times:)
var howmanytimes, colorz, x, y, x2, y2, c, c2 : int
put "How many different patterns would you like?"
get howmanytimes
drawfillbox (0, 0, 500, 500, 255)
c2 := 1
loop
x := Rand.Int (0, 350)
y := x
x2 := x + 150
y2 := x2
colorz := Rand.Int (0, 255)
c := 0
loop
delay (100)
drawbox (x, y, x2, y2, colorz)
drawbox (x - c, y - c, x2 + c, y2 + c, colorz)
exit when (x - c <= 0) or (x2 + c >= 500)
c := c + 10
end loop
exit when c2 = howmanytimes
end loop
|
Note: initially, the view.set was on 500 by 500
try it out and see what i mean:S
any help would be greatly appreciated, thanks |
|
|
|
|
|
Sponsor Sponsor
|
|
|
x-ecutioner
|
Posted: Sat Nov 08, 2008 8:50 pm Post subject: RE:Weird Looping squares |
|
|
okay so i fixed why it looped weird, the only issue left is that the squares still exceed the dimensions of 500:S
code: |
%Document Properties
View.Set ("graphics: max,max")
View.Set ("position:middle, middle")
View.Set ("offscreen")
%determine how many times:)
var howmanytimes, colorz, x, y, x2, y2, add, c, c2 : int
put "How many different patterns would you like?"
get howmanytimes
drawfillbox (0, 0, 500, 500, 255)
c2 := 1
loop
x := Rand.Int (0, 350)
y := x
x2 := x + 150
y2 := x2
colorz := Rand.Int (0, 255)
add := 0
c := 1
loop
delay (120)
drawbox (x - c, y - c, x2 + c, y2 + c, colorz)
exit when (x - c <= 0) or (x2 + c >= 500)
c := c + 20
end loop
exit when c2 = howmanytimes
c2 := c2 + 1
end loop
|
any ideas? |
|
|
|
|
|
TheGuardian001
|
Posted: Sat Nov 08, 2008 11:10 pm Post subject: Re: Weird Looping squares |
|
|
the problem you're having is being caused by where you put your exit when line. with your current code:
code: |
drawbox (x, y, x2, y2, colorz)
drawbox (x - c, y - c, x2 + c, y2 + c, colorz)
exit when (x - c <= 0) or (x2 + c >= 500)
|
you draw the box, then you check if it is too big. since you checked after drawing, you alway exceed the maximum and minimun by one repetition. simply move the exit when to before the drawing, and the problem should be fixed. |
|
|
|
|
|
|
|