| Help With Animation 
 
	 
	
		| Author | Message |   
		| philsee 
 
 
 
 
 | 
			
				|  Posted: Sat Jan 21, 2012 3:16 pm    Post subject: Help With Animation |  |   
				| 
 |  
				| Hey everyone I'm trying to get the fireworks in my christmas scene to work but Im drawing a blank as to how to fix this problem does anyone know what I should do to fix it? 
 
 Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
 <Answer Here>
 
 
 	  | Turing: |  	  | 
<setscreen ("graphics:max,max,noecho,nocursor") %full screen
%snow from compsci.ca
View.Set ("offscreenonly") 
colorback (blue) % background of picture
const  MaxParticles := 200 
const  startfirex := 100 
const  startfirey := 100 
const  smokelength := 300 
type  Particle_Type : %declare type 
record 
x, y, speed : real 
end record 
var  Particles : array 1 . . MaxParticles of  Particle_Type %declare array of type that you've made 
for  i : 1 . . MaxParticles % give particles their initial x,y value 
Particles ( i) .x :=  Rand.Int (0 , maxx) %randmize the x position 
Particles ( i) .y :=  Rand.Int (0 , maxy) %randmize the y position 
Particles ( i) .speed :=  Rand.Int (3 , 5) %randmize the y position 
end for 
process  music
    loop
        Music.PlayFile ("turingsong.mp3")
    end loop
end  music
fork  music
loop %main animation loop 
cls %clear the screen 
type  specs :
    record 
        explosionDraw : proc  x
 
        x, y, vx, vy, vExplosionCounter, explosionCounter : real 
        c, stage, explosionType : int
    end record
const  gravity := 0 .09
var  fireworkExplosions : array 1 . . 2 of proc  z
var  fireworks : array 1 . . 10 of  specs
var  fireworkTimer : int := 0
var  fireworkCount : int := 0
var  fireworkNum : int := 0
proc  explosion1
    for  i : 1 . . 22
        Draw.ThickLine (round ( fireworks ( fireworkNum) .x + ( fireworks ( fireworkNum) .explosionCounter * cosd ( i * 16))),
            round ( fireworks ( fireworkNum) .y + ( fireworks ( fireworkNum) .explosionCounter * sind ( i * 16))),
            round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter + 5) * cosd ( i * 16))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter + 5) * sind ( i * 16))), 4 , fireworks ( fireworkNum) .c)
        Draw.ThickLine (round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter - 3) * cosd ( i * 16))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter - 3) * sind ( i * 16))),
            round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter - 7) * cosd ( i * 16))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter - 7) * sind ( i * 16))), 2 , fireworks ( fireworkNum) .c)
        Draw.ThickLine (round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter - 9) * cosd ( i * 16))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter - 9) * sind ( i * 16))),
            round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter - 12) * cosd ( i * 16))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter - 12) * sind ( i * 16))), 1 , fireworks ( fireworkNum) .c)
        Draw.ThickLine (round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter + 15) * cosd ( i * 16  + 8))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter + 15) * sind ( i * 16  + 8))),
            round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter + 20) * cosd ( i * 16  + 8))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter + 20) * sind ( i * 16  + 8))), 4 , fireworks ( fireworkNum) .c)
        Draw.ThickLine (round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter + 13) * cosd ( i * 16  + 8))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter + 13) * sind ( i * 16  + 8))),
            round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter + 9) * cosd ( i * 16  + 8))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter + 9) * sind ( i * 16  + 8))), 2 , fireworks ( fireworkNum) .c)
        Draw.ThickLine (round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter + 7) * cosd ( i * 16  + 8))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter + 7) * sind ( i * 16  + 8))),
            round ( fireworks ( fireworkNum) .x + (( fireworks ( fireworkNum) .explosionCounter + 4) * cosd ( i * 16  + 8))),
            round ( fireworks ( fireworkNum) .y + (( fireworks ( fireworkNum) .explosionCounter + 4) * sind ( i * 16  + 8))), 1 , fireworks ( fireworkNum) .c)
    end for
end  explosion1
 
fireworkExplosions (1) :=  explosion1
proc  explosion2
    for  i : 1 . . 80  - (round ( fireworks ( fireworkNum) .explosionCounter) div 3)
        var  angle : int :=  Rand.Int (0 , 360)
        Draw.Dot (round ( fireworks ( fireworkNum) .x + ( Rand.Int (0 , round ( fireworks ( fireworkNum) .explosionCounter / 1 .5)) * cosd ( angle))),
            round ( fireworks ( fireworkNum) .y + ( Rand.Int (0 , round ( fireworks ( fireworkNum) .explosionCounter / 1 .5)) * sind ( angle))),  fireworks ( fireworkNum) .c) 
        angle :=  Rand.Int (0 , 360)
        Draw.Dot (round ( fireworks ( fireworkNum) .x + ( Rand.Int (0 , round ( fireworks ( fireworkNum) .explosionCounter / 1 .5)) * cosd ( angle))),
            round ( fireworks ( fireworkNum) .y + ( Rand.Int (0 , round ( fireworks ( fireworkNum) .explosionCounter / 1 .5)) * sind ( angle))), white)
    end for
end  explosion2
 
fireworkExplosions (2) :=  explosion2
for  i : 1 . . 10 
    fireworks ( i) .x := 0 
    fireworks ( i) .y := 0 
    fireworks ( i) .vx := 0 
    fireworks ( i) .vy := 0 
    fireworks ( i) .stage := 0
end for
loop 
    fireworkTimer += 1
    if  fireworkTimer > Rand.Int (40 , 250) then 
        fireworkTimer := 0 
        fireworkCount += 1
        if  fireworkCount > 10 then 
            fireworkCount := 1
        end if 
        fireworks ( fireworkCount) .x :=  Rand.Int (0 , maxx) 
        fireworks ( fireworkCount) .y := 0 
        fireworks ( fireworkCount) .vx :=  Rand.Int ( -2500 , 2500)  / 1000 
        fireworks ( fireworkCount) .vy :=  Rand.Int (6000 , 9000)  / 1000 
        fireworks ( fireworkCount) .stage := 1 
        fireworks ( fireworkCount) .explosionCounter := 0 
        fireworks ( fireworkCount) .vExplosionCounter :=  Rand.Int (3 , 10) 
        fireworks ( fireworkCount) .c :=  Rand.Int (32 , 80) 
        fireworks ( fireworkCount) .explosionType := round ( Rand.Int (5 , 20)  / 10) 
        fireworks ( fireworkCount) .explosionDraw :=  fireworkExplosions ( fireworks ( fireworkCount) .explosionType)
    end if
    for  i : 1 . . 10 
        fireworkNum :=  i
        if  fireworks ( i) .stage = 1 then
            Draw.FillOval (round ( fireworks ( i) .x), round ( fireworks ( i) .y), 5 , 5 , fireworks ( i) .c)
            Draw.FillOval (round ( fireworks ( i) .x - fireworks ( i) .vx * 3), round ( fireworks ( i) .y - fireworks ( i) .vy * 3),  Rand.Int (2 , 3),  Rand.Int (4 , 5),  fireworks ( i) .c)
            Draw.FillOval (round ( fireworks ( i) .x - fireworks ( i) .vx * 6), round ( fireworks ( i) .y - fireworks ( i) .vy * 6),  Rand.Int (2 , 3),  Rand.Int (3 , 4),  fireworks ( i) .c)
            Draw.FillOval (round ( fireworks ( i) .x - fireworks ( i) .vx * 9), round ( fireworks ( i) .y - fireworks ( i) .vy * 9),  Rand.Int (2 , 3),  Rand.Int (2 , 3),  fireworks ( i) .c) 
            fireworks ( i) .x +=  fireworks ( i) .vx
 
            fireworks ( i) .y +=  fireworks ( i) .vy
 
            fireworks ( i) .vy -=  gravity
            if  fireworks ( i) .y > maxy or  fireworks ( i) .y < 0 then 
                fireworks ( i) .stage := 0
            end if
            if  fireworks ( i) .vy < -1 then 
                fireworks ( i) .stage := 2
            end if
        end if
        if  fireworks ( i) .stage = 2 then 
            fireworks ( i) .explosionDraw
            if  fireworks ( i) .explosionType = 1 then 
                fireworks ( i) .explosionCounter +=  fireworks ( i) .vExplosionCounter
 
                fireworks ( i) .vExplosionCounter -= 0 .1
            elsif  fireworks ( i) .explosionType = 2 then 
                fireworks ( i) .explosionCounter +=  fireworks ( i) .vExplosionCounter / 1 .5 
                fireworks ( i) .vExplosionCounter -= 0 .05
            end if
            if  fireworks ( i) .vExplosionCounter < 0 .5 then 
                fireworks ( i) .stage := 0
            end if
        end if
    end for
    View.UpdateArea (0 , 0 , maxx , maxy)
    delay (5)
    cls
