summaryrefslogtreecommitdiffstats
path: root/Demo/sgi/gl/mixing.py
blob: 57dea9c865fa3c018eadcc943cba005d1b34dce1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#! /usr/local/bin/python

# Use Gouraud shading to mix colors.  Requires Z-buffer.
# It changes the color assignments so fast that you see white.
# Left button pauses, middle rotates the square.  ESC to quit.
# Experiment with a larger window (too slow) or smaller window (really white).

from GL import *
from gl import *
import DEVICE
from math import *

#
#  tekenvlak : draw a square. with bgnpolygon
#
def tekenvlak (vc) :
	bgnpolygon()
	#vcarray (vc)
	for i in vc :
		c3f (i[1])
		v3f (i[0])
	endpolygon()

#
# tekendoos : draw a box
#
def tekendoos (col) :
	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)]
	vc = [(v[0],col[0]),(v[1],col[1]),(v[2],col[2]),(v[3],col[1])]
	tekenvlak (vc)

#
# initialize gl
#
def initgl () :
	#
	# open window
	#
	foreground ()
	keepaspect (1, 1)
	prefposition (100, 500, 100, 500)
	w = winopen ('PYTHON RGB')
	keepaspect (1, 1)
	winconstraints()
	#
	# configure pipeline (2buf, GOURAUD and RGBmode)
	#
	doublebuffer ()
	zbuffer (1)
	shademodel (GOURAUD)
	RGBmode ()
	gconfig ()
	#
	# set viewing
	#
	perspective (900, 1, 1.0, 10.0)
	polarview (10.0, 0, 0, 0)
	#
	# ask for the REDRAW and ESCKEY events
	#
	qdevice(DEVICE.MOUSE2)
	qdevice(DEVICE.MOUSE3)
	qdevice(DEVICE.REDRAW)
	qdevice(DEVICE.ESCKEY)


#
# the color black
#
black = 0
#
# GoForIT : use 2buf to redraw the object 2n times. index i is used as 
# the (smoothly changing) rotation angle
#
def GoForIt(i) :
	col = [(255.0,0.0,0.0), (0.0,255.0,0.0), (0.0,0.0,255.0)]
	twist = 0
	freeze = 1
	while 1 :
		if freeze <> 0 :
			col[0],col[1],col[2] = col[1],col[2],col[0]
		#
		# clear z-buffer and clear background to light-blue
		#
		zclear()
		cpack (black)
		clear()
		#
		tekendoos (col)
		#
		swapbuffers()
		#
		if qtest() <> 0 :
			dev, val = qread()
			if dev == DEVICE.ESCKEY :
				break
			elif dev == DEVICE.REDRAW :
				reshapeviewport ()
			elif dev == DEVICE.MOUSE2 and val <> 0 :
				twist = twist + 30
				perspective (900, 1, 1.0, 10.0)
				polarview (10.0, 0, 0, twist)
			elif dev == DEVICE.MOUSE3 and val <> 0 :
				freeze = 1 - freeze


# the main program
#
def main () :
	initgl ()
	GoForIt (0)

#
# exec main
#
main  ()