arraytest.py :  » Development » PyObjC » trunk » pyobjc » PyOpenGL-2.0.2.01 » OpenGL » Demo » GLUT » tom » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » PyObjC 
PyObjC » trunk » pyobjc » PyOpenGL 2.0.2.01 » OpenGL » Demo » GLUT » tom » arraytest.py
"""GLUT replacement for the original arraytest.py demonstration code
"""

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

__version__='$Revision: 1.1.2.1 $'[11:-2]
__date__ = '$Date: 2004/11/15 01:10:45 $'[6:-2]


from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import time, sys
try:
  from Numeric import *
except ImportError:
  print "This demo requires the Numeric extension, sorry."
  sys.exit(1)
from RandomArray import *

n=50

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

def buildArrays( ):
  a = arange(0,n)
  vertex = shuffle(cos(2*pi*a/n), sin(2*pi*a/n))
  vertex.shape = (n, 2)
  color = random(n*3)
  color.shape = (n, 3)
  return vertex,color

vertex,color = buildArrays()

def drawArrays( ):
  glVertexPointerd(vertex)
  glColorPointerd(color)
  glEnableClientState(GL_VERTEX_ARRAY)
  glEnableClientState(GL_COLOR_ARRAY)
  glDisable(GL_LIGHTING)
  try:
    glDrawArrays(GL_LINE_LOOP, 0, n)
  finally:
    glEnable(GL_LIGHTING)

def display( swap=1, clear=1):
  """Callback function for displaying the scene

  This defines a unit-square environment in which to draw,
  i.e. width is one drawing unit, as is height
  """
  glClearColor(0.5, 0.5, 0.5, 0)
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

  # establish the projection matrix (perspective)
  glMatrixMode(GL_PROJECTION)
  glLoadIdentity()
  glOrtho(-1, 1, -1, 1, -1, 1)

  # and then the model view matrix
  glMatrixMode(GL_MODELVIEW)
  glLoadIdentity()
  rotation()

  drawArrays()

  glutSwapBuffers()

def idle( ):
  glutPostRedisplay()

starttime = time.time()

def rotation( period = 10):
  """Do rotation of the scene at given rate"""
  angle = (((time.time()-starttime)%period)/period)* 360
  glRotate( angle, 0,1,0)
  return angle

if __name__ == "__main__":
  print """You should see a polynomial curve rotating about the origin."""
  import sys
  glutInit(sys.argv)
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
  glutCreateWindow('Array Drawing Demo')
  glutDisplayFunc(display)
  glutIdleFunc(display)
  # note need to do this to properly render faceted geometry
  glutMainLoop()
www__._jav_a2s__.c__o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.