# Strange attractor balls

mmmm

Hi,

many thanks to this forum. I got it out now, how to make a strange attractor visible with faces.

The whole script do running through the attractor and gets coordinates. At these positions balls get painted.
Your choice how many balls, how big the balls became and how detailed the are.

Tace kare at the parameters. If you choose big counts of balls and a high resolutionâ€¦it takes days :d

Here it is - have fun

``````
#!BPY

"""
Name: 'Strange pipe'
Blender: 101
Group: 'Misc'
Tooltip: 'An strange attractor build with a pipe'
"""

#############################################################################
# Andy Huber                                                                #
# [email protected]                                                        #
# Creative common copyrights: free to copy, free to use,                    #
# no selling without asking... 2013;                                        #
#                                                                           #
# parts of the scripts are (C) Februari 2004 Wim Van Hoydonck               #
#                                                                           #
# script use parameters of an strange attractor and make balls in           #
# the shape of the attractor                                                #
#                                                                           #
#############################################################################

from random import random
import Blender
from Blender import *
from Blender.Draw import *
from Blender.BGL import *

from math import pi, sin, cos, fmod

# parameters

# n1: shape of torus ring
# n2: shape of cross section of ring
# 1 gives normal torusshape, 2 gives straight edges, 0 creates doubles
n1 = Create(1.0)
n2 = Create(1.0)

# segments (vertical)
# rings (horizontal)
segments = Create(3)
rings = Create(3)

# r0: base radius of the torus
# r1: radius of cross section of ring
r0 = Create(0.3)
r1 = Create(0.15)

# xFactor = 0 draws a pipe
# xFactor = 1 draws a ball
xFactor = Create(1.0)

#positions
xxA = Create(0.0)
iseMax = Create(6)
size4 = Create(4.0)
# only one drawing
PaintHelp = True

#=============#
# SuperToroid #
#=============#

def SuperToroid(pipeBall):

px = 0.0
py = 0.0
pz = 0.0
#a = [-0.66, -0.153, -0.143, 0.077,-0.747, -0.485, 0.11, 0.482,-1.01, 0.659, 0.224, -0.225,-0.899, -0.959, -1.131, 0.427,-0.902, 0.398, -0.025, -0.304,0.8, -0.332, 0.131, -0.533,0.734, -0.612, -0.887, 0.228,0.461, -0.183]
a=[1.024, 0.111, -0.139, -0.621,0.861, -0.244, -0.152, 0.49,-0.599, -0.794, 0.00200000000000004, 0.239,0.418, -0.833, -0.699, 0.718,-1.008, -0.121, 0.202, -0.709,-0.022, -0.156, 0.374, 0.04,0.055, -1.038, 0.377, -0.802,-0.687, 1.188]

ise=0
while ise &lt; iseMax.val:

newpx = a[0]+a[1]*px+a[2]*px*px+a[3]*px*py+a[4]*px*pz+a[5]*py+a[6]*py*py+a[7]*py*pz+a[8]*pz+a[9]*pz*pz
newpy = a[10]+a[11]*px+a[12]*px*px+a[13]*px*py+a[14]*px*pz+a[15]*py+a[16]*py*py+a[17]*py*pz+a[18]*pz+a[19]*pz*pz
newpz = a[20]+a[21]*px+a[22]*px*px+a[23]*px*py+a[24]*px*pz+a[25]*py+a[26]*py*py+a[27]*py*pz+a[28]*pz+a[29]*pz*pz
px = newpx
py = newpy
pz = newpz

px=px*size4.val
pz=pz*size4.val
py=py*size4.val

UltraSuperToroidD(pipeBall, ise, px, py, pz )

px=px/size4.val
pz=pz/size4.val
py=py/size4.val
ise += 1

def getColor( x, y, z ):

#red = random()*256
#green = random()*256
#blue = random()*256
red =   x%256
green = y%256
blue =  z%256

return red, green, blue

def UltraSuperToroidD(pB, ise, xx, yy, zz):

#except:
# no torus selected, create a new one
#    print "nothing selected, creating a new one"

# parameters
# powers of sines and cosines
n1v = n1.val
n2v = n2.val

segmentsV = segments.val
ringsv = rings.val

r0v = r0.val
r1v = r1.val

dtheta = 2*pi/segmentsV
dphi = 2*pi/ringsv

supertoroid = Blender.NMesh.New('myMeshs')

xf = pB
if xf &gt;= 0.9:
r0v=0.0

# make verts
for i in range(0,segmentsV):
for j in range(0, ringsv):

