Last active
January 18, 2016 22:10
-
-
Save typemytype/738aebeedeea653ae0e3 to your computer and use it in GitHub Desktop.
Fractals are cool!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # create a reusable bezierPath with a triangle | |
| triangle = BezierPath() | |
| triangle.moveTo((0, 0)) | |
| triangle.lineTo((width(), 0)) | |
| triangle.lineTo((width()/2, height())) | |
| triangle.closePath() | |
| # set the maximum recusions | |
| maxSteps = 7 | |
| # recursive drawing | |
| def recursiveDrawTriangle(steps): | |
| # draw the initial triangle | |
| drawPath(triangle) | |
| # check if it ran out of steps | |
| if steps < 0: | |
| return | |
| # save the whole thing | |
| save() | |
| # scale it | |
| scale(.5) | |
| # start a new recursive drawing | |
| recursiveDrawTriangle(steps-1) | |
| # translate to the right | |
| translate(width(), 0) | |
| # start a new recursive drawing | |
| recursiveDrawTriangle(steps-1) | |
| # translate back and up | |
| translate(-width()*.5, height()) | |
| # start a new recursive drawing | |
| recursiveDrawTriangle(steps-1) | |
| # restore it back | |
| restore() | |
| # some drawing stuff | |
| stroke(0) | |
| fill(None) | |
| # go | |
| recursiveDrawTriangle(maxSteps) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sweet!
But what!, you call a function within itself... Okay, new things every day eh :)
Thanks Frederik