File:Sierpinski triangle.svg

Summary

Source code

Python code

from __future__ import division
import matplotlib.pyplot as plt
plt.figure()
plt.subplot(1,1,1)
plt.axis('off')

def drawBlue(p1,p2,p3):
  plt.fill([p1[0],p2[0],p3[0]],[p1[1],p2[1],p3[1]],facecolor='b',edgecolor='none')

def drawWhite(p1,p2,p3):
   plt.fill([p1[0],p2[0],p3[0]],[p1[1],p2[1],p3[1]],facecolor='w',edgecolor='none')

def midpoint(p1,p2):
  return ((p1[0]+p2[0])/2,(p1[1]+p2[1])/2)
def sierpinski(p1,p2,p3,repeat):
  drawWhite(midpoint(p1,p2),midpoint(p2,p3),midpoint(p3,p1))
  if (repeat <= 8):
    sierpinski(p1,midpoint(p1,p2),midpoint(p1,p3),repeat+1)
    sierpinski(p2,midpoint(p1,p2),midpoint(p2,p3),repeat+1)
    sierpinski(p3,midpoint(p1,p3),midpoint(p2,p3),repeat+1)

drawBlue((0,0),(7,0),(3.5,6.0621778265))

sierpinski((0,0),(7,0),(3.5,6.0621778265),0)

plt.show()

Licensing

w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-3.0#Sierpinski%20triangle.svg

Original upload log

The original description page was here. All following user names refer to en.wikipedia.

Transferred to Commons.

Upload dateUserBytesDimensionsComment
2007-10-21 06:40:53Marco Polo29761774×1536typo
2007-10-21 06:39:47Marco Polo29761774×1536Recursive algorithm for generation
Category:Sierpinski triangles Category:Media missing infobox template Category:Monochrome fractals Category:Order 8 Category:Recursion
Category:CC-BY-SA-3.0 Category:Files with no machine-readable author Category:Files with no machine-readable source Category:Media missing infobox template Category:Monochrome fractals Category:Order 8 Category:Recursion Category:Sierpinski triangles Category:Valid SVG created with Matplotlib code