Friday, February 15, 2008

[Python]Draw a fractal pattern(Julia set)

I wrote a program to draw a fractal pattern.
Julia set - Wikipedia, the free encyclopedia.
I found it is very easy to implement; it took much time to check the mathematical definition of Julia set than to implement. If you already know Python and don't know Python Imaging Library (PIL) yet, I strongly recommend to learn it!

Using PIL you can generate images like above from very simple code:

import Image
import ImageDraw

SIZE = 128
image ="L", (SIZE, SIZE))
d = ImageDraw.Draw(image)

c = 0.5 + 0.2j
for x in range(SIZE):
for y in range(SIZE):
re = (x * 2.0 / SIZE) - 1.0
im = (y * 2.0 / SIZE) - 1.0

for i in range(128):
if abs(z) > 2.0: break
z = z * z + c
d.point((x, y), i * 2)"c:\julia.png", "PNG")

Here is a movie(2MB, c = -0.78 + i * 0.002 + 0.23j (i < 40), center = -0.5 + 0.2j, scale = 1.0). I think this type of movie isn't suitable for MPEG compression, it is raw avi.


Anonymous said...

i know python but did not figure this out, you helped much
keep up the good work

Anonymous said...

Wow beautiful pattern, I tried and it didn't work, maybe something is wrong with my computer, I will let you know how it works. I was hoping that work as well as buy viagra. Thanks for sharing.

hedden said...

The above statement is seen to be contradictory. The situation is
very critical and need an experience complainer to resolve it.
Assignment Help : Physics, Chemistry, Math

Assignment help. Experts available 24/7.

Anonymous said...

That's nice. Have you considered using a modified escape time algorithm to permit smoothing of coloration?