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

This fractal created by converting logic statements into equations using fuzzy logic operators:

X: X is as true as Y is true

Y: Y is as true as X is false

See: Scientific American Magazine, February 1993, "A Partly True Story"

Python, 27 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
# Fuzzy Logic Fractal
# See: Scientific American Magazine, February 1993, "A Partly True Story"
# http://en.wikipedia.org/wiki/Fuzzy_logic
# FB - 201108147
import math
from PIL import Image
# drawing area
xa = -1.2
xb = 1.2
ya = -1.2
yb = 1.2
maxIt = 255 # max iterations allowed
# image size
imgx = 512
imgy = 512
image = Image.new("RGB", (imgx, imgy))
for ky in range(imgy):
    for kx in range(imgx):
        x = kx * (xb - xa) / (imgx - 1)  + xa
        y = ky * (yb - ya) / (imgy - 1)  + ya
        for i in range(maxIt):
            if math.hypot(x, y) > 1.1: break
            x0 = 1 - math.fabs(x - y)
            y = 1 - math.fabs(y - (1 - x))
            x = x0
        image.putpixel((kx, ky), (i % 8 * 32, i % 4 * 64, i % 16 * 16))
image.save("FuzzyLogicFractal.png", "PNG")