Lorenz attractor with automatic gain

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

Lorenz attractor with automatic gain

Post by Dutchman » Sun Sep 15, 2019 9:33 am

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
Lorenz attractor.JPG (129.79 KiB) Viewed 940 times
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Lorenz attractor with automatic gain

Post by kibernetik » Sun Sep 15, 2019 10:20 am

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
Снимок экрана 2019-09-15 в 3.19.00 PM.jpg (100.33 KiB) Viewed 935 times

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

Re: Lorenz attractor with automatic gain

Post by Dutchman » Sun Sep 15, 2019 11:05 am

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

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

Re: Lorenz attractor with automatic gain

Post by Dutchman » Sun Sep 15, 2019 11:37 am

With color mode selection for those who want to see action right away. :D

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
Image with mode=0 and c=1.JPG (39.74 KiB) Viewed 923 times
It is still a long way to go

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

Re: Lorenz attractor with automatic gain

Post by Dutchman » Thu Sep 19, 2019 12:39 pm

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

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Lorenz attractor with automatic gain

Post by kibernetik » Thu Sep 19, 2019 4:09 pm

Very nice settings, much more stable.

Post Reply