Computer Science Canada

stars

Author:  marshymell0 [ Sun May 01, 2005 1:43 pm ]
Post subject:  stars

I was wondering, is there a way to make a million of these stars like pop up and fade away?
code:
var x : int := 1
var y : int := 1
colourback (black)
process star
loop
    randint (x, 1, maxy)
    randint (y, 1, maxy)
    for decreasing kolour : 103 .. 16
        cls
        drawfillstar (x, y, x + 50, y + 50, kolour)
        View.Update
    end for
end loop
end star
fork star
cause when I fork star many times like
code:
fork star fork star fork star
it makes no difference! thx

Author:  Cervantes [ Sun May 01, 2005 3:40 pm ]
Post subject: 

You shouldn't be using processes. Read the tutorial to find out why Wink

Here's your code, process-free!

Turing:

View.Set ("offscreenonly")
colourback (black)

var star : array 1 .. 10 of
    record
        x, y : int
        clr : int
        size : int
    end record

for i : 1 .. upper (star)
    star (i).x := Rand.Int (0, maxx)
    star (i).y := Rand.Int (0, maxy)
    star (i).clr := 103
    star (i).size := 25
end for


loop
    cls
    for i : 1 .. upper (star)
        star (i).clr -= 1
        if star (i).clr <= 15 then
            star (i).x := Rand.Int (0, maxx)
            star (i).y := Rand.Int (0, maxy)
            star (i).clr := 103
        end if
        Draw.FillStar (star (i).x - star (i).size, star (i).y - star (i).size, star (i).x + star (i).size, star (i).y + star (i).size, star (i).clr)
    end for
    View.Update
    delay (2)
end loop

Author:  marshymell0 [ Sun May 01, 2005 4:07 pm ]
Post subject: 

wow. what are all these new thigns? lol arrays?

Author:  Cervantes [ Sun May 01, 2005 7:54 pm ]
Post subject: 

Yep. Want to learn?

Author:  marshymell0 [ Sun May 08, 2005 10:05 am ]
Post subject: 

wow. well, I don't think I can use arrays though lol, sry! but I modified my program now, and ended up with a flashy star being chased by a single coloured star. The only problem is that sometimes, it appears like theere's a hole int he flashy star once the solid star has caught up with the flashy star, and sometimes it doesn't. anybody know why this happens and how to get rid of it? thx! Very Happy
code:

var x : int := 1
var y : int := 1
var delaytime : int := 1
process random
    randint (delaytime, 1, 10)
    randint (x, 1, maxy - 50)
    randint (y, 110, maxy - 50)
end random
process star
    loop
        drawfillbox (1, 1, maxx, maxy, black)
        fork random
        for decreasing kolour : 103 .. 16
            delay (delaytime)
            drawfillstar (x, y, x + 50, y + 50, kolour)
            delay (delaytime)
        end for
    end loop
end star
process star2
    loop
        fork random
        for decreasing kolour : 103 .. 16
            delay (delaytime)
            drawfillstar (x+50, y+50, x, y, kolour)
        delay (delaytime)
        end for
    end loop
end star2
fork star
delay (150)
fork star2



Author:  jamonathin [ Sun May 08, 2005 1:22 pm ]
Post subject: 

Its not working because the answers to your problems are right infront of you, or at least you skipped by them. Read what Cervantes wrote and learn form that, because two things are happening. He's doing something right, and your doing something wrong <cough> process' <cough>.

Read the tutorial and study cervantes program. array's aren't that hard. And look up process under search (at the top) under turing tutorials, you'll find out why your program is so buggy.


: