aboutsummaryrefslogtreecommitdiff
path: root/src/fractals/burningship.c
blob: d9e1a9c895505139958237d6acaa1ad6d43f4569 (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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   burningship.c                                      :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/24 16:15:49 by cacharle          #+#    #+#             */
/*   Updated: 2020/02/27 12:25:24 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "fractol.h"

#define BURNING_SHIP_ESCAPE_RADIUS_SQUARED 4.0

int	burningship(t_state *state, t_complex c)
{
	int			n;
	t_complex	z;
	t_complex	z_square;
	double		tmp;

	(void)state;
	z.r = c.r;
	z.i = c.i;
	n = -1;
	while (++n < state->iterations)
	{
		z_square.i = z.i * z.i;
		z_square.r = z.r * z.r;
		if (z_square.r + z_square.i > BURNING_SHIP_ESCAPE_RADIUS_SQUARED)
			break;
		tmp = z_square.r - z_square.i + c.r;
		z.i = fabs(2.0 * z.r * z.i + c.i);
		z.r = fabs(tmp);
	}
	return (n);
}