home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / sb.ex < prev    next >
Text File  |  1994-03-02  |  2KB  |  84 lines

  1.         ------------------------------------
  2.         -- Atomic Reaction Screen Blanker --
  3.         ------------------------------------
  4. without type_check
  5.  
  6. include graphics.e
  7. include select.e
  8.  
  9. constant GRAPHICS_MODE = 18 -- VGA
  10.  
  11. constant POPULATION = 50        -- number of circles
  12. constant MAX_SIZE = 15, MIN_SIZE = 5    -- size of circles
  13.  
  14. constant TRUE = 1
  15. constant X = 1, Y = 2
  16. constant FILL = 1
  17. constant BLACK = 0
  18.  
  19. sequence size, circles, dirs, colors
  20. sequence vc
  21.  
  22. procedure init()
  23. -- initialize global variables
  24.     if not select_mode(GRAPHICS_MODE) then
  25.     puts(1, "needs VGA graphics\n")
  26.         abort(1)
  27.     end if
  28.     vc = video_config()
  29.     circles = {}
  30.     dirs = {}
  31.     colors = {}
  32.     size = {}
  33. end procedure
  34.  
  35. procedure bounce()
  36. -- main routine
  37.     sequence top_left, prev_circle
  38.     integer x, y, s
  39.     atom t
  40.  
  41.     init()
  42.     t = time()
  43.     while t+2 > time() do
  44.     -- wait for screen to settle
  45.     end while
  46.     while TRUE do
  47.         if get_key() != -1 then
  48.         exit
  49.         end if
  50.         if length(circles) < POPULATION then
  51.             -- add a new circle
  52.             x = 0  y = 0 -- start each circle at top left corner of screen
  53.             s = MIN_SIZE + rand(MAX_SIZE+1-MIN_SIZE) - 1
  54.             size = append(size, s)
  55.             circles = append(circles, {{x, y}, {x, y}+s})
  56.             dirs = append(dirs, floor(s/2)+rand({10*s, 10*s})/10)
  57.         colors = append(colors, 8+rand(vc[VC_NCOLORS]/2-1))
  58.         end if
  59.  
  60.         -- move all the circles
  61.         for i = 1 to length(circles) do
  62.              top_left = circles[i][1]
  63.              prev_circle = circles[i]
  64.              if top_left[X] < 0 or top_left[X]+size[i] >= vc[VC_XPIXELS] then 
  65.             dirs[i][X] = -dirs[i][X] 
  66.             end if
  67.             if top_left[Y] < 0 or top_left[Y]+size[i] >= vc[VC_YPIXELS] then 
  68.             dirs[i][Y] = -dirs[i][Y] 
  69.             end if
  70.             top_left = top_left + dirs[i]
  71.             circles[i] = {top_left, top_left+size[i]}
  72.         -- blank out old position
  73.         ellipse(BLACK, FILL, prev_circle[1], prev_circle[2])
  74.         -- draw at new position
  75.         ellipse(colors[i], FILL, circles[i][1], circles[i][2])
  76.         end for
  77.     end while
  78.     if graphics_mode(-1) then
  79.     end if
  80. end procedure
  81.  
  82. bounce()
  83.  
  84.