noeol.de

Sebastian Schneider
Berlin, Germany
 

[noeol]
stands for no end of line
Update: 07. Feb. 2012

Animate strange attractor via Python in Blender 2.6

Example how to use bpy.app.handlers.render_pre.append() to animate meshes

Download:

anim_attractor.blend (07. Feb. 2012)
Open the demo file and
1) Click 'Run Script'
2) Select the Output
3) Click 'Animation'

Note: the script window in Blender 2.62 will freeze after rendering (I do not know why, maybe a bug), so you have to restart if you want to do a new animation/rendering.

Python script:

This code is a short render handlers example how to rotate a simple cube (frame by frame) without using keys.

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  1. import bpy
  2.  
  3. try:
  4.     bpy.data.objects['Cube']
  5. except:
  6.     bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
  7.     cube = bpy.context.scene.objects.active
  8.     cube.name = 'Cube'
  9.  
  10. i = 0
  11.  
  12. def move_cube(scene):
  13.     global i
  14.     cube = bpy.data.objects['Cube']
  15.     cube.rotation_euler = (0, i/10, i/10)
  16.     print("Callback:"+str(i+1)+",Frame:"+str(scene.frame_current))
  17.     i = i+1
  18.  
  19. for i in range(len(bpy.app.handlers.frame_change_pre)):
  20.     bpy.app.handlers.frame_change_pre.pop()
  21.  
  22. bpy.app.handlers.render_pre.append(move_cube)
  23.  
 
Update: 09. Jul. 2011

Strange Attractor Add-On for Blender 2.6

A simple Python Add-on to create diffrent shapes of beautiful 'Peter de Jong', 'Clifford' or 'Lorenz' attractors

Download:

Download Add-On v0.3 (09. Jul. 2011)
Python script 12KB for Blender 2.6.0

Video tutorial (youtube.com)

Note: Instead of using 'Halos' to visualize every single point of the attractor cloud in Blender, you can also use a 'Wire' material with zero-length edges to get a nicer and sharper result. How to do this: 1. Select the attractor, 2. Switch to 'Edit Mode' (Tab-Key), 3. Extrude the vertices by pressing e-key and don't move the mouse, just hit Enter, 4. Go to the material panel and select 'Wire' (and change colour, emit etc. if you want), 5. Optional: uncheck Anti-Aliasing in the render panel

Peter de Jong in Python:

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  1. itr = 0
  2. while itr < MAX:
  3.     new_x = math.sin(a*y)-math.cos(b*x)
  4.     new_y = math.sin(c*x)-math.cos(d*y)
  5.     x = new_x
  6.     y = new_y
  7.     # save (x,y) coordinates into array
  8.     itr += 1

Example

Clifford in Python:

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  1. itr = 0
  2. while itr < MAX:
  3.     new_x = math.sin(a*y)+c*math.cos(a*x)
  4.     new_y = math.sin(b*x)+d*math.cos(b*y)
  5.     x = new_x
  6.     y = new_y
  7.     # save (x,y) coordinates into array
  8.     itr += 1

Example

Lorenz in Python:

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  1. itr = 0
  2. while itr < MAX:
  3.     new_x = x + h * a * (y - x)
  4.     new_y = y + h * (x * (b - z) - y)
  5.     new_z = z + h * (x * y - c * z)
  6.     x = new_x
  7.     y = new_y
  8.     z = new_z
  9.     # save (x,y,z) coordinates into array
  10.     itr += 1

Example

 
Date: 26. Mar. 2012

Strange Attractor via HTML5 Canvas and JavaScript

A simple JavaScript Browser Application to test or find a nice 'Peter de Jong' Attractor shape.

Points:
a:
b:
c:
d:
Start
or
Anim(slow)
Stop

Webkit browser (Safari, Chrome) or Opera are much more faster than Firefox.
Try some other Attractors:
1) a: 2 , b: -2 , c: 2 , d: -2
2) a: -2 , b: -2 , c: -4 , d: -2

You can find the JavaScript here (requires jQuery).