end loop
colorback (blue) %colours screen blue
cls
drawfillbox (30 , 30 , 200 , 200 , brown) %body of house
drawfillbox (0 , 29 , 2000 , 0 , white)%ground 
drawfillbox (88 , 30 , 143 , 120 , black) %door
drawfillbox (55 , 130 , 95 , 150 , white) %window
drawfillbox (135 , 130 , 175 , 150 , white) %window
drawline (30 , 200 , 100 , 300 , white) %roof
 drawline (200 , 200 , 100 , 300 , white)%roof
%stars 
Draw.FillStar (300 , 500 , 310 , 510 , yellow) 
Draw.FillStar (265 , 465 , 255 , 455 , yellow) 
Draw.FillStar (400 , 550 , 410 , 540 , yellow) 
Draw.FillStar (200 , 510 , 210 , 520 , yellow) 
Draw.FillStar (115 , 550 , 125 , 560 , yellow) 
Draw.FillStar (375 , 485 , 365 , 475 , yellow) 
Draw.FillStar (65 , 480 , 75 , 490 , yellow) 
Draw.FillStar (130 , 420 , 140 , 410 , yellow) 
Draw.FillStar (750 , 550 , 760 , 560 , yellow) 
Draw.FillStar (690 , 455 , 700 , 465 , yellow) 
Draw.FillStar (720 , 430 , 730 , 440 , yellow) 
Draw.FillStar (700 , 400 , 710 , 410 , yellow) 
Draw.FillStar (670 , 405 , 680 , 415 , yellow) 
Draw.FillStar (630 , 380 , 640 , 390 , yellow) 
Draw.FillStar (605 , 350 , 615 , 360 , yellow) 
Draw.FillStar (600 , 320 , 610 , 330 , yellow) 
Draw.FillStar (500 , 500 , 490 , 490 , yellow)  
Draw.FillStar (530 , 550 , 545 , 565 , yellow)  
Draw.FillStar (510 , 530 , 500 , 520 , yellow) 
Draw.FillStar (495 , 500 , 485 , 490 , yellow) 
Draw.FillStar (490 , 470 , 480 , 460 , yellow) 
Draw.FillStar (490 , 430 , 480 , 420 , yellow) 
Draw.FillStar (460 , 475 , 450 , 465 , yellow) 
Draw.FillStar (460 , 430 , 450 , 420 , yellow) 
%snowman 
%body 
Draw.FillOval (600 , 80 , 60 , 60 , white) 
Draw.FillOval (600 , 165 , 45 , 45 , white) 
Draw.FillOval (600 , 230 , 27 , 27 , white) 
%eyes 
Draw.FillOval (610 , 240 , 5 , 5 , black) 
Draw.FillOval (590 , 240 , 5 , 5 , black) 
%nose 
Draw.Line (605 , 233 , 595 , 233 , 42) 
Draw.Line (600 , 220 , 565 , 233 , 42) 
Draw.Line (600 , 220 , 605 , 233 , 42) 
Draw.Line (600 , 220 , 604 , 233 , 42) 
Draw.Line (600 , 220 , 603 , 233 , 42) 
Draw.Line (600 , 220 , 602 , 233 , 42) 
Draw.Line (600 , 220 , 601 , 233 , 42) 
Draw.Line (600 , 220 , 600 , 233 , 42) 
Draw.Line (600 , 220 , 599 , 233 , 42) 
Draw.Line (600 , 220 , 598 , 233 , 42) 
Draw.Line (600 , 220 , 597 , 233 , 42) 
Draw.Line (600 , 220 , 596 , 233 , 42) 
 %Hat 
