feat: Stabilize fractal shape

This commit is contained in:
Leni Aniva 2025-06-03 15:08:18 -07:00
parent d814811e9a
commit 76e2c11911
Signed by: aniva
GPG Key ID: D5F96287843E8DFB
2 changed files with 26 additions and 6 deletions

View File

@ -1,3 +1,22 @@
# Boundary Bad Apple!!
Boundary-aware Bad Apple!! animation generation
## Fractal
Usage:
Load an image with `Images`
```julia
using Images, FileIO
img = load("examples/frame.png")
```
Then generate the fractal using the pseudomandelbrot function
```julia
include("src/fractal.jl")
mandel(img, -3-2im, 2+2im)
```
The coördinates specified are the bottom left and top right, respectively.

View File

@ -12,23 +12,24 @@ function sample(m, u, v)
end
end
function is_stable(m, z1, z2, z)
function is_stable(m, z1, z2, c)
iter = 1000
x1 = real(z1)
y1 = imag(z1)
x2 = real(z2)
y2 = imag(z2)
c = z
z = c
for _ in 1:iter
if abs(z) > 2
r = abs(z)
if r > 4
return false
end
# Sample the image at position z
u = (real(z) - x1) / (x2 - x1)
v = (imag(z) - y1) / (y2 - y1)
f = sample(m, u, v)
if f == 0
z = z^2
if f < 0.5
z = z^2/8 + c
else
z = z^2 + c
end
@ -42,7 +43,7 @@ function mandel(m, z1::Complex, z2::Complex)
for (i, x) in enumerate(range(real(z1), real(z2), width))
for (j, y) in enumerate(range(imag(z1), imag(z2), height))
t = greyscale(m[i,j])
s = is_stable(m, z1, z2, x + y * im)
s = !is_stable(m, z1, z2, x + y * im)
if t > 0.5
if s
buffer[i,j] = colorant"white"