rem ================================================================== rem ex_objects. rem ================================================================== set redraw off rem Create 200 star objects. stars?[200] s = sizeof(stars) for i = 0 to sizeof(stars) - 1 stars[i] = NewStar() next do rem Update stars. proc UpdateStars stars rem Draw. rem Using a low alpha when calling cls is what makes it look as if rem the stars had tails. set color 0, 0, 0, 32 cls proc DrawStars stars set color 255, 255, 255 set caret 320, 4 center "Press Esc to quit ..." redraw wait 10 until keydown(27) rem Return a new star with some random properties. function NewStar?() rem Create a star object and set its position. star?.x# = float(rnd(640)) star.y# = float(rnd(480)) rem Set direction. angle# = float(rnd(360)) speed# = float(rnd(4) + 1) star.dx# = cos(angle)*speed star.dy# = sin(angle)*speed rem Set color. star.r = rnd(128) + 128 star.g = rnd(128) + 128 star.b = rnd(128) + 128 return star endfunc rem Update all stars in array. procedure UpdateStars(&stars?[]) s = sizeof(stars) - 1 for i = 0 to s rem Update single star. proc UpdateStar stars[i] next endproc rem Draw all stars in array. procedure DrawStars(&stars?[]) s = sizeof(stars) - 1 for i = 0 to s rem Draw single star. proc DrawStar stars[i] next endproc rem Update a star. procedure UpdateStar(&star?) rem Move. star.x# = star.x# + star.dx# star.y# = star.y# + star.dy# rem Out on one side of the screen, in on the other. if star.x# >= 640.0 star.x# = star.x# - 640.0 elseif star.x# < 0.0 star.x# = star.x# + 640.0 endif if star.y# >= 480.0 star.y# = star.y# - 480.0 elseif star.y# < 0.0 star.y# = star.y# + 480.0 endif endproc rem Draw a star. procedure DrawStar(&star?) set color star.r, star.g, star.b draw pixel int(star.x#), int(star.y#) endproc