moltenform
Home
Previous: Microsoft
Previous: Microsoft
Drawdraw
Drawdraw
Next: FPGA
Next: FPGA

Drawdraw

(from a blog post I wrote in 2007, halfhourhacks 2007-10-recursive-shapes-v02.html)

This is the older Python version of Drawdraw.


While doodling in Bio, I thought of a way to programmatically draw any recursively-defined shape. By this, I mean any shape that contains a scaled-down version of the entire shape, scaled down or rotated in a linear way. This is a property found in many fractals.


Traditionally, and in all of the fractal-drawing software of this type I've seen, the shapes are defined with turtle-style commands (turn right, draw a line, turn left, and so on). There exists a specific system called L-System that can define recursive pictures, and with a lot of work can probably define everything my program can, with the exception of curves. However, when looking at the shape, I do not always find the long list of turtle instructions or L-System rules to be intuitive. I decided to instead use traditional Euclidean x and y coordinates, and Python code as the rule defining the next iteration. This way, I can sketch out a shape on a piece of paper and enter its code very quickly and clearly. It is much easier to me to enter a shape in terms of x and y.

I had an idea for drawing curved lines that turned out very well. The code actually draws an arc of a circle, but positioned so that the arc passes through the two points. A parameter specifies how much curvature should be given.


Looking at the still images is only half of it: I added an easy way to draw animations! There are a lot of really cool animations defined in the samples. (Play them by removing the # and pressing draw.)

Here is the code. (Requires Python 2.5, cross-platform and used on Windows and Linux). All you need to do is unzip the file, open main.py, load a shape from the shapes menu and start playing with it! The argument to the .draw() method is the number of iterations (don't make this too big). You are encouraged to tweak the code or create your own shapes.

I wrote this just for fun, and it's (unfortunately) not connected with anything I'm doing at school.

Planned for the next version:
Drawing images, ellipses, text, save images as PNG files, anti-aliasing.

Back