Welcome, guest | Sign In | My Account | Store | Cart

5 Regular Polygon IFS Fractals.

Python, 29 lines
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29``` ```# Regular Polygon IFS Fractal # FB - 201003151 from PIL import Image import math import random # image size imgx = 512 imgy = 512 for n in range(3, 8): image = Image.new("L", (imgx, imgy)) m = n % 2 p = (n - m + 2.0) / 4.0 q = p + 1.0 a = 2.0 * math.pi / n b = a / 2.0 * (1.0 - m) x = 0.0 y = 0.0 for i in range(imgx * imgy): k = random.randint(0, n - 1) c = k * a + b x = (x + math.sin(c)) / q y = (y + math.cos(c)) / q kx = int((x * p + 1.0) / 2.0 * (imgx - 1)) ky = int((y * p + 1.0) / 2.0 * (imgy - 1)) image.putpixel((kx, ky), 255) image.save("rpIFSfr_" + str(n) + ".png", "PNG") ```

#### 1 comment

FB36 (author) 13 years, 2 months ago

Here is another type of the same fractals which I called Hexaflake-type:

``````# Regular Polygon IFS Fractals (Hexaflake-type)
# FB - 201003217
from PIL import Image
import math
import random

imgx = 512
imgy = 512

# coefficients of the t(n) (found using curve-fitting to experimentation data)
a0 =  1.1840972490170618e+01
b0 =  5.0562324258401986e-02
c0 = -1.3007278403313109e+01
d0 =  1.2962513369840259e-02
e0 =  4.6912973441805188e+06
f0 = -5.3565139656093468e+00

for n in range(3, 9): # triangle to octagon

t = float(n) / ( a0 * math.exp(b0 * n) + c0 * math.exp(d0 * n) + e0 * math.exp(f0*n))

image = Image.new("L", (imgx, imgy))
m = n % 2
p = (n - m + 2.0) / 4.0
q = p + 1.0
a = 2.0 * math.pi / n
b = a / 2.0 * (1.0 - m)
x = 0.0
y = 0.0

for i in range(imgx * imgy):
k = random.randint(0, n)
if k < n:
c = k * a + b
x = (x + math.sin(c)) / q
y = (y + math.cos(c)) / q
else:
x = x / t
y = y / t

kx = int((x * p + 1.0) / 2.0 * (imgx - 1))
ky = int((y * p + 1.0) / 2.0 * (imgy - 1))
image.putpixel((kx, ky), 255)

image.save("rpIFSfrHT_" + str(n) + ".png", "PNG")
``````
 Created by FB36 on Mon, 15 Mar 2010 (MIT)