A turtle can draw fractals
pythonTurtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzig and Seymour Papert in 1966.
Imagine a robotic turtle starting at (0, 0) in the x-y plane. After animport turtle, give it the commandturtle.forward(15), and it moves (on-screen!) 15 pixels in the direction it is facing, drawing a line as it moves. Give it the commandturtle.right(25), and it rotates in-place 25 degrees clockwise.
(The uniqueness of this article is that it features an interactive python code snippet inside a regular blog post. This is done by a tool of mine namedKLIPSE - a multi-language evaluator pluggable on any web page.)
The amazing thing about Python Turtle is that you can draw quite very cool shapes with a couple of recursive instructions to this turtle. For instance, theSpace Filling Hilbert Curve:
Go ahead, modify the code (the depth, the step or anything else) and the turtle will immediatly restart to draw.
Can you draw other cool shape with the turtle? Please share your code and screenshots on the comments below or on twitter…
This article was inspired byLindenmayer Fractals.
If you want to write your own blog post with interactive code snippets in python, you shoulde checkout theKLIPSE plugin documentation and usage: it is a simple javascript tag that you add to your page.
The python code evaluation in the browser is made possible bySkulpt.
Subscribe to Yehonathan Sharvit newsletter
Get the latest and greatest from Yehonathan Sharvit delivered straight to your inbox every week.
