pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Tiny Fractals

Tiny Fractals - 145 bytes

Vitor Bosshard (algorias)

Tags:

Description

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

removed init(), as seen in NanoSnake!

Links

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

Screenshot


click to view original size

Releases

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

Pygame.org account Comments

If you wish to leave a comment with your pygame.org 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 mediafire.com) 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?
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Dec 16, 2014


Dec 14, 2014

Dec 9, 2014

Dec 6, 2014

Dec 5, 2014

Dec 3, 2014

Nov 27, 2014


Nov 13, 2014

Nov 11, 2014


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