Animation exiting before executing final for loop
Author |
Message |
jinjin
|
Posted: Sat Apr 12, 2008 11:59 am Post subject: Animation exiting before executing final for loop |
|
|
Hi everybody,
I am currently creating an animation program for my Grade 10 CompSci class and everything works fine and looks good until the final for loop. Here is the animation so far:
Turing: |
setscreen ("graphics")
var d, num, num1, num2, num3, rad, col : int
rad := 16
num1 := 0
num2 := 0
num3 := 0
loop
randint (num, 20, 103)
drawbox (num1, num1, num2, num2, num )
delay (10)
randint (num, 20, 103)
drawbox (maxx - num3, maxy - num3, maxx - num2, maxy - num2, num )
delay (10)
randint (num, 20, 103)
drawbox (maxx - num3, num1, maxx - num2, num2, num )
delay (10)
randint (num, 20, 103)
drawbox (num1, maxy - num3, num2, maxy - num2, num )
exit when num1 = 200
num1 := num1 + 1
num2 := num2 + 2
num3 := num3 + 1
end loop
View.Set ("offscreenonly")
for xb : 40 .. maxx - 40 by 3
randint (col, 1, 255)
drawfilloval (xb, maxy - 40, rad, rad, col )
View.Update
delay (10)
drawfilloval (xb, maxy - 40, rad, rad, col )
end for
for decreasing yb : maxy - 40 .. 40 by 3
randint (col, 1, 255)
drawfilloval (maxx - 40, yb, rad, rad, col )
View.Update
delay (10)
drawfilloval (maxx - 40, yb, rad, rad, col )
end for
for decreasing xb : maxx - 40 .. 40 by 3
randint (col, 1, 255)
drawfilloval (xb, 40, rad, rad, col )
View.Update
delay (10)
drawfilloval (xb, 40, rad, rad, col )
end for
for yb : 40 .. maxy - 40 by 3
randint (col, 1, 255)
drawfilloval (40, yb, rad, rad, col )
View.Update
delay (10)
drawfilloval (40, yb, rad, rad, col )
end for
View.Set ("offscreenonly")
for decreasing yb : maxy - 60 .. 60 by 2
randint (col, 1, 255)
drawfilloval (60, yb, 13, 13, col )
View.Update
delay (10)
drawfilloval (60, yb, 13, 13, col )
end for
for xb : 60 .. maxx - 60 by 2
randint (col, 1, 255)
drawfilloval (xb, 60, 13, 13, col )
View.Update
delay (10)
drawfilloval (xb, 60, 13, 13, col )
end for
for yb : 60 .. maxy - 60 by 2
randint (col, 1, 255)
drawfilloval (maxx - 60, yb, 13, 13, col )
View.Update
delay (10)
drawfilloval (maxx - 60, yb, 13, 13, col )
end for
for decreasing xb : maxx - 60 .. 60 by 2
randint (col, 1, 255)
drawfilloval (xb, maxy - 60, 13, 13, col )
View.Update
delay (10)
drawfilloval (xb, maxy - 60, 13, 13, col )
end for
View.Set ("offscreenonly")
for decreasing yb : maxy - 80 .. 80 by 4
randint (col, 1, 255)
drawfilloval (80, yb, 10, 10, col )
View.Update
delay (10)
drawfilloval (80, yb, 10, 10, col )
end for
for xb : 80 .. maxx - 70 by 4
randint (col, 1, 255)
drawfilloval (xb, 80, 10, 10, col )
View.Update
delay (10)
drawfilloval (xb, 80, 10, 10, col )
end for
for yb : 80 .. maxy - 80 by 4
randint (col, 1, 255)
drawfilloval (maxx - 70, yb, 10, 10, col )
View.Update
delay (10)
drawfilloval (maxx - 70, yb, 10, 10, col )
end for
for decreasing xb : maxx - 70 .. 80 by 4
randint (col, 1, 255)
drawfilloval (xb, maxy - 80, 10, 10, col )
View.Update
delay (10)
drawfilloval (xb, maxy - 80, 10, 10, col )
end for
for decreasing xb : 300 .. 90 by 2
drawfillbox (0, 0, 0, xb, black)
View.Update
delay (20)
drawfillbox (558, 310, 90, xb, black)
end for
%% THE BELOW LINES OF CODE DO NOT EXECUTE
for xy : 1 .. maxx by 3
drawoval (350, 250, xy + 4, xy + 4, 35)
drawfilloval (350, 250, xy + 4, xy + 4, 7)
end for
for fx : 1 .. 430
drawfilloval (350, 250, fx + 4, fx + 4, 31)
end for
%% END OF LINES OF CODE THAT DO NOT EXECUTE
|
The for loop at the end which wipes the screen with an expanding dark circle and then a white circle does not work. All that happens at the end is that it delays for a few seconds and then the screen goes white. I am not sure why this code does not work as I have tried running the loop by itself (without all the other animation code) and it works fine. Any help is appreciated.
Thanks
jinjin |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: Sat Apr 12, 2008 12:06 pm Post subject: RE:Animation exiting before executing final for loop |
|
|
Did you use View.Update in the loops? |
|
|
|
|
![](images/spacer.gif) |
jinjin
|
Posted: Sat Apr 12, 2008 12:48 pm Post subject: Re: RE:Animation exiting before executing final for loop |
|
|
CodeMonkey2000 @ Sat Apr 12, 2008 12:06 pm wrote: Did you use View.Update in the loops?
Ah, you're right, that was the problem. It works perfect now, thanks CodeMonkey ![Very Happy Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
jinjin
|
Posted: Sat Apr 12, 2008 1:38 pm Post subject: Re: Animation exiting before executing final for loop |
|
|
Sorry for the double post but there is a new problem with the same program. When I try looping the entire animation so that it will loop forever, it works fine for the first time it runs but for the second time it runs, the program skips the first loop and goes onto the for loop. Plus, it leaves an unusual traced shape in the background on its second run.
Here's the updated code:
Turing: |
setscreen ("graphics")
var d, num, num1, num2, num3, rad, col : int
rad := 16
num1 := 0
num2 := 0
num3 := 0
loop
%% IN THE SECOND RUN, THE FOLLOWING LOOP IS SKIPPED
loop
randint (num, 20, 103)
drawbox (num1, num1, num2, num2, num )
delay (10)
randint (num, 20, 103)
drawbox (maxx - num3, maxy - num3, maxx - num2, maxy - num2, num )
delay (10)
randint (num, 20, 103)
drawbox (maxx - num3, num1, maxx - num2, num2, num )
delay (10)
randint (num, 20, 103)
drawbox (num1, maxy - num3, num2, maxy - num2, num )
exit when num1 = 200
num1 := num1 + 1
num2 := num2 + 2
num3 := num3 + 1
end loop
%% END OF LOOP SKIPPED IN SECOND RUN
View.Set ("offscreenonly")
for xb : 40 .. maxx - 40 by 3
randint (col, 1, 255)
drawfilloval (xb, maxy - 40, rad, rad, col )
View.Update
delay (10)
drawfilloval (xb, maxy - 40, rad, rad, col )
end for
for decreasing yb : maxy - 40 .. 40 by 3
randint (col, 1, 255)
drawfilloval (maxx - 40, yb, rad, rad, col )
View.Update
delay (10)
drawfilloval (maxx - 40, yb, rad, rad, col )
end for
for decreasing xb : maxx - 40 .. 40 by 3
randint (col, 1, 255)
drawfilloval (xb, 40, rad, rad, col )
View.Update
delay (10)
drawfilloval (xb, 40, rad, rad, col )
end for
for yb : 40 .. maxy - 40 by 3
randint (col, 1, 255)
drawfilloval (40, yb, rad, rad, col )
View.Update
delay (10)
drawfilloval (40, yb, rad, rad, col )
end for
View.Set ("offscreenonly")
for decreasing yb : maxy - 60 .. 60 by 2
randint (col, 1, 255)
drawfilloval (60, yb, 13, 13, col )
View.Update
delay (10)
drawfilloval (60, yb, 13, 13, col )
end for
for xb : 60 .. maxx - 60 by 2
randint (col, 1, 255)
drawfilloval (xb, 60, 13, 13, col )
View.Update
delay (10)
drawfilloval (xb, 60, 13, 13, col )
end for
for yb : 60 .. maxy - 60 by 2
randint (col, 1, 255)
drawfilloval (maxx - 60, yb, 13, 13, col )
View.Update
delay (10)
drawfilloval (maxx - 60, yb, 13, 13, col )
end for
for decreasing xb : maxx - 60 .. 60 by 2
randint (col, 1, 255)
drawfilloval (xb, maxy - 60, 13, 13, col )
View.Update
delay (10)
drawfilloval (xb, maxy - 60, 13, 13, col )
end for
View.Set ("offscreenonly")
for decreasing yb : maxy - 80 .. 80 by 4
randint (col, 1, 255)
drawfilloval (80, yb, 10, 10, col )
View.Update
delay (10)
drawfilloval (80, yb, 10, 10, col )
end for
for xb : 80 .. maxx - 70 by 4
randint (col, 1, 255)
drawfilloval (xb, 80, 10, 10, col )
View.Update
delay (10)
drawfilloval (xb, 80, 10, 10, col )
end for
for yb : 80 .. maxy - 80 by 4
randint (col, 1, 255)
drawfilloval (maxx - 70, yb, 10, 10, col )
View.Update
delay (10)
drawfilloval (maxx - 70, yb, 10, 10, col )
end for
for decreasing xb : maxx - 70 .. 80 by 4
randint (col, 1, 255)
drawfilloval (xb, maxy - 80, 10, 10, col )
View.Update
delay (10)
drawfilloval (xb, maxy - 80, 10, 10, col )
end for
for decreasing xb : 300 .. 90 by 2
drawfillbox (0, 0, 0, xb, black)
View.Update
delay (20)
drawfillbox (558, 310, 90, xb, black)
end for
View.Set ("offscreenonly")
for xy : 1 .. maxx by 3
drawoval (350, 250, xy + 4, xy + 4, 35)
View.Update
drawfilloval (350, 250, xy + 4, xy + 4, 7)
end for
for fx : 1 .. 430
View.Update
drawfilloval (350, 250, fx + 4, fx + 4, 31)
end for
end loop
|
Once again, any help is appreciated. Thanks ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
BigBear
|
Posted: Sat Apr 12, 2008 1:56 pm Post subject: Re: Animation exiting before executing final for loop |
|
|
The first loop is skipped because your exit statement is true.
code: | exit when num1 = 200 |
It goes through the first time and increases num1 but it is already = 200 the second time. Just re declare your variables in the beginning of your loop.
Also for me the last giant growing white circle didn't quite erase everything, I just increased 430 to 530 but if it works for you it's all good.
Hope this helps, |
|
|
|
|
![](images/spacer.gif) |
jinjin
|
Posted: Sat Apr 12, 2008 2:21 pm Post subject: Re: Animation exiting before executing final for loop |
|
|
Thanks BigBear, it loops perfectly now. I would have never thought about that exit statement. I'll remember to check those for the next time I make a looping animation as I am still new at this. Also, I think the white circle erased everything fine for me but thanks for the advice
Regards,
jinjin |
|
|
|
|
![](images/spacer.gif) |
|
|