+#include <stddef.h>
#include "color.h"
t_color to_color(unsigned int num)
norm_par = 0.;
else if (norm_par > 1.)
norm_par = 1.;
- res.a = zero.a + norm_par * one.a;
- res.r = zero.r + norm_par * one.r;
- res.g = zero.g + norm_par * one.g;
- res.b = zero.b + norm_par * one.b;
+ res.a = (1 - norm_par) * zero.a + norm_par * one.a;
+ res.r = (1 - norm_par) * zero.r + norm_par * one.r;
+ res.g = (1 - norm_par) * zero.g + norm_par * one.g;
+ res.b = (1 - norm_par) * zero.b + norm_par * one.b;
return (res);
}
return (lin_interp_color(to_color(0x000000FF), to_color(0x00FFFF00), normalized_par));
}
-t_color double_grad(double normalized_par)
+t_color general_palette(double np, const t_color *array, size_t size)
{
- const double breakpoint = 0.1;
+ size_t i;
- if (normalized_par < breakpoint)
- return (lin_interp_color(to_color(0x00000000), to_color(0x000000FF), normalized_par / breakpoint));
- return (lin_interp_color(to_color(0x000000FF), to_color(0x00FFFF00), (normalized_par - breakpoint) / breakpoint));
+ if (!array)
+ return (to_color(0x00000000));
+ if (np < 0 || size <= 1)
+ return (array[0]);
+ i = 1;
+ while (i + 1 < size)
+ {
+ if (np < (i + 1)/(double)size)
+ return (lin_interp_color(array[i], array[i + 1], np * size - i));
+ ++i;
+ }
+ return (lin_interp_color(array[i], array[1], np * size - i));
}
t_color tri_color(double np)
{
- if (np < 0)
- np = 0;
- else if (np > 1)
- np = 1;
- if (np < 1/3.)
- return (lin_interp_color(to_color(0x000000FF), to_color(0x00FFFF00), np * 3));
- if (np < 2/3.)
- return (lin_interp_color(to_color(0x00FFFF00), to_color(0x00FF0000), np * 3 - 1));
- return (lin_interp_color(to_color(0x00FF0000), to_color(0x000000FF), np * 3 - 2));
+ t_color colors[4];
+
+ colors[0] = to_color(0x00000000);
+ colors[1] = to_color(0x000000FF);
+ colors[2] = to_color(0x00FFFF00);
+ colors[3] = to_color(0x00FF0000);
+ return (general_palette(np, colors, 4));
}
t_color lin_interp_color(t_color zero, t_color one, double norm_par);
t_color basic_palette(double normalized_par);
-t_color double_grad(double normalized_par);
+t_color general_palette(double np, const t_color *array, size_t size);
t_color tri_color(double np);
#endif
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */
-/* Updated: 2023/11/11 17:31:25 by ljiriste ### ########.fr */
+/* Updated: 2023/11/11 18:41:55 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
++count;
}
if (count == max_count)
- return (0);
+ return (-1);
return (fmod(count / 100., 1.));
}
return (0);
}
-int no_event_handle(__attribute__((unused)) t_session *s)
+/* valgrind indicates an issue when the draw_fractal is in proccess
+ * while and ESC is pressed thus ending the program.
+ *
+ * Setting the condition to less than 1 basically turns this redrawing
+ * off.
+ */
+int no_event_handle(t_session *s)
{
- if (s->view.resolution < 100)
+ if (s->view.resolution < 1)
{
s->view.draw_whole = 0;
s->view.resolution *= 2;
{
if (argc == 0)
free(argv);
- s->img.width = 1024;
- s->img.height = 768;
+ s->img.width = 200;
+ s->img.height = 200;
init_view(s);
return ;
}