from visual import * from random import * import Image import webbrowser #Create a 601 by 601 pixels image, black and white) im= Image.new(mode="1", size=(601,601)) x=0.0 y=0.0 count=0 #Iterates count times the 1/2 distance, 3 corners chaos game while count<100000: count=count+1 RandomNumber=random() if RandomNumber<=0.333: x=x-0.5*x y=y-0.5*y if (RandomNumber>0.333 and RandomNumber<=0.666): x=x+0.5*(1-x) y=y-0.5*y if RandomNumber>0.666: x=x+0.5*(0.5-x) y=y+0.5*(0.866-y) im.putpixel((int(600*x),600-int(600*y)),1) im.save("SierpinskiPutPixel.jpg") im.show("SierpinskiPutPixel.jpg") webbrowser.open("SierpinskiPutPixel.jpg")