from visual import * from visual.graph import * from random import * scene1 = display(title='MengerSponge', x=0, y=0, width=600, height=600, center=(0.5,0.5,0), background=(0,0,0)) x=0.0 y=0.0 z=0.0 count=0 p=1.0/20.0 #Iterates count times the 1/2 distance, 3 corners chaos game while count<1000000: if count>100: dot = sphere(pos=(x,y,z), radius=0.0001) count=count+1 RandomNumber=random() #Starts first plane (z=0) with hole in the center if RandomNumber<=1*p: x=0.333*x y=0.333*y z=0.333*z elif (RandomNumber<=2*p): x=0.333*x + 0.333 y=0.333*y z=0.333*z elif (RandomNumber<=3*p): x=0.333*x + 0.666 y=0.333*y z=0.333*z elif (RandomNumber<=4*p): x=0.333*x y=0.333*y + 0.333 z=0.333*z elif (RandomNumber<=5*p): x=0.333*x + 0.666 y=0.333*y + 0.333 z=0.333*z elif (RandomNumber<=6*p): x=0.333*x y=0.333*y + 0.666 z=0.333*z elif (RandomNumber<=7*p): x=0.333*x + 0.333 y=0.333*y + 0.666 z=0.333*z elif (RandomNumber<=8*p): x=0.333*x + 0.666 y=0.333*y + 0.666 z=0.333*z #Starts second plane (z=0.333) with "hole" in the middle and on each middle face (4 cubes on the corners only) elif RandomNumber<=9*p: x=0.333*x y=0.333*y z=0.333*z + 0.333 elif (RandomNumber<=10*p): x=0.333*x + 0.666 y=0.333*y z=0.333*z + 0.333 elif (RandomNumber<=11*p): x=0.333*x y=0.333*y + 0.666 z=0.333*z + 0.333 elif (RandomNumber<=12*p): x=0.333*x + 0.666 y=0.333*y + 0.666 z=0.333*z + 0.333 #Starts third plane (z=0.666) elif RandomNumber<=13*p: x=0.333*x y=0.333*y z=0.333*z + 0.666 elif (RandomNumber<=14*p): x=0.333*x + 0.333 y=0.333*y z=0.333*z + 0.666 elif (RandomNumber<=15*p): x=0.333*x + 0.666 y=0.333*y z=0.333*z + 0.666 elif (RandomNumber<=16*p): x=0.333*x y=0.333*y + 0.333 z=0.333*z + 0.666 elif (RandomNumber<=17*p): x=0.333*x + 0.666 y=0.333*y + 0.333 z=0.333*z + 0.666 elif (RandomNumber<=18*p): x=0.333*x y=0.333*y + 0.666 z=0.333*z + 0.666 elif (RandomNumber<=19*p): x=0.333*x + 0.333 y=0.333*y + 0.666 z=0.333*z + 0.666 elif (RandomNumber<=20*p): x=0.333*x + 0.666 y=0.333*y + 0.666 z=0.333*z + 0.666