Fractal Generation #2

Open
aniva wants to merge 3 commits from fractal into main
2 changed files with 26 additions and 6 deletions
Showing only changes of commit 76e2c11911 - Show all commits

View File

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