Explore
Courses
Batches
Sketches
Statistics
Code a Pookkalam
Jobs
Devsprint
People
Course Creation
Create a Course
Guidelines
Resources
Support
Blogs
My Profile
About Us
Login
Sketches
0
Sierpinski in a spiral
By
Sahaja
Run
# Inspired by "sierpinski" by Anushka Trivedi def midpoint(a, b): """Calculates midpoint between two points a b""" return point((a.x+b.x)/2, (a.y+b.y)/2) def sierpinski(p1, p2, p3, depth): if (depth == 0): return polygon([p1, p2, p3], fill="black") else: mid1 = midpoint(p1, p2) mid2 = midpoint(p2, p3) mid3 = midpoint(p3, p1) return sierpinski(p1, mid1, mid3, depth-1) \ + sierpinski(p2, mid2, mid1, depth-1) \ + sierpinski(p3, mid3, mid2, depth-1) p1 = point(-150, -150) p2 = point(150, -150) p3 = point(0, 150) Sierpinski2 = sierpinski(p1, p2, p3, 5) shape = Sierpinski2 | scale(0.35) | translate(y=120) | repeat(100, rotate(30) | scale(0.96)) show(shape)
Comments
Want to discuss?
Post it here, our mentors will help you out.
Login