Skip to main content

Tiny Fractals - 175 bytes

A tiny iterated function system, generates a Sierpinski Gasket.


Vitor Bosshard
(algorias)
A tiny iterated function system, generates a Sierpinski Gasket and other fractals.

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()

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()

Changes

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.

Links

Home Page
http://www.pygame.org/

Releases

Tiny Fractals 164 bytes — 1 Aug, 2008

Tiny Fractals 151 bytes: Now with memory leak! — 2 Aug, 2008

Tiny Fractals 172 bytes — 31 Jul, 2008

Tiny Fractals 175 bytes — 31 Jul, 2008

Tiny Fractals 153 bytes — 2 Aug, 2008

Tiny Fractals 145 bytes — 16 Aug, 2008

Pygame.org account Comments