Statistics
| Revision:

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

 1 2 3 1 equemene """GLUT replacement for the original arraytest.py demonstration code 1 equemene """ 1 equemene 1 equemene # This is statement is required by the build system to query build info 1 equemene if __name__ == '__build__': 1 equemene raise Exception 1 equemene 1 equemene __version__='$Revision: 1.1.1.1$'[11:-2] 1 equemene __date__ = '$Date: 2007/02/15 19:25:11$'[6:-2] 1 equemene 1 equemene 1 equemene from OpenGL.GL import * 1 equemene from OpenGL.GLU import * 1 equemene from OpenGL.GLUT import * 1 equemene import time, sys 1 equemene try: 1 equemene from numpy import * 1 equemene from numpy.random import * 1 equemene except ImportError, err: 1 equemene try: 1 equemene from Numeric import * 1 equemene from RandomArray import * 1 equemene except ImportError, err: 1 equemene print "This demo requires the numpy or Numeric extension, sorry" 1 equemene import sys 1 equemene sys.exit() 1 equemene 1 equemene n=50 1 equemene 1 equemene def shuffle(a,b): 1 equemene return ravel(transpose(reshape(concatenate([a,b]), (2,len(a))))) 1 equemene 1 equemene def buildArrays( ): 1 equemene a = arange(0,n) 1 equemene vertex = shuffle(cos(2*pi*a/n), sin(2*pi*a/n)) 1 equemene vertex.shape = (n, 2) 1 equemene color = random(n*3) 1 equemene color.shape = (n, 3) 1 equemene return vertex,color 1 equemene 1 equemene vertex,color = buildArrays() 1 equemene 1 equemene def drawArrays( ): 1 equemene glVertexPointerd(vertex) 1 equemene glColorPointerd(color) 1 equemene glEnableClientState(GL_VERTEX_ARRAY) 1 equemene glEnableClientState(GL_COLOR_ARRAY) 1 equemene glDisable(GL_LIGHTING) 1 equemene try: 1 equemene glDrawArrays(GL_LINE_LOOP, 0, n) 1 equemene finally: 1 equemene glEnable(GL_LIGHTING) 1 equemene 1 equemene def display( swap=1, clear=1): 1 equemene """Callback function for displaying the scene 1 equemene 1 equemene This defines a unit-square environment in which to draw, 1 equemene i.e. width is one drawing unit, as is height 1 equemene """ 1 equemene glClearColor(0.5, 0.5, 0.5, 0) 1 equemene glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 1 equemene 1 equemene # establish the projection matrix (perspective) 1 equemene glMatrixMode(GL_PROJECTION) 1 equemene glLoadIdentity() 1 equemene glOrtho(-1, 1, -1, 1, -1, 1) 1 equemene 1 equemene # and then the model view matrix 1 equemene glMatrixMode(GL_MODELVIEW) 1 equemene glLoadIdentity() 1 equemene rotation() 1 equemene 1 equemene drawArrays() 1 equemene 1 equemene glutSwapBuffers() 1 equemene 1 equemene def idle( ): 1 equemene glutPostRedisplay() 1 equemene 1 equemene starttime = time.time() 1 equemene 1 equemene def rotation( period = 10): 1 equemene """Do rotation of the scene at given rate""" 1 equemene angle = (((time.time()-starttime)%period)/period)* 360 1 equemene glRotate( angle, 0,1,0) 1 equemene return angle 1 equemene 1 equemene def key_pressed(*args): 1 equemene # If escape is pressed, kill everything. 1 equemene if args[0] == '\033': 1 equemene sys.exit() 1 equemene 1 equemene 1 equemene if __name__ == "__main__": 1 equemene print """You should see a polynomial curve rotating about the origin.""" 1 equemene import sys 1 equemene glutInit(sys.argv) 1 equemene glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) 1 equemene glutCreateWindow('Array Drawing Demo') 1 equemene glutDisplayFunc(display) 1 equemene glutIdleFunc(display) 1 equemene glutKeyboardFunc(key_pressed) 1 equemene # note need to do this to properly render faceted geometry 1 equemene glutMainLoop()