Hopalong fraktali

Uzmimo neku tačku $(x_0,y_0)$ i izračunjamo prema formuli: $$ x_{i+1}=y_i-\frac{x_i}{|x_i|} \sqrt{|bx_i+c|} $$ $$ y_{i+1}=a-x_i$$

Ako izračunamo npr. 100 ovakivh tačaka dobijemo tzv- hopalong fraktale.

In [33]:
import numpy as np

def hopalong(x0,y0,n,a,b,c):
 def update(x,y):
  x1 = y-x/np.abs(x)*np.sqrt(np.abs(b*x+c))
  y1 = a-x
  return x1,y1
 xx = []
 yy = []
 for _ in range(n):
  x0,y0 = update(x0,y0) 
  xx.append(x0)
  yy.append(y0)
 return xx,yy

Promjenom vrijednosti za $x_0,\,y_0,\, a,\, b$ i $c$ dobit ćemo različite oblike

In [75]:
from pylab import scatter,show, cm, axis
from numpy import array,mean, random
plt.figure(dpi=200)

x =-1; y=10
a=-55;b=-1;c=-42

xx,yy = hopalong(x,y,n,a,b,c)
cr = np.sqrt((xx-mean(xx))**2+(yy-mean(yy))**2)

scatter(xx, yy, marker='.', c=cr/max(cr), 
        edgecolor='w', cmap=cm.inferno, s=50)
axis('equal')
plt.savefig('fraktal1.png')
show()
In [77]:
#from pylab import scatter,show, cm, axis
#from numpy import array,mean, random
import matplotlib.pyplot as plt
plt.figure(dpi=200)

x =-33; y=.33
a=-55;b=-1;c=-42
n = 40000
xx,yy = hopalong(x,y,n,a,b,c)
cr = np.sqrt((xx-mean(xx))**2+(yy-mean(yy))**2)

plt.scatter(xx, yy, marker='.', c=cr/max(cr), 
        edgecolor='w', cmap=cm.inferno, s=50)
axis('equal')
plt.savefig('fraktal2.png')
show()
In [78]:
#from pylab import scatter,show, cm, axis
#from numpy import array,mean, random
import matplotlib.pyplot as plt
plt.figure(dpi=200)

x =1; y=0
a=-5;b=1;c=5
n = 40000
xx,yy = hopalong(x,y,n,a,b,c)
cr = np.sqrt((xx-mean(xx))**2+(yy-mean(yy))**2)

plt.scatter(xx, yy, marker='.', c=cr/max(cr), 
        edgecolor='g', cmap=cm.inferno, s=25)
axis('equal')
plt.savefig('fraktal3.png')
show()