diff --git a/README.md b/README.md index f19f8ab..65efb96 100644 --- a/README.md +++ b/README.md @@ -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. + diff --git a/src/fractal.jl b/src/fractal.jl index a941e3e..a6d19a5 100644 --- a/src/fractal.jl +++ b/src/fractal.jl @@ -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"