Tetration Fractal.
| 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 30 | # Tetration Fractal
# http://en.wikipedia.org/wiki/Tetration
# FB - 201110237
import math
from PIL import Image
imgx = 512
imgy = 512
image = Image.new("RGB", (imgx, imgy))
# drawing area (xa < xb & ya < yb)
xa = -1.5
xb = -0.75
ya = 0.0
yb = 0.75
maxIt = 256 # max number of iterations allowed
for ky in range(imgy):
    for kx in range(imgx):
        x = xa + (xb - xa) * kx / (imgx - 1)
        y = ya + (yb - ya) * ky / (imgy - 1)
        for i in range(maxIt):
            try:
                e = math.exp(-0.5 * math.pi * y)
                p = math.pi * x / 2
                x = e * math.cos(p)
                y = e * math.sin(p)
            except:
                break
            if math.hypot(x, y) > 1000000:
                break
        image.putpixel((kx, ky), (i % 4 * 64, i % 8 * 32, i % 16 * 16))
image.save("TetrationFractal.png", "PNG")
 | 

 Download
Download Copy to clipboard
Copy to clipboard

Basic arithmetic operations (addition, multiplication, power) are actually first 3 of a general operation sequence. Tetration is the 4th, pentation is the 5th.