# Coding Lorenz Attractor (Sverchock)

I am trying to write a script to make a Lorenz attractor, using sverchok nodes, similar to this video: https://www.youtube.com/watch?v=V7xaPvaz0Ug

Using this script with the Scripted Node Lite does not work and running this script in Blender's text editor produces the following error from the console:

"Traceback (most recent call last): File "D:\0_RMaps\Projects\1700_Attractors\Blend Files\Attractors_v1.blend\Attractor_ChaoticAtmosphere_Lorenz.py", line 45, in NameError: name 'number' is not defined Error: Python script failed, check the message in the system console"

"""
in number s d=1000 n=2
in dt s d=0.01 n=2
in sigma s d=10.0 n=2
in phi s d=28.0 n=2
in beta s d=2.6667 n=2
out vertex v
out edges s
"""

import math

def Lorenz(n, t, sig, ph, bet):

x = 0.1
y = 0.1
z = 0.1
s = sig
p = ph
b = bet

for i in range(n):
dx = s*(y-x) * t
x = x + dx

dy = x*(p-z) * t
y = y + dy

dz = (x*y-b*z) * t
z = z + dz

p = [x,y,z]

vertex.append(p)

for i in range(n - 1):
v1 = i
v2 = i + 1
newEdge = (v1, v2)
edges.append(newEdge)

print(vertex)

Lorenz(number, dt, sigma, phi, beta)


I also made a script for the Three-Scroll Attractor here: https://chaoticatmospheres.com/mathrules-strange-attractors, which works. The script I used for the Three-Scroll is:

"""
in number s d=100 n=2
in dt s d=0.01 n=2
in a s d=40.0 n=2
in b s d=0.833 n=2
in c s d=0.5 n=2
in d s d=0.65 n=2
in e s d=20.0 n=2
out vertex v
out edges s
"""

import math

def Lorenz(n, t, p1, p2, p3, p4, p5):

x = 0.1
y = 0.1
z = 0.1

a = p1
b = p2
c = p3
d = p4
e = p5

for i in range(n):
dx = (a*(y-x)+c*x*z) * t
x = x + dx

dy = (e*y-x*z) * t
y = y + dy

dz = (b*z+x*y-d*x**2) * t
z = z + dz

p = [x,y,z]
vertex.append(p)

for i in range(n - 1):
v1 = i
v2 = i + 1
newEdge = (v1, v2)
edges.append(newEdge)

Lorenz(number, dt, a, b, c, d, e)


Not sure where to go from here. From the console error, it seems something is wrong with the 'number' input, but I'm having trouble seeing how this input works for the second script, but not the second.

Any help would be greatly appreciated. Thanks,

the python interpreter won't help you here, because the "python"-code is interpreted by Sverchok. So python doesn't show you here the "right" error.

You have to update your custom node

in order to see the "right" error which is thrown by Sverchok.

Anyway...here is code that runs:

"""
in number s d=1000 n=2
in dt s d=0.01 n=2
in sigma s d=10.0 n=2
in phi s d=28.0 n=2
in beta s d=2.6667 n=2
out vertex v
out edges s
"""

import math

def Lorenz(n, t, sig, ph, bet):

x = 0.1
y = 0.1
z = 0.1
s = sig
p = ph
b = bet

for i in range(n):

print("i:",i)

dx = s*(y-x) * t
x = x + dx
dy = x*(p-z)*t

y = y + dy

dz = (x*y-b*z) * t

z = z + dz

v = [x,y,z]

vertex.append(v)

for i in range(n - 1):
v1 = i
v2 = i + 1
newEdge = (v1, v2)
edges.append(newEdge)

Lorenz(number, dt, sigma, phi, beta)

vertex = [vertex]
edges = [edges]


result:

Sverchoks "demands" here another bracket, so the four lines to solve your problem was this:

vertex = [vertex]
edges = [edges]


and

v = [x,y,z]
vertex.append(v)


You used p as input variable (phi) and later as vector. So this line here

dy = x*(p-z) * t


got a type conflict error because in the first run of the loop p was just a number, but in the second run you declared it as vector.

• Great! Obviously I overlooked using p twice, thanks for pointing that out. I also didn't realize adding brackets around vertex and edges takes care of wrapping, I had been using the socket handle options. Glad I won't have to do that tedious step anymore. Commented Aug 18, 2021 at 1:48
• Don’t worry. I made exactly the same mistake with the wrapping…🙈 Commented Aug 18, 2021 at 3:28