from visual import * from visual.graph import * from random import * rad=5e-3 # the radius of a point scene=display( title="Sierpinski triangle", height=600,width=600,x=0,y=200, foreground=color.black, background=color.white, fov=1e-8, userspin=0,userzoom=0, center=vector(.5,.5,0),range=(0.6,0.6,0.6)) x=0.0 y=0.0 a=[0.5 , 0.5 , 0.5 ] b=[0.0 , 0.0 , 0.0 ] c=[0.0 , 0.0 , 0.0 ] d=[0.5 , 0.5 , 0.5 ] e=[0.0 , 0.5 , 0.25 ] f=[0.0 , 0.0 , 0.5 ] K=3 #dummy needed for starting "highlighting" effect new_point=sphere(pos=(x,y),radius=0,visible=0) while(1): rate(1500) dum=randint(0,K-1) x=a[dum]*x+b[dum]*y+e[dum] y=c[dum]*x+d[dum]*y+f[dum] #remove highlighting from the last new_point new_point.color=color.blue new_point.radius=rad #now, show a new point with highlighting new_point=sphere(pos=(x,y),radius=5.*rad,color=color.red)