
-----------------------------------
mathgenius
Fri May 18, 2007 12:19 pm

need help with the screem
-----------------------------------

I'm doing the christmas house project. i have several problems.
 :? 
hope someone can help me:D
the first problem:
I want to create a moon moving along a quadratic equation. but the problem comes from the quadratic equation. this problem i cannot fully explain. i hope someone can look up my code. make the moon goes constantly.  

 the second problem:
the screem is keep flashing as the moon goes by.

below is my code:
View.Set("offscreenonly")
View.Set("graphics:1000,700")
colourback (7)
cls
 
 
type FlakeType :                            %This is a type d
    record
        x, y, speed, size : real
    end record
 
 

var x, y, button : int := 0
var size : int := 200
var inuse : boolean := false
var Snow : array 1 .. size of FlakeType
const delaytime := 1000000
 
var aa,bb,aaa,bbb,aaaa,bbbb,aaaaa,bbbbb : int
var c,d,cc,dd,ccc,ddd,cccc,dddd:int 
var q : int
 
procedure DrawBack
 
randint(aa, 1, maxx) 
randint(bb, 400,maxx) 
randint(aaa,1,maxx)
randint(bbb,400,maxx)
randint(aaaa,1,maxx)
randint(bbbb,400,maxx)
randint(aaaaa,1,maxx)
randint(bbbbb,400,maxx)
drawfillstar(aa,bb,aa+8,bb+8,white)
drawfillstar(aaa,bbb,aaa+8,bbb+8,white)
drawfillstar(aaaa,bbbb,aaaa+8,bbbb+8,white)
drawfillstar(aaaaa,bbbb,aaaaa+8,bbbb+8,white)
 
 
 

    drawfilloval (500, 10, 500, 70, grey)
    drawfilloval (240, 250, 90, 110, green)
    drawfillbox (330, 250, 400, 350, 15)
    drawfillbox (150, 50, 400, 250, blue)
    drawfillbox (290, 50, 360, 190, 4)
    drawline (290, 120, 360, 120, brown)
    drawline (290, 121, 360, 121, brown)
    drawline (290, 122, 360, 122, brown)
    drawfilloval (305, 130, 5, 5, brown)
    drawfillbox (180, 140, 240, 200, yellow)
    drawline (210, 140, 210, 200, black)
    drawfilloval (550, 50, 60, 36, white)
    drawfilloval (550, 60, 5, 5, black)
    drawfilloval (550, 95, 50, 30, white)
    drawfilloval (550, 95, 5, 5, black)
    drawfilloval (550, 130, 35, 23, white)
    drawfilloval (550, 130, 5, 5, black)
    drawfilloval (550, 182, 40, 40, white)
    drawfilloval (550, 175, 3, 6, red)
    drawfilloval (550, 222, 50, 20, blue)
    drawfillbox (527, 232, 573, 270, 1)
    drawfilloval (535, 190, 4, 4, 1)
    drawfilloval (565, 190, 4, 4, 1)
    drawfilloval (550, 164, 8, 2, 67)
    drawfilloval (850, 70, 60, 36, green)
    drawfilloval (850, 115, 50, 30, green)
    drawfilloval (850, 150, 35, 23, green)
    drawfilloval (850, 175, 20, 40, green)
    drawfillstar (830, 200, 875, 245, yellow)
    
    randint(q,1,20)
randint(c,790,910)
randint(cc,790,910)
randint(ccc,790,910)
randint(cccc,790,910)
randint(d,34,215)
randint(dd,34,215)
randint(ddd,34,215)
randint(dddd,34,215)
drawfillstar(c,d,c+6,d+6,q)
drawfillstar(cc,dd,cc+4,dd+4,q)
drawfillstar(ccc,ddd,ccc+5,ddd+5,q)
drawfillstar(cccc,dddd,cccc+4,dddd+4,q)
    
    
end DrawBack
 
 

procedure GenerateFlakeArray
    for i : 1 .. size
        Snow (i).x := Rand.Int (0, maxx)
        Snow (i).y := Rand.Int (0, maxy)
        Snow (i).speed := Rand.Real * Rand.Int (1, 3)
        Snow (i).size := Snow (i).speed
    end for
end GenerateFlakeArray
process GenerateX
    if (not (inuse)) then
        x := Rand.Int (-600, 600)
        inuse := true
        delay (2500)
        inuse := false
    end if
end GenerateX
process LetItSnow
    loop

        fork GenerateX
        for i : 1 .. size
            if x < 500 and x > 300 then
                x := 0
            elsif x < 600 and x > 500 then
                x := 200
            elsif x < 700 and x > 600 then
                x := 400
            elsif x < 800 and x > 700 then
                x := 600
            elsif x < 300 and x > 200 then
                x := -200
            elsif x < 200 and x > 100 then
                x := -400
            elsif x < 100 and x > 0 then
                x := -600
            end if
            Snow (i).y -= Snow (i).speed
            Snow (i).x += round (x / 100)
            if Snow (i).y < 0 then
                Snow (i).y := Rand.Int (maxy, maxy + 100)
            end if
            if Snow (i).x > maxx then
                Snow (i).x := Rand.Int (-10, 0)
            end if
            if Snow (i).x < 0 then
                Snow (i).x := Rand.Int (maxx, maxx + 100)
            end if
            drawfilloval (round (Snow (i).x), round (Snow (i).y), round (Snow (i).size), round (Snow (i).size), white)
        end for
        View.Update
        for o : 1 .. size
            drawfilloval (round (Snow (o).x), round (Snow (o).y), round (Snow (o).size), round (Snow (o).size), blue)
        end for
        DrawBack %Prevents scratching the whole picture
    end loop
end LetItSnow
 
 
 
 

%Main function:
      %Draw the initial black background.
GenerateFlakeArray                          %Generate the snow flake array.
fork LetItSnow                              %Let it snow!
 
 
var hl1, hl2 : int
 

loop
    for i : 1 .. 30
        hl1 := (i) * 36
        hl2 := 610 - (15 - (i)) ** 2
       
        cls
        drawfilloval (hl1, hl2, 58, 58, yellow)
        drawfilloval (hl1, hl2, 55, 55, black)
        drawfilloval (hl1, hl2, 52, 52, yellow)
        drawfilloval (hl1, hl2, 49, 49, black)
        drawfilloval (hl1, hl2, 46, 46, yellow)
        drawfilloval (hl1, hl2, 43, 43, black)
        drawfilloval (hl1, hl2, 40, 40, yellow) %------------------------moon
       delay(300)
     

    end for
View.Update

end loop

-----------------------------------
Albrecd
Fri May 18, 2007 12:32 pm

Re: need help with the screem
-----------------------------------
The first thing you could do that would drasticly help your ability to debug your code, would be to change your variable names.  aa, aaa, aaaa, etc. are very similar, and get confusing fast, as well as not being at all descriptive.

About the choppy motion of the moon.  The reason this occurs is that you're moving it a large number of pixels (36 in the x-axis alone) every frame, with a large delay between frames (0.3 seconds).  Decreasing the distance and delay will make the movement much smoother.

As for your error with your quadratic formula, I'm not entirely sure what you are referring to; the moon does travel in a parabola.  Please specify the error.
