sprott.py

Created by gianfranco-oddenino

Created on March 17, 2024

673 Bytes

The script draws 10^6 points of a strange attractor for a general quadratic map:
x[n+1]=a1+a2*x[n]+a3*x[n]²+a4*x[n]*y[n]+a5*y[n]+a6*y[n]²
y[n+1]=a7+a8*x[n]+a9*x[n]²+a10*x[n]*y[n]+a11*y[n]+a12*y[n]²
In the script the letters A to Y stand for coefficients a[i] of the quadratic from -1.2 to 1.2 in steps of 0.1

http://mathworld.wolfram.com/StrangeAttractor.html


from math import *
from kandinsky import *

def plot(s="CVQKGHQTPHTE"):
  a=[]; l=[1000,-1000,1000,-1000]
  for c in s:
    a.append((ord(c)-77)/10)
  x=y=0
  for i in range(1000000):
    if i>1000:
      xi,yi=round((x-l[0])*319/(l[1]-l[0])),round((l[3]-y)*221/(l[3]-l[2]))
      c=get_pixel(xi,yi)[0]-8
      if c<0:
        c=0
      set_pixel(xi,yi,color(c,c,c))
    x,y=a[0]+a[1]*x+a[2]*x**2+a[3]*x*y+a[4]*y+a[5]*y**2,a[6]+a[7]*x+a[8]*x**2+a[9]*x*y+a[10]*y+a[11]*y**2
    if i<1000:
      if x<l[0]:
        l[0]=x-abs(x)*0.2
      if x>l[1]:
        l[1]=x+abs(x)*0.2
      if y<l[2]:
        l[2]=y-abs(y)*0.2
      if y>l[3]:
        l[3]=y+abs(y)*0.2