# This is is the same snowflake fractal with different viewing options.
options = ['Upper Left', 'Upper Right', 'Lower Left', 'Lower Right', 'Normal']
@interact
def snowflake(option = selector(options, nrows = 2, width=8), x= slider(srange(1,100,1),default = 1), y= slider(srange(1,100,1),default = 1), MarkerSize= slider(srange(0,3,0.1),default = 1), iterations= slider(srange(200,40000,100),default = 25000)):
M = []
P = [0.25, 0.25, 0.25, 0.25]
a = GeneralDiscreteDistribution(P)
for i in range (iterations):
if (i>100):
M+=[(x,y)]
b = a.get_random_element()
if (b==0):
temp = (0.333*x)
y = (0.333*y) -0.333
x = temp
if (b==1):
temp = (0.333*x)
y = (0.333*y) + 0.333
x = temp
if (b==2):
temp = (0.167*x) - (0.289*y) - 0.083
y = (0.289*x) + (0.167*y) + 0.144
x = temp
if (b==3):
temp = (0.167*x) + (0.289*y) + 0.083
y = -(0.289*x) + (0.167*y) + 0.144
x = temp
if option == 'Upper Left':
Mplot = scatter_plot(M, markersize=1,xmin=-0.25, xmax=0, ymin=0, ymax=0.55)
if option == 'Upper Right':
Mplot = scatter_plot(M, markersize=1,xmin=0, xmax=0.25, ymin=0, ymax=0.55)
if option == 'Lower Left':
Mplot = scatter_plot(M, markersize=1,xmin=-0.25, xmax=0, ymin=-0.55, ymax=0)
if option == 'Lower Right':
Mplot = scatter_plot(M, markersize=1,xmin=0, xmax=0.25, ymin=-0.55, ymax=0)
if option == 'Normal':
Mplot = scatter_plot(M, markersize=1,xmin=-0.25, xmax=0.25, ymin=-0.55, ymax=0.55)
show (Mplot)
|
|
Click to the left again to hide and once more to show the dynamic interactive window
|