From the course: Python: Recursion

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Sierpinski triangle

Sierpinski triangle - Python Tutorial

From the course: Python: Recursion

Start my 1-month free trial

Sierpinski triangle

- [Instructor] Next up, we have the Sierpinski Triangle. So the Sierpinski Triangle is a fractal with the shape of an equilateral triangle subdivided recursively into smaller equilateral triangles. Steps for drawing it are, draw the outer triangle, make three recursive calls, one for each of the new corner triangles, and repeat until we reach the base case which is when the depth equals zero. Let's look at the code for this. So, this is in chapter eight, video two, sierpinskitriangle.py. Then we can run it by doing Ctrl + Shift + F10. And there it is. Now there's a couple of things we can do to help to follow along with what's going on visually, with also understanding what's going on programmatically. I've set the speed here to one, which is very good for following along. If you want it a bit faster, it'll go as high I think as 10, if I recall. So, let's just change that value and also change the depth,…

Contents