Added 'description' class attribute to every command class (to help the
[python/dscho.git] / Demo / sgi / gl / backface.py
blob41c69d60a207e922942504a419eaa8b9e61816ae
1 #! /usr/bin/env python
3 # backface
5 # draw a cube that can run with backface() turned on or off.
6 # cube is moved when LEFTMOUSE is pressed and mouse itself is moved.
8 from gl import *
9 from DEVICE import *
10 from GL import *
12 CUBE_SIZE = 200.0
13 CUBE_OBJ = 1
15 def main () :
17 x = 0
18 y = 0
19 moveit = 0
21 initialize()
23 while (1) :
25 while (qtest()) :
26 dev, val = qread()
28 if dev == ESCKEY :
29 backface(0)
30 return
32 elif dev == REDRAW :
33 reshapeviewport()
34 drawcube(x,y)
36 elif dev == LEFTMOUSE :
38 # LEFTMOUSE down
39 moveit = val
41 elif dev == BKEY :
42 backface(1)
43 drawcube(x,y)
45 elif dev == FKEY :
46 backface(0)
47 drawcube(x,y)
49 if moveit :
50 x = getvaluator(MOUSEX)
51 y = getvaluator(MOUSEY)
52 drawcube(x,y)
55 def initialize () :
56 foreground ()
57 keepaspect (1, 1)
58 gid = winopen('backface')
59 winset(gid)
60 winconstraints()
62 doublebuffer()
63 gconfig()
64 shademodel(FLAT)
66 ortho(-1024.0, 1024.0, -1024.0, 1024.0, -1024.0, 1024.0)
68 qdevice(ESCKEY)
69 qdevice(REDRAW)
70 qdevice(LEFTMOUSE)
71 qdevice(BKEY)
72 qdevice(FKEY)
73 qenter(REDRAW,gid)
75 backface(1)
78 # define a cube
79 def cube () :
81 # front face
82 pushmatrix()
83 translate(0.0,0.0,CUBE_SIZE)
84 color(RED)
85 rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
86 popmatrix()
88 # right face
89 pushmatrix()
90 translate(CUBE_SIZE, 0.0, 0.0)
91 rotate(900, 'y')
92 color(GREEN)
93 rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
94 popmatrix()
96 # back face
97 pushmatrix()
98 translate(0.0, 0.0, -CUBE_SIZE)
99 rotate(1800, 'y')
100 color(BLUE)
101 rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
102 popmatrix()
104 # left face
105 pushmatrix()
106 translate(-CUBE_SIZE, 0.0, 0.0)
107 rotate(-900, 'y')
108 color(CYAN)
109 rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
110 popmatrix()
112 # top face
113 pushmatrix()
114 translate(0.0, CUBE_SIZE, 0.0)
115 rotate(-900, 'x')
116 color(MAGENTA)
117 rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
118 popmatrix()
120 # bottom face
121 pushmatrix()
122 translate(0.0, -CUBE_SIZE, 0.0)
123 rotate(900, 'x')
124 color(YELLOW)
125 rectf(-CUBE_SIZE,-CUBE_SIZE,CUBE_SIZE,CUBE_SIZE)
126 popmatrix()
128 def drawcube(x,y) :
130 pushmatrix()
131 rotate(2*x, 'x')
132 rotate(2*y, 'y')
133 color(BLACK)
134 clear()
135 cube()
136 popmatrix()
137 swapbuffers()
140 main ()