from visual import * from random import * scene = display(title='Sierpinski Carpet', width=800,height=800,center=(0.5,0.5,0),range=0.6) x=0.0 y=0.0 p=1.0/8.0 n=0 while n<10000: RandomNumber=random() if RandomNumber<=p: x=0.333*x y=0.333*y if (RandomNumber>p and RandomNumber<=2*p): x=0.333*x+0.333 y=0.333*y if (RandomNumber>2*p and RandomNumber<=3*p): x=0.333*x+0.666 y=0.333*y if (RandomNumber>3*p and RandomNumber<=4*p): x=0.333*x y=0.333*y+0.333 if (RandomNumber>4*p and RandomNumber<=5*p): x=0.333*x+0.666 y=0.333*y+0.333 if (RandomNumber>5*p and RandomNumber<=6*p): x=0.333*x y=0.333*y+0.666 if (RandomNumber>6*p and RandomNumber<=7*p): x=0.333*x+0.333 y=0.333*y+0.666 if (RandomNumber>7*p and RandomNumber<=8*p): x=0.333*x+0.666 y=0.333*y+0.666 dot=sphere(pos=(x,y), radius=0.002)