nurbsCircle.py :  » Game-2D-3D » PyOpenGL » PyOpenGL-Demo-3.0.1b1 » PyOpenGL-Demo » proesch » nurbsCurve » 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 » Game 2D 3D » PyOpenGL 
PyOpenGL » PyOpenGL Demo 3.0.1b1 » PyOpenGL Demo » proesch » nurbsCurve » nurbsCircle.py
#!/usr/bin/python2.4
# Plot a circle using NURBS
# 
# Copyright (C) 2007  "Peter Roesch" <Peter.Roesch@fh-augsburg.de>
#
# This code is licensed under the PyOpenGL License.
# Details are given in the file license.txt included in this distribution.

import sys
import math
from time import sleep

try:
  from OpenGL.GLUT import *
  from OpenGL.GL import *
  from OpenGL.GLU import *
except:
  print ''' Fehler: PyOpenGL nicht intalliert !!'''
  sys.exit(  )

animationAngle = 0.0
frameRate = 25
animationTime = 0

def animationStep( ):
  """Update animated parameters"""
  global animationAngle
  global frameRate
  animationAngle += 0.3
  while animationAngle > 360:
    animationAngle -= 360
  sleep( 1 / float( frameRate ) )
  glutPostRedisplay( )

degree=3
s2=math.sqrt(2)/2.0

# Initialise circle control points.
circlePoints = [\
  [0.0, 1.0, 0.0, 1.0],\
  [s2, s2, 0.0, s2],\
  [1.0, 0.0, 0.0, 1.0],\
  [s2, -s2, 0.0, s2],\
  [0.0, -1.0, 0.0, 1.0],\
  [-s2, -s2, 0.0, s2],\
  [-1.0, 0.0, 0.0, 1.0],\
  [-s2, s2, 0.0, s2],\
  ]

# make sure circle is closed properly
circlePoints = circlePoints + [circlePoints[0], circlePoints[1]]

# initialise circle knots
circleKnots =  [ 0.0 ] + \
  [ float(i/2) for i in range( len( circlePoints ) + degree -1 )]

def display(  ):
  glClear( GL_COLOR_BUFFER_BIT )
  glMatrixMode( GL_PROJECTION )
  glLoadIdentity( )
  xSize, ySize = glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT )
  gluPerspective(60, float(xSize) / float(ySize), 0.1, 50)
  glMatrixMode( GL_MODELVIEW )
  glLoadIdentity( )
  glTranslatef( 0, 0, -2 )
  glRotatef( animationAngle, 0, 0, 1 )
  global circlePoints, circleKnots
  glColor3f(0, 1, 0)
  glBegin(GL_LINE_STRIP)
  for coord in circlePoints:
    glVertex3f(coord[0], coord[1], coord[2]);
  glEnd()
  global nurb
  glColor3f(1, 1, 1)
  gluBeginCurve( nurb )
  gluNurbsCurve  (  nurb, circleKnots, circlePoints, GL_MAP1_VERTEX_4 )
  gluEndCurve( nurb )
  glutSwapBuffers( )

nurb=None
samplingTolerance=1.0
def init(  ):
  """Glut init function."""
  glClearColor ( 0, 0, 0, 0 )
  global nurb
  nurb = gluNewNurbsRenderer()
  global samplingTolerance
  glLineWidth(2.0)
  gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, samplingTolerance)

glutInit( sys.argv )
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB )
glutInitWindowSize( 250, 250 )
glutInitWindowPosition( 100, 100 )
glutCreateWindow( sys.argv[0] )
init(  )
glutDisplayFunc( display )
glutIdleFunc( animationStep )
glutMainLoop(  )
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.