Statistics
| Revision:

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

History | View | Annotate | Download (1.9 kB)

1 1 equemene
#!/usr/bin/python
2 1 equemene
3 1 equemene
# This is statement is required by the build system to query build info
4 1 equemene
if __name__ == '__build__':
5 1 equemene
        raise Exception
6 1 equemene
7 1 equemene
8 1 equemene
import string
9 1 equemene
__version__ = string.split('$Revision: 1.1.1.1 $')[1]
10 1 equemene
__date__ = string.join(string.split('$Date: 2007/02/15 19:25:40 $')[1:3], ' ')
11 1 equemene
__author__ = 'Tarn Weisner Burton <twburton@users.sourceforge.net>'
12 1 equemene
13 1 equemene
import sys
14 1 equemene
try:
15 1 equemene
        from numpy import *
16 1 equemene
except ImportError, err:
17 1 equemene
        try:
18 1 equemene
                from Numeric import *
19 1 equemene
        except ImportError, err:
20 1 equemene
                print "This demo requires the numpy or Numeric extension, sorry"
21 1 equemene
                import sys
22 1 equemene
                sys.exit()
23 1 equemene
from OpenGL.GL import *
24 1 equemene
from OpenGL.Tk import *
25 1 equemene
26 1 equemene
n, dt = 2000, 0.01
27 1 equemene
x, y, z = 0.01, 0.01, 0.01
28 1 equemene
frac = -1.0 * (8.0/3.0)
29 1 equemene
a = array((n,3), 'd')
30 1 equemene
31 1 equemene
def lorentz(o, x, y, z, n=2000, dt=0.01):
32 1 equemene
        """Generate Lorentz attractor.  Put graphic in a graphical object"""
33 1 equemene
        o.grob = glGenLists(1);
34 1 equemene
        glNewList(o.grob, GL_COMPILE);
35 1 equemene
        try:
36 1 equemene
                glDisable(GL_LIGHTING)
37 1 equemene
                glBegin(GL_LINE_STRIP)
38 1 equemene
                try:
39 1 equemene
                        glVertex3d(x, y, z)
40 1 equemene
                        frac = -1.0 * (8.0/3.0)
41 1 equemene
                        for i in range(0, n):
42 1 equemene
                                xp = x + (-10.0 * x * dt + 10.0 * y * dt)
43 1 equemene
                                yp = y + ( 28.0 * x * dt - y * dt - x * dt * z *dt)
44 1 equemene
                                zp = z + ( frac * z * dt + x * dt * y * dt)
45 1 equemene
                                x=xp
46 1 equemene
                                y=yp
47 1 equemene
                                z=zp
48 1 equemene
                                glVertex3d(x, y, z)
49 1 equemene
                finally:
50 1 equemene
                        glEnd()
51 1 equemene
52 1 equemene
                glEnable(GL_LIGHTING)
53 1 equemene
        finally:
54 1 equemene
                glEndList()
55 1 equemene
56 1 equemene
def redraw(o):
57 1 equemene
        """The main scene redraw function."""
58 1 equemene
59 1 equemene
        # Clear the background and depth buffer.
60 1 equemene
        glClearColor(1., 0., 1., 0.)
61 1 equemene
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
62 1 equemene
        glColor3f(1., 1., 1.)
63 1 equemene
        glCallList(o.grob)
64 1 equemene
65 1 equemene
#
66 1 equemene
# Demo starts here really.
67 1 equemene
if __name__ == "__main__":
68 1 equemene
        import Tkinter, sys
69 1 equemene
70 1 equemene
        # Create the opengl widget here.
71 1 equemene
72 1 equemene
        o = Opengl(None, width = 400, height = 400, double = 1)
73 1 equemene
74 1 equemene
        # Register the redraw procedure for the widget.
75 1 equemene
76 1 equemene
        o.redraw = redraw
77 1 equemene
78 1 equemene
        o.pack(side = 'top', expand = 1, fill = 'both')
79 1 equemene
        o.set_centerpoint(0., 0., 2000.)
80 1 equemene
        o.set_eyepoint(13000.)
81 1 equemene
82 1 equemene
        o.far = 600000.
83 1 equemene
84 1 equemene
        lorentz(o, 0.01, 0.01, 0.01)
85 1 equemene
86 1 equemene
        # Enter the tk mainloop.
87 1 equemene
88 1 equemene
        Tkinter.mainloop()