Statistics
| Revision:

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

History | View | Annotate | Download (1.6 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:38 $')[1:3], ' ')
11
__author__ = 'Tarn Weisner Burton <twburton@users.sourceforge.net>'
12

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

    
28
n=50
29

    
30
def shuffle(a,b):
31
        return ravel(transpose(reshape(concatenate([a,b]), (2,len(a)))))
32

    
33
def redraw(o):
34
        glClearColor(1, 1, 1, 0)
35
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
36
        glOrtho(-1, 1, -1, 1, -1, 1)
37
        glDisable(GL_LIGHTING)
38
        glDrawArrays(GL_LINE_LOOP, 0, n)
39
        glEnable(GL_LIGHTING)
40

    
41
def main():
42
        f = Frame()
43
        f.pack(side = 'top', expand = 1)
44
        quit = Button(f, text = 'Quit', command = sys.exit)
45
        quit.pack(side = 'top')
46
        o = Opengl(width = 400, height = 400, double = 1)
47
        a = arange(0,n)
48
        vertex = shuffle(cos(2*pi*a/n), sin(2*pi*a/n))
49
        vertex.shape = (n, 2)
50
#        vertex1 = shuffle(0.5*cos(2*pi*a/n), 0.5*sin(2*pi*a/n))
51
#        color=ones((n, 3), 'i')
52
#        color[0]=[1,0,0]
53
#        color[1]=[1,1,0]
54
#        color[1]=[1,0,0]
55
        color = random(n*3)
56
        color.shape = (n, 3)
57

    
58
        glVertexPointerd(vertex)
59
        glColorPointerd(color)
60
        glEnableClientState(GL_VERTEX_ARRAY)
61
        glEnableClientState(GL_COLOR_ARRAY)
62

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

    
67
main()