aboutsummaryrefslogtreecommitdiff
path: root/src/sets.c
blob: 2c0198740e1cd3abce48f890d04da6406164012d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * sets.c
 *
 *  Created on: 15.01.2018
 *      Author: Superleo1810
 */

#include "sets.h"

u32 mandelbrot_s(long double x, long double y, u32 iterations)
{
	long double cx = x, cy = y, x2;
	u32 m = 0;
	while(m <= iterations && (x*x)+(y*y) <= 4)
	{
		x2 = x;
		x = (x*x) - (y*y) + cx;
		y = 2.0*x2*y + cy;
		m++;
	}
	return m;
}

u32 mandelbrot_r(long double x, long double y, u32 iterations)
{
	return _mandelbrot_r(x, y, 0.0, 0.0, 0, iterations, 4.0);
}

u32 _mandelbrot_r(long double x, long double y, long double zx, long double zy, u32 n, u32 iterations, long double threshold)
{
	if ((n < iterations) && ((zx * zx + zy * zy) < threshold)) {
		long double zx_new = (zx * zx - zy * zy + x);
		long double zy_new = (2 * zx * zy + y);
	    if ((zx_new == zx) && (zy_new == zy)) {
	      return iterations;
	    }
	    n = _mandelbrot_r(x, y, zx_new, zy_new, n + 1, iterations, threshold);
	  }
	  return n;
}

u32 julia(long double x, long double y, u32 iterations)
{
	// TODO: Julia-Menge
	return 0;
}