Statistics
| Revision:

root / PyOpenGL-Demo / GLE / texas.py @ 1

History | View | Annotate | Download (1.9 kB)

1
#!/usr/bin/python
2

    
3
# This is statement is required by the build system to query build info
4
if __name__ == '__build__':
5
        raise Exception
6

    
7

    
8
from OpenGL.GL import *
9
from OpenGL.GLUT import *
10
from OpenGL.GLE import *
11
from math import *
12
import maintest
13

    
14

    
15

    
16
SCALE = 0.8
17
TSCALE = 4
18

    
19
brand_points = map(lambda x: (0, 0, TSCALE*x), (0.1, 0.0, -5.0, -5.1))
20
brand_colors = ((1.0, 0.3, 0.0),)*4
21

    
22
points = ((-1.5, 2.0), (-0.75, 2.0), (-0.75, 1.38), (-0.5, 1.25), (0.88, 1.12), (1.0, 0.62), (1.12, 0.1), (0.5, -0.5), (0.2, -1.12),
23
          (0.3, -1.5), (-0.25, -1.45), (-1.06, -0.3), (-1.38, -0.3), (-1.65, -0.6), (-2.5, 0.5), (-1.5, 0.5), (-1.5, 2.0), (-0.75, 2.0))
24

    
25
tspine = map(lambda x: (TSCALE*x[0], TSCALE*x[1], 0), points)
26

    
27
texas_xsection = map(lambda x: (SCALE*x[0], SCALE*x[1]), points[1:])
28

    
29
tcolors = []
30

    
31
for i in range(len(texas_xsection)):
32
        tcolors.append((((i*33) % 255)/255.0, ((i*47) % 255)/255.0, ((i*89) % 255)/255.0))
33

    
34

    
35
texas_normal = []
36

    
37
for i in range(1, len(texas_xsection)):
38
        ax = texas_xsection[i][0] - texas_xsection[i-1][0]
39
        ay = texas_xsection[i][1] - texas_xsection[i-1][1]
40
        alen = sqrt (ax*ax + ay*ay)
41
        texas_normal.append((-ay / alen, ax / alen))
42

    
43
texas_normal.insert(0, texas_normal[-1])
44

    
45

    
46
def DrawStuff():
47
        global texas_xsection, texas_normal, tspine, tcolors, brand_points, brand_colors
48
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
49
        # set up some matrices so that the object spins with the mouse
50
        gleSetJoinStyle(TUBE_NORM_FACET | TUBE_JN_ANGLE | TUBE_CONTOUR_CLOSED | TUBE_JN_CAP)
51
        glPushMatrix ()
52
        glTranslatef (0.0, 0.0, -80.0)
53
        glRotatef (maintest.lastx, 0.0, 1.0, 0.0)
54
        glRotatef (maintest.lasty, 1.0, 0.0, 0.0)
55

    
56
        gleExtrusion(texas_xsection, texas_normal, None, tspine, tcolors)
57
        gleExtrusion(texas_xsection, texas_normal, None, brand_points, brand_colors)
58

    
59
        glPopMatrix ()
60

    
61
        glutSwapBuffers ()
62

    
63

    
64
if __name__ == "__main__":
65
        import logging
66
        logging.basicConfig()
67
        maintest.main(DrawStuff)