c1 = cos(i*dtheta*xf)#pipe
s1 = sin(i*dtheta)#pipe

c2 = cos(j*dphi)
s2 = sin(j*dphi)

# make sure to take a fractional power of a negative number
if c1 &lt; 0:
c1m = -((-c1)**n1v)
else:
c1m = c1**n1v
if s1 &lt; 0:
s1m = -((-s1)**n1v)
else:
s1m = s1**n1v
if c2 &lt; 0:
c2m = -((-c2)**n2v)
else:
c2m = c2**n2v
if s2 &lt; 0:
s2m = -((-s2)**n2v)
else:
s2m = s2**n2v

# x, y and z coordinates of the current vertex
x = c1m*(r0v+r1v*c2m)
y = s1m*(r0v+r1v*c2m)
z = (r1v*s2m)
x = x+xx
y=y+yy
z=z+zz

xxA.val = x

v = NMesh.Vert(x,y,z)
supertoroid.verts.append(v)

# make faces
for i in range(0, segmentsV):
for j in range(0, ringsv):
f = NMesh.Face()

f.v.append(supertoroid.verts[i*ringsv + j])
f.v.append(supertoroid.verts[i*ringsv + int(fmod(j+1, ringsv))])
f.v.append(supertoroid.verts[int(fmod((i+1)*ringsv, segmentsV*ringsv)) + int(fmod(j+1, ringsv))])
f.v.append(supertoroid.verts[int(fmod((i+1)*ringsv, segmentsV*ringsv)) + j])
f.v.reverse()

mat = Material.New('newMat')

supertoroid.materials = []
supertoroid.materials += [mat]
supertoroid.materials[0].rgbCol = [256.0*xx, 256.0*yy, 256.0*zz ]

supertoroid.faces.append(f)

name = 'torus'
nameT= 'torusT'
st_ob = NMesh.PutRaw(supertoroid)#,'torus')#,name)

#############################################################
# Graphics                                                  #
#############################################################

def draw():
global n1, n2, segments, rings, r0, r1, xFactor, iseMax, size4, PaintHelp

# Background
BGL.glClearColor(0.5, 0.5, 0.5, 0.0)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
BGL.glColor3f(0.2,0.2,0.2)
BGL.glRectf(2, 2, 370, 280)

# Text
BGL.glColor3f(1, 1, 1)
BGL.glRasterPos2d(10, 160)
Text("Strange attractor :d")
BGL.glRasterPos2d(10, 140)
Text("(C) Febr. 2004 Wim Van Hoydonck, Andy Huber")

# Buttons & sliders
Button("Create", 3, 10, 10, 350, 20, "create torus at cursor position in XY-plane, CKEY with mouse in script window")
Button("Exit", 1, 320, 145, 40, 20, "get out, QKEY with mouse in script window")

r0 = Slider("radius0: ", 2, 10, 85, 240, 20, r0.val, 0.0, 10.0, 1, "base radius of toroid")
r1 = Slider("radius1: ", 2, 10, 106, 240, 20, r1.val, 0.0, 5.0, 1, "thickness of toroid")

n1 = Slider("ring shape: ", 2, 10, 57, 240, 20, n1.val, 0.0, 5.0, 1, "shape of torus ring; 1: normal torus")
n2 = Slider("segm. shape: ", 2, 10, 36, 240, 20, n2.val, 0.0, 5.0, 1, "shape of cross section of ring; 1: normal torus")

rings = Number("rings: ", 2, 260, 57, 100, 20, rings.val, 3, 164, "number of rings (horizontal)")
segments = Number("segments: ", 2, 260, 36, 100, 20, segments.val, 3, 164, "number of segments (vertical)")

Factor = Slider("xFactor: ", 2, 260, 86, 100, 20, xFactor.val, 0.0, 6.0, 0.5, "ball or pipe")
iseMax = Number("Iterations: ", 2, 260, 6, 100, 20, iseMax.val, 1, 10000, "number of balls")
size4 = Slider("Size: ", 2, 260, 126, 100, 20, size4.val, 0.0, 10.0, 4 , "overall size")

def event(evt, val):
if (evt== QKEY and not val):
Exit()
if (evt==CKEY and not val):
SuperToroid(1)
Redraw()

def bevent(evt):
if evt == 1:
Exit()
elif evt == 3:
SuperToroid(1)
Redraw()

# if a button is pressed, redraw the gui
elif evt == 2:
#SuperToroid(1)
Redraw()

Register(draw, event, bevent)

``````

Lg Andy

:spin: