You can change the average size of the clusters by changing the maxIt value. (The calculation would take longer if you increase it though.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # Random percolation cluster fractals
# FB - 201003243
from PIL import Image
from PIL import ImageDraw
import random
imgx = 512
imgy = 512
image = Image.new("RGB", (imgx, imgy))
maxIt = imgx * imgy / 1.25
for i in range(maxIt):
x = random.randint(0, imgx - 1)
y = random.randint(0, imgy - 1)
r = random.randint(1, 255)
g = random.randint(1, 255)
b = random.randint(1, 255)
r2 = random.randint(1, 255)
g2 = random.randint(1, 255)
b2 = random.randint(1, 255)
image.putpixel((x, y), (r, g, b))
ImageDraw.floodfill(image, (x, y), (r2, g2, b2), (0, 0, 0))
image.save("percolation.png", "PNG")
|
When I ran this code in my IDLE (i've got 2.65 with all the necessary libs installed), I got:
Warning (from warnings module): File "/Users/johnhammink/Documents/Random_Percolation_Cluster_Fractals.py", line 11 for i in range(maxIt): DeprecationWarning: integer argument expected, got float
I tried importing cmath and math but that didn't help :P