Révision 2
| PyOpenGL-Demo/da/dots.py (revision 2) | ||
|---|---|---|
| 1 |
#!/usr/bin/python |
|
| 1 |
#!/usr/bin/python3
|
|
| 2 | 2 |
|
| 3 | 3 |
# This is statement is required by the build system to query build info |
| 4 | 4 |
if __name__ == '__build__': |
| 5 | 5 |
raise Exception |
| 6 | 6 |
|
| 7 |
import string |
|
| 8 |
__version__ = string.split('$Revision: 1.1.1.1 $')[1]
|
|
| 9 |
__date__ = string.join(string.split('$Date: 2007/02/15 19:25:28 $')[1:3], ' ')
|
|
| 7 |
__version__ = str.split('$Revision: 1.1.1.1 $')[1]
|
|
| 8 |
__date__ = str.join('$Date: 2007/02/15 19:25:28 $', ' ')
|
|
| 10 | 9 |
__author__ = 'Tarn Weisner Burton <twburton@users.sourceforge.net>' |
| 11 | 10 |
|
| 12 | 11 |
try: |
| 13 | 12 |
from numpy import * |
| 14 | 13 |
from numpy.random import * |
| 15 |
except ImportError, err:
|
|
| 14 |
except ImportError: |
|
| 16 | 15 |
try: |
| 17 | 16 |
from Numeric import * |
| 18 | 17 |
from RandomArray import * |
| 19 |
except ImportError, err:
|
|
| 20 |
print "This demo requires the numpy or Numeric extension, sorry"
|
|
| 18 |
except ImportError: |
|
| 19 |
print("This demo requires the numpy or Numeric extension, sorry")
|
|
| 21 | 20 |
import sys |
| 22 | 21 |
sys.exit() |
| 23 | 22 |
import string, sys |
| 24 | 23 |
from OpenGL.GL import * |
| 25 |
from OpenGL.GLUT import *
|
|
| 24 |
from OpenGL.GLUT import * |
|
| 26 | 25 |
|
| 27 | 26 |
MY_LIST=1 |
| 28 | 27 |
NUMDOTS = 500 |
| ... | ... | |
| 40 | 39 |
|
| 41 | 40 |
def display(*args): |
| 42 | 41 |
global x, y, move_x, move_y, NUMDOTS, NUMDOTS2, MAX_AGE, age |
| 43 |
glClearColor(0.0, 0.0, 0.0, 0.0)
|
|
| 44 |
glClear(GL_COLOR_BUFFER_BIT)
|
|
| 45 |
glColor3f(1.0,1.0,0.0)
|
|
| 46 |
x = x + move_x
|
|
| 47 |
y = y + move_y
|
|
| 48 |
age = age + 1
|
|
| 49 |
which = greater(age, MAX_AGE)
|
|
| 50 |
x = choose(which, (x, random(NUMDOTS)))
|
|
| 51 |
y = choose(which, (y, random(NUMDOTS)))
|
|
| 52 |
age = choose(which, (age, 0))
|
|
| 53 |
x = choose(greater(x,1.0),(x,x-1.0)) # very cool - wraparound
|
|
| 54 |
y = choose(greater(y,1.0),(y,y-1.0))
|
|
| 55 |
x2 = random(NUMDOTS2)
|
|
| 56 |
y2 = random(NUMDOTS2)
|
|
| 57 |
v = concatenate((transpose(array([x,y])), transpose(array([x-.005,y+.005])), transpose(array([x+.005,y-.005])), transpose(array([x2,y2]))))
|
|
| 58 |
glVertexPointerd(v)
|
|
| 59 |
glEnableClientState(GL_VERTEX_ARRAY)
|
|
| 60 |
glDrawArrays(GL_POINTS, 0, len(v))
|
|
| 61 |
glDisableClientState(GL_VERTEX_ARRAY)
|
|
| 62 |
glFlush()
|
|
| 63 |
glutSwapBuffers()
|
|
| 42 |
glClearColor(0.0, 0.0, 0.0, 0.0) |
|
| 43 |
glClear(GL_COLOR_BUFFER_BIT) |
|
| 44 |
glColor3f(1.0,1.0,0.0) |
|
| 45 |
x = x + move_x |
|
| 46 |
y = y + move_y |
|
| 47 |
age = age + 1 |
|
| 48 |
which = greater(age, MAX_AGE) |
|
| 49 |
x = choose(which, (x, random(NUMDOTS))) |
|
| 50 |
y = choose(which, (y, random(NUMDOTS))) |
|
| 51 |
age = choose(which, (age, 0)) |
|
| 52 |
x = choose(greater(x,1.0),(x,x-1.0)) # very cool - wraparound |
|
| 53 |
y = choose(greater(y,1.0),(y,y-1.0)) |
|
| 54 |
x2 = random(NUMDOTS2) |
|
| 55 |
y2 = random(NUMDOTS2) |
|
| 56 |
v = concatenate((transpose(array([x,y])), transpose(array([x-.005,y+.005])), transpose(array([x+.005,y-.005])), transpose(array([x2,y2])))) |
|
| 57 |
glVertexPointerd(v) |
|
| 58 |
glEnableClientState(GL_VERTEX_ARRAY) |
|
| 59 |
glDrawArrays(GL_POINTS, 0, len(v)) |
|
| 60 |
glDisableClientState(GL_VERTEX_ARRAY) |
|
| 61 |
glFlush() |
|
| 62 |
glutSwapBuffers() |
|
| 64 | 63 |
|
| 65 | 64 |
|
| 66 | 65 |
def halt(): |
| ... | ... | |
| 98 | 97 |
glutInit(sys.argv) |
| 99 | 98 |
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) |
| 100 | 99 |
glutInitWindowSize(300, 300) |
| 101 |
glutCreateWindow('Dots')
|
|
| 100 |
glutCreateWindow(b'Dots')
|
|
| 102 | 101 |
setup_viewport() |
| 103 | 102 |
glutReshapeFunc(reshape) |
| 104 | 103 |
glutDisplayFunc(display) |
| ... | ... | |
| 107 | 106 |
glutKeyboardFunc(keyboard) |
| 108 | 107 |
glutMainLoop() |
| 109 | 108 |
|
| 110 |
print "Use the mouse buttons to control some of the dots."
|
|
| 111 |
print "Hit any key to quit."
|
|
| 109 |
print("Use the mouse buttons to control some of the dots.")
|
|
| 110 |
print("Hit any key to quit.")
|
|
| 112 | 111 |
main() |
| 113 | 112 |
|
| 114 | 113 |
|
Formats disponibles : Unified diff