Skip to main content
Code Review

Return to Revisions

4 of 4
replaced http://meta.codereview.stackexchange.com/ with https://codereview.meta.stackexchange.com/

Mandelbrot Set Fractal

I thought I would give this months community challenge a try. This is my first time using Python. It does take quite a while to run and it's not very colourful but it works.

from PIL import Image, ImageDraw
img = Image.new("RGB", (2400, 2400), "white")
draw = ImageDraw.Draw(img)
max_count = 200
width = img.size[0]
height = img.size[1]
for row in range(height):
 for col in range(width):
 str_output = ""
 c = complex(
 (col - float(width)/2.0)*5.0/float(width),
 (row - float(height)/2.0)*5.0/float(height)
 )
 iteration = 0
 z = 0
 while abs(z) < 2 and iteration < max_count:
 z = z**2 + c
 iteration += 1
 if abs(z) < 2:
 draw.point((col, row), fill="black")
 else:
 draw.point((col, row), fill=(255 - iteration,255 - iteration,255 - iteration))
img.save('mandelbrot.png')

black and white mandelbrot set

lang-py

AltStyle によって変換されたページ (->オリジナル) /