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

Tetration Fractal.

Python, 30 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
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")

2 comments

FB36 (author) 12 years, 6 months ago  # | flag
# Tetration Calculator
# http://en.wikipedia.org/wiki/Tetration
# FB - 201110237
import math
# Tetration by Linear Approximation
def Tetration_LA(a, x):
    if x <= -1:
        return math.log(Tetration_LA(a, x + 1), a)
    if -1 < x and x <= 0:
        return 1 + x
    if 0 < x:
        return math.pow(a, Tetration_LA(a, x - 1))

# Test
print Tetration_LA(math.e, 0.5 * math.pi)
print Tetration_LA(0.5, -4.3)
print Tetration_LA(math.pi, 0.5 * math.e)
FB36 (author) 12 years, 6 months ago  # | flag

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