fractals are mathematical objects whose jaggedness (formally, hausdorff dimension) is greater than that of a typical shape in whatever dimension we're studying (euclidean dimension). fractals are generally self-similar or have a recursive structure (but this is not a necessary condition).
two famous fractals are the julia set and the mandelbrot set, both of which are self-similar. these fractals are generated by repeatedly applying a function f(z) = z² + c to a point on the complex plane. if the sequence of values generated by this process diverges off to infinity, the initial point is excluded from the set. in applying this criterion, we can see how quickly points in different regions of the complex plane diverge or converge:
from PIL import Image
from glitchcraft.fractal import colorshift
output_dir = Path("../artifacts/output/fractals")
output_dir.mkdir(exist_ok=True)
blank = Image.new("RGB", src.size, color="white")
colorshift(blank, normalization=3).save(output_dir/"julia.png")
in the image above, the number of iterations before convergence is mapped to a color. instead of starting with a blank value of (255, 255, 255)
, we can use a pixel's intensity as a starting value, which is what the colorshift
function does, when applied to an image.
src = Image.open("../artifacts/input/stream_square.png")
for (cx, cy) in [
(-1, 1), # default
(-0.7, 0.27015), # julia
(-0.5, 0.5) # another point
]:
for normalization in [3, 6, 9]:
print(normalization, cx, cy)
colorshift(src, normalization=normalization, cx=cx, cy=cy).save(output_dir/("stream_shifted_{}_{}_{}.png".format(normalization, cx, cy)))
starting with this initial image, we can vary the fractal colorshift parameters:
changing the starting point of the convergence search ((cx, cy)
) and the initial intensity mapping (normalization
) produces these results:
(cx, cy) |
(-1, 1) |
(-0.7, 0.27015) |
(-0.5, 0.5) |
---|---|---|---|
normalization = 3 |
|||
normalization = 6 |
|||
normalization = 9 |
here's an example of fractal colorshifting combined with other techniques