1. Newbie challenge, guru brain candy

Following is a very simple graphics program.  For me, I just wanted a =
break from serious programming; but then I thought this might make a =
good challenge for the newbies. =20

Question 1:  How can I change the speed of the program? (Hint: look in =
the docs for the time() function)

Question 2:  How can I change the shape of the stars? (Hint: look up =
display_image(s1,s2) in the docs)

Bonus question:  Change the program from twinkling stars to falling =
snow. =20

Let us know if you've solved it, or if you're stuck.

----------------- twinkle.ex ---------------------------------

include image.e
include graphics.e

constant MAXSTARS =3D 75
constant TWINKLES =3D 15
constant STAR_IMAGE =3D {{1,0,1},{0,1,0},{1,0,1}}

sequence vc, stars

stars =3D {}
if not graphics_mode(18) then
  vc =3D video_config()
else
  abort(1)
end if
while get_key() < 1 do
   =20
  while length(stars) < MAXSTARS do
    stars =3D append(stars,{rand(vc[VC_XPIXELS])-1,
      rand(vc[VC_YPIXELS])-1,rand(vc[VC_NCOLORS])-1})
  end while
 =20
  for a =3D 1 to TWINKLES do
    for b =3D 1 to MAXSTARS do
      display_image(stars[b][1..2],STAR_IMAGE*stars[b][3])
      stars[b][3] =3D rand(vc[VC_NCOLORS])-1
    end for
  end for
   =20
  display_image(stars[1][1..2],STAR_IMAGE*0)
  stars =3D stars[2..MAXSTARS]

end while

------------------ end code ----------------------

Michael J. Sabal
mjs at osa.att.ne.jp
http://home.att.ne.jp/gold/mjs/index.html

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu