Apparently the code to forestall Tk eating events was too aggressive (Tk user input...
[python/dscho.git] / Demo / sgi / gl / mixing.py
blob9a4c9c1fca7fb663fa710442c3de76996eabe1e5
1 #! /usr/bin/env python
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).
8 from GL import *
9 from gl import *
10 import DEVICE
11 from math import *
14 # tekenvlak : draw a square. with bgnpolygon
16 def tekenvlak (vc) :
17 bgnpolygon()
18 #vcarray (vc)
19 for i in vc :
20 c3f (i[1])
21 v3f (i[0])
22 endpolygon()
25 # tekendoos : draw a box
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)
33 # initialize gl
35 def initgl () :
37 # open window
39 foreground ()
40 keepaspect (1, 1)
41 prefposition (100, 500, 100, 500)
42 w = winopen ('PYTHON RGB')
43 keepaspect (1, 1)
44 winconstraints()
46 # configure pipeline (2buf, GOURAUD and RGBmode)
48 doublebuffer ()
49 zbuffer (1)
50 shademodel (GOURAUD)
51 RGBmode ()
52 gconfig ()
54 # set viewing
56 perspective (900, 1, 1.0, 10.0)
57 polarview (10.0, 0, 0, 0)
59 # ask for the REDRAW and ESCKEY events
61 qdevice(DEVICE.MOUSE2)
62 qdevice(DEVICE.MOUSE3)
63 qdevice(DEVICE.REDRAW)
64 qdevice(DEVICE.ESCKEY)
68 # the color black
70 black = 0
72 # GoForIT : use 2buf to redraw the object 2n times. index i is used as
73 # the (smoothly changing) rotation angle
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]
83 # clear z-buffer and clear background to light-blue
85 zclear()
86 cpack (black)
87 clear()
89 tekendoos (col)
91 swapbuffers()
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
107 # the main program
109 def main () :
110 initgl ()
111 GoForIt (0)
114 # exec main
116 main ()