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

  1.         -----------------------------
  2.         -- Polygon Pattern Program --
  3.         -----------------------------
  4.  
  5. -- press space bar to see a new pattern
  6. -- press any other key to quit
  7.  
  8. constant GRAPHICS_MODE = 261 -- SVGA graphics mode 
  9.                  -- see euphoria\include\graphics.e
  10. without type_check
  11.  
  12. include graphics.e
  13. include select.e
  14.  
  15. constant TRUE = 1
  16.  
  17. constant X = 1,
  18.      Y = 2
  19.  
  20. sequence config
  21. integer nlines, npoints, spacing, solid
  22.  
  23. function screen_blank()
  24.     integer color, color_step, ncolors, key
  25.     sequence points, deltas, history
  26.  
  27.     if not select_mode(GRAPHICS_MODE) then
  28.     puts(1, "couldn't find a good graphics mode\n")
  29.     return 1
  30.     end if
  31.     config = video_config()
  32.     ncolors = config[VC_NCOLORS]
  33.     color = 1
  34.     color_step = 1
  35.     points = rand(repeat(config[VC_XPIXELS..VC_YPIXELS], npoints)) - 1
  36.     deltas = rand(repeat({2*spacing-1, 2*spacing-1}, npoints)) - spacing
  37.     history = {}
  38.     while TRUE do
  39.     if length(history) >= nlines then
  40.         -- blank out oldest line
  41.         polygon(0, solid, history[1])
  42.         history = history[2..nlines]
  43.     end if
  44.     polygon(color, solid, points)
  45.     history = append(history, points)
  46.        points = points + deltas
  47.     -- make vertices change direction at edge of screen
  48.     for j = 1 to npoints do
  49.         if points[j][X] <= 0 or points[j][X] >= config[VC_XPIXELS] then
  50.         deltas[j][X] = -deltas[j][X]
  51.         end if
  52.         if points[j][Y] <= 0 or points[j][Y] >= config[VC_YPIXELS] then
  53.         deltas[j][Y] = -deltas[j][Y]
  54.         end if
  55.     end for
  56.     -- step through the colors
  57.     color = color + color_step
  58.     if color >= ncolors then
  59.         color_step = rand(ncolors)
  60.         color = color_step
  61.     end if
  62.     -- change background color once in a while
  63.     if rand(80) = 1 then
  64.         bk_color(rand(ncolors)-1)
  65.     end if
  66.     -- see if user wants to quit
  67.     key = get_key()
  68.     if key = ' ' then
  69.         return 0
  70.     elsif key != -1 then
  71.         return 1
  72.     end if
  73.     end while
  74. end function
  75.  
  76. while TRUE do
  77.     -- Play with these parameters for neat effects!
  78.     nlines = rand(150)   -- number of lines on screen at one time
  79.     npoints = 2+rand(16) -- number of points in polygons
  80.     spacing = rand(24)   -- spacing between lines
  81.     solid = rand(2)-1    -- solid polygons? 1 or 0
  82.     if screen_blank() then
  83.     exit
  84.     end if
  85. end while
  86.  
  87. if graphics_mode(-1) then
  88. end if
  89.  
  90.