Mandelbrot

Visualização do conjunto de Mandelbrot e do conjunto de Julia gerados por shader WebGL.

f(z)=z2+cf(z) = z^2 + c

int iterate(vec2 p, vec2 c) {
	const int maxIterations = 100;
	const float threshold = 16.0;

	int result = 0;

	for (int i = 0; i < maxIterations; i++) {
		result++;

		float _x = p.x * p.x - p.y * p.y + c.x;
		float _y = 2.0 * p.x * p.y       + c.y;

		float mag_sqr = _x * _x + _y * _y;
		if (mag_sqr > threshold) {
			break;
		}

		p.x = _x;
		p.y = _y;
	}

	return result;
}

Referências