# Copyright (c) 2009, 2014 Bartosz Szczesny <bszcz@bszcz.org>
# This program is free software under the MIT license.

import time
import visual

class Lorentz(object):
	def __init__(self, beta, rho, sigma, x, y, z, dt):
		# parameters
		self.beta = beta
		self.rho = rho
		self.sigma = sigma
		# coordinates
		self.x = x
		self.y = y
		self.z = z
		# time step
		self.dt = dt

	def get_xyz(self):
		return self.x, self.y, self.z

	def advance(self):
		x_ = self.x
		y_ = self.y
		z_ = self.z
		self.x = x_ + self.dt * self.sigma * (y_ - x_)
		self.y = y_ + self.dt * (x_ * (self.rho - z_) - y_)
		self.z = z_ + self.dt * (x_ * y_ - self.beta * z_)

def main():
	visual.rate(100)

	beta, rho, sigma = 8.0/3.0, 28.0, 10.0
	x, y, z = 5.0, 5.0, 5.0
	dt = 0.002
	system = Lorentz(beta, rho, sigma, x, y, z, dt)

	num_curves = 30
	for i in range(num_curves):
		curve = visual.curve(color = visual.color.white)
		curve_max_points = 1000 # "skipping points" otherwise
		for j in range(curve_max_points):
			system.advance()
			x, y, z = system.get_xyz()
			curve.append(pos = (x, y, z))

if __name__ == "__main__":
	main()