Draw.ThickLine (627 , 256 , 573 , 256 , 3 , black) 
Draw.ThickLine (627 , 260 , 573 , 260 , 4 , white) 
Draw.ThickLine (627 , 263 , 573 , 263 , 3 , black) 
Draw.ThickLine (629 , 266 , 629 , 273 , 2 , black) 
Draw.ThickLine (553 , 266 , 553 , 273 , 2 , black) 
Draw.FillBox (580 , 273 , 620 , 309 , black) 
%Buttons 
Draw.FillOval (600 , 135 , 5 , 5 , black) 
Draw.FillOval (600 , 155 , 5 , 5 , black) 
Draw.FillOval (600 , 175 , 5 , 5 , black) 
Draw.FillOval (600 , 195 , 5 , 5 , black) 
 drawfilloval (740 , 550 , 45 , 45 , grey)     %moon 
    drawfilloval (710 , 550 , 30 , 35 , blue)     %moon 
Draw.Line (300 , 78 , 500 , 78 , brightgreen) 
Draw.Line (300 , 78 , 380 , 158 , brightgreen) 
Draw.Line (500 , 78 , 420 , 158 , brightgreen) 
Draw.Line (320 , 158 , 380 , 158 , brightgreen) 
Draw.Line (420 , 158 , 480 , 158 , brightgreen) 
Draw.Line (320 , 158 , 380 , 218 , brightgreen) 
Draw.Line (480 , 158 , 420 , 218 , brightgreen) 
Draw.Line (380 , 218 , 340 , 218 , brightgreen) 
Draw.Line (420 , 218 , 460 , 218 , brightgreen) 
Draw.Line (340 , 218 , 380 , 258 , brightgreen) 
Draw.Line (460 , 218 , 420 , 258 , brightgreen) 
Draw.Line (420 , 258 , 440 , 258 , brightgreen) 
Draw.Line (380 , 258 , 360 , 258 , brightgreen) 
Draw.Line (400 , 298 , 360 , 258 , brightgreen) 
Draw.Line (400 , 298 , 440 , 258 , brightgreen) 
    drawfillbox (372 , 30 , 428 , 78 , 119) %christmas tree's trunk 
%star 
Draw.FillStar (380 , 290 , 420 , 330 , 30)
for  i : 1 . . MaxParticles %inside this loop we go through all the particles 1 by 1 
Particles ( i) .y -=  Particles ( i) .speed %move down the drop of rain 
if  Particles ( i) .y <= 0 then %if drop of rain has fallen to the ground, reset it's values 
Particles ( i) .y := maxy %set it's y location back to the top again 
Particles ( i) .x :=  Rand.Int (0 , maxx) %randmize the x position of rain droplets from 0 to maxx 
Particles ( i) .speed :=  Rand.Int (1 , 3) %randmize the speed of drops rain 
end if 
Draw.ThickLine (round ( Particles ( i) .x), round ( Particles ( i) .y), round ( Particles ( i) .x), round ( Particles ( i) .y + ( Particles ( i) .speed)), 3 , 0) %draw the drop of rain 
end for 
View.Update 
end loop 
>
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| Alex C. 
 
 
 
 
 | 
			
				|  Posted: Sat Jan 21, 2012 3:21 pm    Post subject: RE:Help With Animation |  |   
				| 
 |  
				| um first off, "proc" shouldn't be in a loop |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Insectoid 
 
  
 
 
 | 
			
				|  Posted: Sat Jan 21, 2012 4:45 pm    Post subject: RE:Help With Animation |  |   
				| 
 |  
				| What's the problem? |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |