aboutsummaryrefslogtreecommitdiff
path: root/src/fractals/tricorn.c
blob: 052cc2f7503b09e0410cd85ab3b9f38d6850184f (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   tricorn.c                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/24 16:00:46 by cacharle          #+#    #+#             */
/*   Updated: 2020/02/25 07:34:01 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "fractol.h"

#define TRICORN_MAX_ITERATION 20
#define TRICORN_ESCAPE_RADIUS_SQUARED 100

int	tricorn(t_state *state, t_complex z)
{
	int		n;
	double	zr;
	double	zi;
	double	zr_square;
	double	zi_square;
	double	tmp;
	
	(void)state;
	zr = z.r;
	zi = z.i;
	n = -1;
	while (++n < state->iterations)
	{
		zi_square = zi * zi;
		zr_square = zr * zr;
		if (zr_square + zi_square > TRICORN_ESCAPE_RADIUS_SQUARED)
			break;
		tmp = zr_square - zi_square + z.r;
		zi = -2.0 * zr * zi + z.i;
		zr = tmp;
	}
	return (n);
}