Skip to main content
100%

Mandelbrot

✓ Published0🌍 Public
KKristin Baumann
Last edited Apr 23, 2024
Created on Apr 23, 2024
Forked from Circles with D3

This visualization renders a slice of the Mandelbrot set as a 360 by 360 grid of pixels on an HTML canvas. Each pixel’s color is computed by iterating the complex function `z = z² + c` for up to 200 iterations; colors, from black to a teal gradient, are derived from the iteration count using `d3.scaleLinear`. The visualization uses Svelte components (`App.svelte`, `Canvas.svelte`, `Pixel.svelte`) where the canvas context manages drawing and invalidation for rendering.

AI-generated description

Mandelbrot Set

Fractal pattern

Math

from CodingTrain Coding Challenge: https://www.youtube.com/watch?v=6z7GQewK-Ks

  • Sqrt(-1) is an imaginary number i
  • Complex number has a real component (a) and an imaginary component (b): a+bi
  • Set of complex mapped on canvas with x axis mapping a and the y axis mapping b
  • Function f(z) = z^2 + c = z^2 + (a + bi)
  • f(z_0) = 0
  • f(z_1) = 0^2 + (a + bi) = a + bi = c
  • f(z_2) = c^2 + c --> need to find out c^2
  • c^2 = (a + bi) * (a + bi) = a^2 + 2abi + b^2*i^2 = a^2 + 2abi - b^2 = (a^2-b^2) + 2ab * i
  • --> meaning c^2 is a complex number with a real component a^2-b^2 and and imaginary component 2ab
  • when calculation iteration over many iterations does result of function stay bounded or goes to infinity

Code Setup

From D3-Svelte Starter: https://vizhub.com/higsch/8599a94f8de14a858c04f8064ce368d7

MIT Licensed

Similar vizzes