-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlorenz
executable file
·61 lines (54 loc) · 1.39 KB
/
lorenz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
from __future__ import division
from geode import *
from geode.value import parser
from gui import *
from OpenGL import GL
import scipy.integrate
import sys
# Properties
props = PropManager()
sigma = props.add('sigma',10.)
rho = props.add('rho',28.)
beta = props.add('beta',8/3)
length = props.add('length',100)
resolution = props.add('resolution',10000)
skip = props.add('skip',.1)
parser.parse(props,'Lorenz attractor visualization')
@cache
def curve():
s,p,b = sigma(),rho(),beta()
def f((x,y,z),t):
return s*(y-x),x*(p-z)-y,x*y-b*z
random.seed(17341)
X0 = .1*random.randn(3)
t = linspace(0,length(),resolution())
X = scipy.integrate.odeint(f,X0,t)
X = X[int(skip()*len(X)):]
return X
class LorenzScene(Scene):
def bounding_box(self):
return bounding_box(curve())
def render(self,*args):
X = curve()
color = wheel_color(linspace(0,1,len(X)))
GL.glBegin(GL.GL_LINE_STRIP)
gl_colored_vertices(color,X)
GL.glEnd()
@cache
def mesh():
n = resolution()
n = n-int(skip()*n)
segs = empty((n-1,2),dtype=int32)
segs[:,0] = arange(n-1)
segs[:,1] = arange(n-1)+1
return SegmentSoup(segs)
def main():
app = QEApp(sys.argv,True)
main = MainWindow(props)
main.view.add_scene('lorenz',LorenzScene())
#main.view.add_scene('lorenz',MeshScene(props,mesh,curve,(1,0,0),(1,0,0)))
main.init()
app.run()
if __name__=='__main__':
main()