Statistics
| Revision:

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

History | View | Annotate | Download (1.9 kB)

1
#!/usr/bin/python
2

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

    
7

    
8
import string
9
__version__ = string.split('$Revision: 1.1.1.1 $')[1]
10
__date__ = string.join(string.split('$Date: 2007/02/15 19:25:40 $')[1:3], ' ')
11
__author__ = 'Tarn Weisner Burton <twburton@users.sourceforge.net>'
12

    
13
import sys
14
try:
15
        from numpy import *
16
except ImportError, err:
17
        try: 
18
                from Numeric import *
19
        except ImportError, err:
20
                print "This demo requires the numpy or Numeric extension, sorry"
21
                import sys
22
                sys.exit()
23
from OpenGL.GL import *
24
from OpenGL.Tk import *
25

    
26
n, dt = 2000, 0.01
27
x, y, z = 0.01, 0.01, 0.01
28
frac = -1.0 * (8.0/3.0)
29
a = array((n,3), 'd')
30

    
31
def lorentz(o, x, y, z, n=2000, dt=0.01):
32
        """Generate Lorentz attractor.  Put graphic in a graphical object"""
33
        o.grob = glGenLists(1);
34
        glNewList(o.grob, GL_COMPILE);
35
        try:
36
                glDisable(GL_LIGHTING)
37
                glBegin(GL_LINE_STRIP)
38
                try:
39
                        glVertex3d(x, y, z)
40
                        frac = -1.0 * (8.0/3.0)
41
                        for i in range(0, n):
42
                                xp = x + (-10.0 * x * dt + 10.0 * y * dt)
43
                                yp = y + ( 28.0 * x * dt - y * dt - x * dt * z *dt)
44
                                zp = z + ( frac * z * dt + x * dt * y * dt)
45
                                x=xp
46
                                y=yp
47
                                z=zp
48
                                glVertex3d(x, y, z)
49
                finally:
50
                        glEnd()
51
                
52
                glEnable(GL_LIGHTING)
53
        finally:
54
                glEndList()
55

    
56
def redraw(o):
57
        """The main scene redraw function."""
58
        
59
        # Clear the background and depth buffer.
60
        glClearColor(1., 0., 1., 0.)
61
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
62
        glColor3f(1., 1., 1.)
63
        glCallList(o.grob)
64

    
65
#
66
# Demo starts here really.
67
if __name__ == "__main__":
68
        import Tkinter, sys
69
        
70
        # Create the opengl widget here.
71
        
72
        o = Opengl(None, width = 400, height = 400, double = 1)
73
        
74
        # Register the redraw procedure for the widget.
75
        
76
        o.redraw = redraw
77
        
78
        o.pack(side = 'top', expand = 1, fill = 'both')
79
        o.set_centerpoint(0., 0., 2000.)
80
        o.set_eyepoint(13000.)
81
        
82
        o.far = 600000.
83
        
84
        lorentz(o, 0.01, 0.01, 0.01)
85
        
86
        # Enter the tk mainloop.
87
        
88
        Tkinter.mainloop()