## Lorenz attractor with automatic gain

For finished programs
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

### Lorenz attractor with automatic gain

One of the problems with the Lorenz attractor is that the maximum x-y values can vary greatly if the parameters are changed. That is why I have extended the program with an automatic gain correction.
It is now attractive to "play" with the a b c and h parameters.

Code: Select all

``````'Lorenz attractor v2
'by "Dutchman" Ton Nillesen, August 2019
' automatic gain added September 2019
'
'See http://paulbourke.net/fractals/lorenz/
'One commonly used set of constants is a=10, b=28, c=8/3
'Another is a=28, b=46.92, c=4.
'
'==== User settings
gainx gainy =3 3 ' start values
Runtime=5 'seconds
a b c = 10 28 2
h=0.001
'
'--- constants
Test=0
sw sh = SCRSIZE|2
midx midy = sw/2 sh/2
x0 y0 z0 = 0.0001
N=0
DRAW CLEAR 0 0 1
DRAW SIZE 1
DRAW AT midx midy
TIMER SET
DO
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
N+=1 : oldt=t
t=INT(10*TIMER GET)/10 ' steps of 0.1 sec
DRAW COLOR HSV2RGB|3 5*t/runtime*360 0.8 1
DRAW TO midx+gainx*x0 midy+gainy*y0
xmax=MAX(xmax,x0) : xmin=MIN(xmin,x0)
ymax=MAX(ymax,y0) : ymin=MIN(ymin,y0)
zmax=MAX(zmax,z0) : zmin=MIN(zmin,z0)
IF t>1 and oldt<>t
IF (gainx*xmax<midx) THEN gainx+=0.03
IF (gainy*ymax<midy) THEN gainy+=0.03
ENDIF
REDO if t<10*Runtime
IF NOT test THEN END
PRINT "gainx=";gainx;" gainy=";gainy
PRINT "x ranges from ";xmin;"to";xmax
PRINT "y ranges from ";ymin;"to";ymax
PRINT "z ranges from ";zmin;"to";zmax
END``````
. Lorenz attractor.JPG (129.79 KiB) Viewed 2060 times
It is still a long way to go

kibernetik
Site Admin
Posts: 147
Joined: Tue Aug 06, 2019 3:03 pm

### Re: Lorenz attractor with automatic gain

My version of coloring:

Code: Select all

``````'Lorenz attractor v2
'by "Dutchman" Ton Nillesen, August 2019
' automatic gain added September 2019
'
'See http://paulbourke.net/fractals/lorenz/
'One commonly used set of constants is a=10, b=28, c=8/3
'Another is a=28, b=46.92, c=4.
'
'==== User settings
gainx gainy =3 3 ' start values
Runtime=50 'seconds
a b c = 10 28 2
h=0.001
'
'--- constants
Test=0
sw sh = SCRSIZE|2
midx midy = sw/2 sh/2
x0 y0 z0 = 0.0001
N=0
DRAW CLEAR 0 0 0
DRAW SIZE 1
DRAW AT midx midy
TIMER SET
DO
x1 = x0 + h * a * (y0 - x0)
y1 = y0 + h * (x0 * (b - z0) - y0)
z1 = z0 + h * (x0 * y0 - c * z0)
ang = atan2(y1-y0,x1-x0)*180/pi+360*t/runtime
x0 = x1 : y0 = y1 : z0 = z1
N+=1 : oldt=t
t=INT(10*TIMER GET)/10 ' steps of 0.1 sec
DRAW COLOR HSV2RGB|3 ang 1 t/runtime
DRAW TO midx+gainx*x0 midy+gainy*y0
xmax=MAX(xmax,x0) : xmin=MIN(xmin,x0)
ymax=MAX(ymax,y0) : ymin=MIN(ymin,y0)
zmax=MAX(zmax,z0) : zmin=MIN(zmin,z0)
IF t>1 and oldt<>t
IF (gainx*xmax<midx) THEN gainx+=0.03
IF (gainy*ymax<midy) THEN gainy+=0.03
ENDIF
REDO if t<Runtime
IF NOT test THEN END
PRINT "gainx=";gainx;" gainy=";gainy
PRINT "x ranges from ";xmin;"to";xmax
PRINT "y ranges from ";ymin;"to";ymax
PRINT "z ranges from ";zmin;"to";zmax
END`````` Снимок экрана 2019-09-15 в 3.19.00 PM.jpg (100.33 KiB) Viewed 2055 times

Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

### Re: Lorenz attractor with automatic gain

Thanks. You corrected also the time handling It is still a long way to go

Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

### Re: Lorenz attractor with automatic gain

With color mode selection for those who want to see action right away. Code: Select all

``````'Lorenz attractor v2
'by "Dutchman" Ton Nillesen, August 2019
' automatic gain added September 2019
'
'See http://paulbourke.net/fractals/lorenz/
'One commonly used set of constants is a=10, b=28, c=8/3
'Another is a=28, b=46.92, c=4.
'
'==== User settings
mode=0 ' coloring: 0=Dutchman, 1=Mr.K
gainx gainy =3 3 ' start values
Runtime=50 'seconds
a b c = 10 28 1
h=0.001
'
'--- constants
Test=0
sw sh = SCRSIZE|2
midx midy = sw/2 sh/2
x0 y0 z0 = 0.0001
N=0
DRAW CLEAR 0 0 1-mode
DRAW SIZE 1
DRAW AT midx midy
TIMER SET
DO
x1 = x0 + h * a * (y0 - x0)
y1 = y0 + h * (x0 * (b - z0) - y0)
z1 = z0 + h * (x0 * y0 - c * z0)
ang = atan2(y1-y0,x1-x0)*180/pi+360*t/runtime
x0 = x1 : y0 = y1 : z0 = z1
N+=1 : oldt=t
t=INT(10*TIMER GET)/10 ' steps of 0.1 sec
IF mode THEN DRAWCOLOR HSV2RGB|3 (ang 1 t/runtime)\
ELSE DRAWCOLOR HSV2RGB|3(5*t/runtime*360 0.8 1)
DRAW TO midx+gainx*x0 midy+gainy*y0
xmax=MAX(xmax,x0) : xmin=MIN(xmin,x0)
ymax=MAX(ymax,y0) : ymin=MIN(ymin,y0)
zmax=MAX(zmax,z0) : zmin=MIN(zmin,z0)
IF t>1 and oldt<>t
IF (gainx*xmax<midx) THEN gainx+=0.05
IF (gainy*ymax<midy) THEN gainy+=0.05
ENDIF
REDO if t<Runtime
IF NOT test THEN END
PRINT "gainx=";gainx;" gainy=";gainy
PRINT "x ranges from ";xmin;"to";xmax
PRINT "y ranges from ";ymin;"to";ymax
PRINT "z ranges from ";zmin;"to";zmax
END``````
Screenshot of result with mode=0 and c=1
. Image with mode=0 and c=1.JPG (39.74 KiB) Viewed 2043 times
It is still a long way to go

Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

### Re: Lorenz attractor with automatic gain

I corrected previous post with 'If mode THEN …' on a singel line. Added image to show that parameters can change a lot in the resulting image.
It is still a long way to go

kibernetik
Site Admin
Posts: 147
Joined: Tue Aug 06, 2019 3:03 pm

### Re: Lorenz attractor with automatic gain

Very nice settings, much more stable.