Clifford Attractor and Lorenz Attracor Script

Share your scripts with other members
User avatar
Ron
Posts: 43
Joined: Wed May 28, 2008 1:57 pm

Clifford Attractor and Lorenz Attracor Script

Postby Ron » Sun Jun 22, 2008 5:59 pm

Here is a fun script that I wrote to draw a Clifford and Lorenz attractor using particles. I'm not sure what use they are, I just wrote them to learn scripting.

Have fun
Ron


Clifford Attractor:

Code: Select all

# Name: Clifford Attractors
# Description: From inputs a, b, c, d this script creates a Clifford attractor
# Author: Ron Soule
# Date: 06/22/2008
# Version: 1.0
#---------------------------------------
import math

#--------------------------------------------------
# Function: onSimulationBegin
#--------------------------------------------------

def onSimulationBegin():
   pass



#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------

def onSimulationStep():
   n = 10000
   x0 = 0.1
   y0 = 0.0
   z0 = 0.0

   #Other coefficients to try
   #a = 1.1, b = -1.0, c = 1.0, d = 1.5
   #a = 1.7, b = 1.7, c = 0.06, d = 1.2    

   a = -1.4
   b = 1.6
   c = 1.0
   d = 0.7
   
   vel = Vector.new(0.0,0.0,0.0)

   emsource = scene.getEmitter("Circle01")
   emsource.setParameter("Type","Dumb" )
   emsource.setParameter("Speed",0.0)
   
   for i in range(0,n):
      x1 = math.sin(a * y0) + c * math.cos(a * x0)
      y1 = math.sin(b * z0) + d * math.cos(b * y0)
      z1 = math.sin(c * x0) + a * math.cos(c * z0)
      x0 = x1
      y0 = y1
      z0 = z1
      pos = Vector.new(x0,y0,z0)
      emsource.addParticle(pos,vel)




#--------------------------------------------------
# Function: onSimulationFrame
#--------------------------------------------------

def onSimulationFrame():
   pass




#--------------------------------------------------
# Function: onSimulationEnd
#--------------------------------------------------

def onSimulationEnd():
   pass




#--------------------------------------------------
# Function: onChangeToFrame
#--------------------------------------------------

def onChangeToFrame():
   pass

Lorenz Attractor:

Code: Select all

# Name: Lorenz Attractors
# Description: Creates a Lorenz attractor
# Author: Ron Soule
# Date: 06/22/2008
# Version: 1.0
#---------------------------------------

#--------------------------------------------------
# Function: onSimulationBegin
#--------------------------------------------------

def onSimulationBegin():
   pass




#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------

def onSimulationStep():
   n = 1000
   x0 = 0.1
   y0 = 0.0
   z0 = 0.0
   
   h = 0.01
   a = 10.0
   b = 28.0
   c = 8.0 / 3.0
   
   vel = Vector.new(0.0,0.0,0.0)

   emsource = scene.getEmitter("Circle01")
   emsource.setParameter("Type","Dumb" )
   emsource.setParameter("Speed",0.0)
   
   for i in range(0,n):
      x1 = x0 + h * a * (y0 - x0);
      y1 = y0 + h * (x0 * (b - z0) - y0);
      z1 = z0 + h * (x0 * y0 - c * z0);
      x0 = x1;
      y0 = y1;
      z0 = z1;
      pos = Vector.new(x0,y0,z0)
      emsource.addParticle(pos,vel)



#--------------------------------------------------
# Function: onSimulationFrame
#--------------------------------------------------

def onSimulationFrame():
   pass




#--------------------------------------------------
# Function: onSimulationEnd
#--------------------------------------------------

def onSimulationEnd():
   pass




#--------------------------------------------------
# Function: onChangeToFrame
#--------------------------------------------------

def onChangeToFrame():
   pass


shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Clifford Attractor and Lorenz Attracor Script

Postby shaun_michael » Sun Jun 22, 2008 7:20 pm

Excuse my ignorance Ron, but whats a Clifford attractor and a Lorenz attractor and how do they differ?

Shaun

User avatar
Ron
Posts: 43
Joined: Wed May 28, 2008 1:57 pm

Clifford Attractor and Lorenz Attracor Script

Postby Ron » Sun Jun 22, 2008 8:27 pm

Sorry I guess I should have given some reference images and definitions.

So a Lorenz attractor was derived be Ed Lorenz in 1963. He was working modeling of weather patterns. It is considered a strange attractor, its not a point or curve or a surface. It has a fractional dimension so it’s a fractal. Within a certain range of parameters the system is has no stable fixed points and no stable limit cycles.

Here is a link:
Lorenz Attractor


I'm not so sure if a Clifford attractor is purely a strange attractor but here is some information on them.

Clifford Attractor


The difference is that the Lorenz attractor is a chaotic system and continuously dynamic and I believe that the Clifford attractor is not.

As an engineer I am fascinated by strange behavior of systems, so that’s why I choose to use these examples to learn RF scripting. Obviously it could be done in any program that has a scriptable particle system.

Thanks
Ron

shaun_michael
Posts: 4766
Joined: Sun Sep 10, 2006 8:04 am

Clifford Attractor and Lorenz Attracor Script

Postby shaun_michael » Mon Jun 23, 2008 5:39 am

Thanks Ron, very interesting.

Shaun

lukeiamyourfather
Posts: 2880
Joined: Mon Oct 15, 2007 4:09 pm
Contact:

Clifford Attractor and Lorenz Attracor Script

Postby lukeiamyourfather » Mon Jun 23, 2008 2:11 pm

Very interesting indeed. Thanks for sharing the scripts and the links!

ranxerox
Posts: 334
Joined: Tue Jan 09, 2007 5:15 pm

Clifford Attractor and Lorenz Attracor Script

Postby ranxerox » Mon Jun 23, 2008 4:32 pm

very cool idea. My first thought is that it would be cooler to put the initialization in the onSimulationBegin section so that you aren't doing this math every substep. This would also let you effect your particles with forces. You also don't need to set the parameters for the emitter. It might be interesting to use these somehow as a weird scripted force (maybe as an alternative to noise).

-ranxx

vectorhead
Posts: 385
Joined: Tue Oct 17, 2006 5:54 am

Clifford Attractor and Lorenz Attracor Script

Postby vectorhead » Mon Jun 23, 2008 4:37 pm

COOL!

User avatar
Ron
Posts: 43
Joined: Wed May 28, 2008 1:57 pm

Clifford Attractor and Lorenz Attracor Script

Postby Ron » Mon Jun 23, 2008 7:22 pm

ranxerox wrote: very cool idea. My first thought is that it would be cooler to put the initialization in the onSimulationBegin section so that you aren't doing this math every substep. This would also let you effect your particles with forces. You also don't need to set the parameters for the emitter. It might be interesting to use these somehow as a weird scripted force (maybe as an alternative to noise).

-ranxx

That would be cool. I'll have to try that when I get a free moment. Thanks for your input.

Ron


Return to “User Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest