Skip to main content

juliaSDF: Julia Set Fractal Distance Field

Complex Number Iteration for Fractal Boundary Detection

The juliaSDF function generates a Julia set fractal pattern through iterative complex number calculations. This function evaluates the escape time of points under the iteration zn+1=zn2+cz_{n+1} = z_n^2 + c, where cc is a complex constant.

Mathematical Foundation

The Julia set is defined by the iterative formula:

zn+1=zn2+cz_{n+1} = z_n^2 + c

where:

  • z0z_0 represents the initial complex coordinate (transformed input position)
  • cc is a complex constant that determines the fractal shape
  • The iteration continues until zn>4|z_n| > 4 or maximum iterations are reached

The escape time normalization:

n=escape_iterationmax_iterationsn = \frac{\text{escape\_iteration}}{\text{max\_iterations}}

produces a continuous field value representing the fractal boundary distance.

Function Variants

FunctionParametersDescription
juliaSDFst, center, c, rFull parameterization with center and radius
juliaSDFSimplest, c, rSimplified version with default center at (0.5, 0.5)

Implementation Demonstrations

Live Editor
const fragment = () => {
      const pos = uv.sub(0.5)
      const c = vec2(-0.7, 0.27015)
      const fractal = juliaSDF(pos.add(0.5), vec2(0.5), c, 1.2)
      const color = fractal.mul(vec3(1, 0.8, 0.3))
      return vec4(color, 1)
}