Statistics
| Revision:

root / PyOpenGL-Demo / tom / poly.py @ 1

History | View | Annotate | Download (1.3 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
import string
9
__version__ = string.split('$Revision: 1.1.1.1 $')[1]
10
__date__ = string.join(string.split('$Date: 2007/02/15 19:25:40 $')[1:3], ' ')
11
__author__ = 'Tarn Weisner Burton <twburton@users.sourceforge.net>'
12

    
13
from OpenGL.GL import *
14
from OpenGL.Tk import *
15
try:
16
        from numpy import *
17
except ImportError, err:
18
        try: 
19
                from Numeric import *
20
        except ImportError, err:
21
                print "This demo requires the numpy or Numeric extension, sorry"
22
                import sys
23
                sys.exit()
24

    
25
n=50
26
a=arange(0,n)
27
vertices = transpose(
28
        reshape(
29
                array(
30
                        (
31
                                cos(2*pi*a/float(n)), 
32
                                sin(3*2*pi*a/float(n))
33
                        )
34
                ),
35
                (2, n)
36
        )
37
)
38

    
39
colors=ones((n, 3))
40
colors[0]=[1,0,0]
41
colors[25]=[1,1,0]
42
colors.shape = (n, 3)
43

    
44

    
45
def redraw(o):
46
        global n
47
        glClearColor(0.5, 0.5, 0.5, 0)
48
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
49
        glOrtho(-1,1,-1,1,-1,1)
50
        glDisable(GL_LIGHTING)
51
        glDrawArrays(GL_LINE_LOOP, 0, n)
52
        glEnable(GL_LIGHTING)
53

    
54
def main():
55
        global n, colors, vertices
56
        o = Opengl(width = 400, height = 400, double = 1)
57
        o.redraw = redraw
58
        o.autospin_allowed = 1
59

    
60
        glVertexPointerd(vertices)
61
        glColorPointerd(colors)
62
        glEnableClientState(GL_VERTEX_ARRAY)
63
        glEnableClientState(GL_COLOR_ARRAY)
64

    
65
        o.pack(side = 'top', expand = 1, fill = 'both')
66
        o.mainloop()
67

    
68
main()