To paint the mandelbrot set, the "color" of each square of Kara's world must be determined (method test). To do this, the coordinates of Kara's world must be transformed into coordinates of the Mandelbrot set image (methods calculateMandelX/Y).

for row in 0...KARA_HEIGHT
  for col in 0...KARA_WIDTH
    x = X_MIN + col * (X_MAX-X_MIN) / KARA_WIDTH
    y = Y_MIN + row * (Y_MAX-Y_MIN) / KARA_HEIGHT

    i = test(x, y, ITERATIONS)
    if i == ITERATIONS
      world.setLeaf(col, row, true)
      tools.checkState
    end

  end
end