home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / sgi / gl / mixing.py < prev    next >
Text File  |  1996-11-27  |  2KB  |  117 lines

  1. #! /usr/bin/env python
  2.  
  3. # Use Gouraud shading to mix colors.  Requires Z-buffer.
  4. # It changes the color assignments so fast that you see white.
  5. # Left button pauses, middle rotates the square.  ESC to quit.
  6. # Experiment with a larger window (too slow) or smaller window (really white).
  7.  
  8. from GL import *
  9. from gl import *
  10. import DEVICE
  11. from math import *
  12.  
  13. #
  14. #  tekenvlak : draw a square. with bgnpolygon
  15. #
  16. def tekenvlak (vc) :
  17.     bgnpolygon()
  18.     #vcarray (vc)
  19.     for i in vc :
  20.         c3f (i[1])
  21.         v3f (i[0])
  22.     endpolygon()
  23.  
  24. #
  25. # tekendoos : draw a box
  26. #
  27. def tekendoos (col) :
  28.     v = [(-5.0,0.0,0.0),(0.0,5.0,0.0),(5.0,0.0,0.0),(0.0,-5.0,0.0)]
  29.     vc = [(v[0],col[0]),(v[1],col[1]),(v[2],col[2]),(v[3],col[1])]
  30.     tekenvlak (vc)
  31.  
  32. #
  33. # initialize gl
  34. #
  35. def initgl () :
  36.     #
  37.     # open window
  38.     #
  39.     foreground ()
  40.     keepaspect (1, 1)
  41.     prefposition (100, 500, 100, 500)
  42.     w = winopen ('PYTHON RGB')
  43.     keepaspect (1, 1)
  44.     winconstraints()
  45.     #
  46.     # configure pipeline (2buf, GOURAUD and RGBmode)
  47.     #
  48.     doublebuffer ()
  49.     zbuffer (1)
  50.     shademodel (GOURAUD)
  51.     RGBmode ()
  52.     gconfig ()
  53.     #
  54.     # set viewing
  55.     #
  56.     perspective (900, 1, 1.0, 10.0)
  57.     polarview (10.0, 0, 0, 0)
  58.     #
  59.     # ask for the REDRAW and ESCKEY events
  60.     #
  61.     qdevice(DEVICE.MOUSE2)
  62.     qdevice(DEVICE.MOUSE3)
  63.     qdevice(DEVICE.REDRAW)
  64.     qdevice(DEVICE.ESCKEY)
  65.  
  66.  
  67. #
  68. # the color black
  69. #
  70. black = 0
  71. #
  72. # GoForIT : use 2buf to redraw the object 2n times. index i is used as 
  73. # the (smoothly changing) rotation angle
  74. #
  75. def GoForIt(i) :
  76.     col = [(255.0,0.0,0.0), (0.0,255.0,0.0), (0.0,0.0,255.0)]
  77.     twist = 0
  78.     freeze = 1
  79.     while 1 :
  80.         if freeze <> 0 :
  81.             col[0],col[1],col[2] = col[1],col[2],col[0]
  82.         #
  83.         # clear z-buffer and clear background to light-blue
  84.         #
  85.         zclear()
  86.         cpack (black)
  87.         clear()
  88.         #
  89.         tekendoos (col)
  90.         #
  91.         swapbuffers()
  92.         #
  93.         if qtest() <> 0 :
  94.             dev, val = qread()
  95.             if dev == DEVICE.ESCKEY :
  96.                 break
  97.             elif dev == DEVICE.REDRAW :
  98.                 reshapeviewport ()
  99.             elif dev == DEVICE.MOUSE2 and val <> 0 :
  100.                 twist = twist + 30
  101.                 perspective (900, 1, 1.0, 10.0)
  102.                 polarview (10.0, 0, 0, twist)
  103.             elif dev == DEVICE.MOUSE3 and val <> 0 :
  104.                 freeze = 1 - freeze
  105.  
  106.  
  107. # the main program
  108. #
  109. def main () :
  110.     initgl ()
  111.     GoForIt (0)
  112.  
  113. #
  114. # exec main
  115. #
  116. main  ()
  117.