import matplotlib.pyplot as plt
plt.figure(figsize=(6,6),dpi=80)
def F(x1,y1,x2,y2,x3,y3): #定義遞迴程式
if((x2-x1) <0.2) :return
(x4,y4)=((x1+x2)/2,(y1+y2)/2)
(x5,y5)=((x2+x3)/2,(y2+y3)/2)
(x6,y6)=((x3+x1)/2,(y3+y1)/2)
X=[x4,x5,x6]
Y=[y4,y5,y6]
plt.fill(X,Y,color="white")
F(x1,y1,x4,y4,x6,y6)
F(x4,y4,x2,y2,x5,y5)
F(x6,y6,x5,y5,x3,y3)
#以下內容為主程式
(x1,y1)=(0,0)
(x2,y2)=(1,0)
(x3,y3)=(0.5,0.5*3**0.5)
X=[x1,x2,x3]
Y=[y1,y2,y3]
plt.fill(X,Y,color="green")
F(x1,y1,x2,y2,x3,y3)
plt.show()