If the refactoring proposed in #2 is made, there is yet another improvement that would make the fractal a lot smoother. It basically consists in modifying julia as such:
// Transforms the [0, 1] value to another value using a smoothstep-like function
#[inline]
fn smoother(iter: u8, z: Complex<float>) -> float
{
(iter as float - z.norm_squared().log2().max(1.).log2()).max(0.).min(u8::MAX as float) / u8::MAX as float
}
// Returns a float between 0 and 1 that represents the color of the pixel
fn julia(c: Complex<float>, x: float, y: float) -> float
{
let mut z = Complex::new(x, y);
for i in 0..u8::MAX {
if z.norm_squared() > 4.0 {
return smoother(i, z);
}
z = z * z + c;
}
smoother(u8::MAX, z)
}
If the refactoring proposed in #2 is made, there is yet another improvement that would make the fractal a lot smoother. It basically consists in modifying
julia
as such:Smoothing off: Smoothing on: