Friday, March 12, 2010

Design your own fractal

After I found this interesting paper - I decided to write some sort of fractal generation program that tests that paper idea of different generators and initiators. Basic fractal generation algorithm is this:

1. Draw initiator shape (triangle, rectangle, or other polygon)
2. Draw generator polyline
3. Set initial fractal to initiator shape
4. For each iteration
For each fractal line
Replace line with generator polyline

Thats it. After some iterations new fractal figure will emerge. Of cource "real" fractal generation agorithm is a bit more complex - there will be generator polyline scaling / rotation / translation operations, but lets not focus on details :-) If you will want my program you can download it and check all details. In my program you can draw generator as well as initiator and see resulting fractal (calculated in 6 iterations). You can download my program from here.
Known issues:
Please use not more than 8 lines for generator or initiator. Otherwise fractal generation process can hang-up because of too many intermediate steps involved.

NOTE: This program is coded in Lua language,- by using free 2D game engine,- so to be able to run my program you need to install above mentioned 2D game engine and after that you can extract archive and run "" program. If you need to see Lua program code - then just rename "" to some *.zip file, extract it and you can see file "main.lua" - source code. BTW, Lua is great scripting language, which programs on average runs faster than Ruby or Python scripts and Lua core is very lightweight - that is why Lua is very suitable for embedding purposes,- such as scripting language for game engines. Also I want to praise love 2D game engine. It is very good for game/animation prototyping tasks. Also has good learning curve. So if you need rapid prototyping of games - you can use love 2D engine with Lua. Enough rants, lets see some resulting fractals :-). At first some classic ones.
Koch snowflake:

Modified Koch antisnowflake:

Structure composed of Sierpinski triangles:

This remainds to me dragon curve:

And now, more bizarre fractals.

Now my favorite one :-)

Seems there is a lot of space for experimenting with different types of generator/initiator.

Have fun with fractals and Lua !!


  1. Suggests an interesting game or puzzle: Give the generator and initiator, try to guess the appearance of the curve. Or vice versa of course.

    Question: In most cases the fractal pattern has approximately the same symmetry as the initiator, but there's one exception (the sixth of your examples). What's the deal there?

  2. Interesting suggestion Brian, thanks !

  3. Hi, great article... would it be possible to re-post the Lua/LOVE source code linked to above? The current link appears to be broken... cheers!

  4. Thanks, I've noticed also that my file somehow is lost in that google-group (heh, possibly because of some bad hacker or google employee). But i'm very sorry - I don't have original file on my computer either. Maybe some day i will try to re-code this little tool...


Comment will be posted after comment moderation.
Thank you for your appreciation.