pygame is
Simple DirectMedia Layer is
Site Swing
Tiny Fractals

Tiny Fractals - 175 bytes

Vitor Bosshard (algorias)



A tiny iterated function system, generates a Sierpinski Gasket and other fractals.

from pygame import*
for e in l:

And here's the code in compact form:
from pygame import*;w=256;z=w,w;l=[z];d=display;s=d.set_mode(z)
for e in l:x,y=e;s.set_at(e,e+e);x/=2;y/=2;l+=(x,y),(x,y+w),(x+w,y+w);d.flip()


Reused a variable, and took a 75% speed penalty in exchange for 4 more bytes. I can still reduce 2 more bytes, but at the expense of messy code.


Home Page:


click to view original size


Tiny Fractals - 145 bytes - Aug 16, 2008
Tiny Fractals - 153 bytes - Aug 2, 2008
Tiny Fractals - 151 bytes: Now with memory leak! - Aug 2, 2008
Tiny Fractals - 164 bytes - Aug 1, 2008
Tiny Fractals - 172 bytes - Jul 31, 2008
Tiny Fractals - 175 bytes - Jul 31, 2008 account Comments

If you wish to leave a comment with your account, please sign in first.

August 23, 2008 2:19pm - Vitor Bosshard - nickname: (algorias)
No, replacing 2 instances of z with (w,w) is longer than the current setting.
August 17, 2008 9:38am - Ian Mallett - nickname: (geometrian)
You can make the 145B version shorter by replacing "z" with "w,w" and removing line 3.
July 31, 2008 7:50pm - Vitor Bosshard - nickname: (algorias)
No special name, just Sierpinski's triangle (or gasket). The reason the code is so short is because what I hardcoded is actually a simplified version of a more complex formula you can use to create pretty much any fractal you want.
July 31, 2008 2:46pm - Luca Fabbri - nickname: (keul) - 4/5
Next time insert your code inside a <pre> </pre> so your spaces will be preserved.
July 31, 2008 1:13pm - Ian Mallett - nickname: (geometrian)
HTML doesn't like special characters. Oh well.
July 31, 2008 1:12pm - Ian Mallett - nickname: (geometrian)
That's what I thought, but the Sierpi&#324;ski Gasket is normally constructed with an equilateral triangle. I was wondering if there is any special name for one with a right triangle.
July 30, 2008 11:59pm - Jordan Trudgett - nickname: (tgfcoder)
Sierpinski's Triangle.
July 30, 2008 11:26pm - Ian Mallett - nickname: (geometrian)
This code is amazingly simple. What is this fractal called?
July 30, 2008 10:23pm - Vitor Bosshard - nickname: (algorias)
Thanks, fixed it now, except for indentation after the while statement.
July 30, 2008 9:52pm - Ian Mallett - nickname: (geometrian)
Put <br> after each line.
July 30, 2008 7:59pm - Luke Endres - nickname: (besktrap)
You don't post your code; you should zip your program, host it on a file hosting website (such as put that link as the source/homepage here at pygame! cheers!
July 30, 2008 7:44pm - Vitor Bosshard - nickname: (algorias)
When I post the code, it kills all my line breaks. Can anyone help?

our projects welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
recent releases
Mar 28, 2015

Mar 27, 2015

Mar 25, 2015

Mar 24, 2015

Mar 20, 2015

Mar 18, 2015

Mar 17, 2015

Mar 12, 2015

Feb 24, 2015

... more!
for pygame related questions, comments, and suggestions, please see help (lists, irc)