cleared out the fractal stuff

This commit is contained in:
djonker 2023-10-26 10:45:19 +02:00
parent 258fc52da0
commit 324929acdd
13 changed files with 21 additions and 1155 deletions

View File

@ -6,7 +6,7 @@
# By: djonker <djonker@student.codam.nl> // \ \ __| | | \ \/ / # # By: djonker <djonker@student.codam.nl> // \ \ __| | | \ \/ / #
# (| | )|_| |_| |> < # # (| | )|_| |_| |> < #
# Created: 2022/11/24 10:12:10 by djonker /'\_ _/`\__|\__,_/_/\_\ # # Created: 2022/11/24 10:12:10 by djonker /'\_ _/`\__|\__,_/_/\_\ #
# Updated: 2023/10/25 14:06:02 by djonker ######## odam.nl # # Updated: 2023/10/26 10:43:49 by houtworm ######## odam.nl #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -17,16 +17,7 @@ HEAD =-I ./include -I $(MLX)/include
RM =rm -rf RM =rm -rf
UNAME_S :=$(shell uname -s) UNAME_S :=$(shell uname -s)
LIB =libft/libft.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm LIB =libft/libft.a mlx/build/libmlx42.a -ldl -lglfw -pthread -lm
SRC =src/main.c\ SRC =src/main.c
src/colors.c\
src/zoommove.c\
src/keyhooks.c\
src/mousehooks.c\
src/print.c\
src/error.c\
src/fractal.c\
src/fractals1.c\
src/fractals2.c
OBJ =$(SRC:src/%.c=obj/%.o) OBJ =$(SRC:src/%.c=obj/%.o)
all: libft libmlx $(NAME) all: libft libmlx $(NAME)

BIN
cub3d Executable file

Binary file not shown.

73
cub3d.h
View File

@ -1,30 +1,24 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* fractol.h |o_o || | */ /* cub3d.h :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */ /* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/29 03:25:46 by houtworm #+# #+# */ /* Created: 2022/11/29 03:25:46 by houtworm #+# #+# */
/* Updated: 2022/12/29 06:29:04 by djonker \___)=(___/ */ /* Updated: 2023/10/26 10:37:13 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef FRACTOL_H #ifndef CUB3D_H
# define FRACTOL_H # define CUB3D_H
# include <unistd.h> # include <unistd.h>
# include <math.h> # include <math.h>
# include "libft/libft.h" # include "libft/libft.h"
# include "mlx/include/MLX42/MLX42.h" # include "mlx/include/MLX42/MLX42.h"
typedef struct s_cnbr
{
long double re; //Real Number
long double im; //Imaginary Number
} t_cnbr;
typedef struct s_varlist typedef struct s_varlist
{ {
mlx_t *mlx; //mlx instance mlx_t *mlx; //mlx instance
@ -32,65 +26,6 @@ typedef struct s_varlist
mlx_image_t *font[30]; //mlx font image mlx_image_t *font[30]; //mlx font image
int w; //actual window width used everywhere int w; //actual window width used everywhere
int h; //actual window height used everywhere int h; //actual window height used everywhere
int fontnbr; //number printed strings on the screen
char *fractal; //name of fractal used for title and info
int fractalid; //int id of the fractal to faster compare
char *cscheme; //name of current colorscheme to print
int cschemeid; //id of current colorscheme to compare
int cscale; //scale used to generate colorschemes
int cshi; //used for shifting colors by 1
int csha; //total amount of colors/shades
int32_t colors[1530]; //colorscheme colors
int iter; //number of iterations to do
long long calc; //Number of calculations per frame
long double xmax; //max number shown on the horizontal numberplane
long double ymax; //max number shown on the vertical numberplane
long double xmin; //min number shown on the horizontal numberplane
long double ymin; //min number shown on the vertical numberplane
long double xscale; //scale of visible numbers horizontal numberplane
long double yscale; //scale of visible numbers vertical numberplane
long double julre; //adjustable c value for x axis
long double julim; //adjustable c value for y axis
int xcur; //current x position of the mouse
int ycur; //current y position of the mouse
int psycho; //psycho mode toggle
int help; //help screen toggle
int info; //info screen toggle
int redraw; //if true then redraw
long double power; //for the mandelpower
} t_varlist; } t_varlist;
typedef struct s_threads
{
t_varlist *vl;
int x;
int y;
} t_threads;
void mousehook(void *param);
void scrollhook(double xdelta, double ydelta, void *param);
void keyhook(mlx_key_data_t keydata, void *param);
void keyhookextra(void *param);
void keyhookmove(void *param);
void keyhookfractal(void *param);
void resizehook(int x, int y, void *param);
void setcolorscheme(t_varlist *vl);
void redrawimage(t_varlist *vl);
void resetfractal(t_varlist *vl);
void ft_error(int r);
void showinfo(t_varlist *vl);
void showhelp(t_varlist *vl);
void justmove(t_varlist *vl, char dir);
void zoomtomouse(t_varlist *vl);
void zoomfrommouse(t_varlist *vl);
void fractal(t_varlist *vl);
void mandelbrot(t_varlist *vl, int x, int y, t_cnbr c);
void mandelcloud(t_varlist *vl, int x, int y, t_cnbr c);
void mandelfeather(t_varlist *vl, int x, int y, t_cnbr c);
void julia(t_varlist *vl, int x, int y, t_cnbr z);
void mandelpower(t_varlist *vl, int x, int y, t_cnbr c);
void burningship(t_varlist *vl, int x, int y, t_cnbr c);
void tricorn(t_varlist *vl, int x, int y, t_cnbr c);
void rorschach(t_varlist *vl, int x, int y, t_cnbr c);
void powerflower(t_varlist *vl, int x, int y, t_cnbr c);
#endif #endif

View File

@ -1,135 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* colors.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 07:43:28 by houtworm #+# #+# */
/* Updated: 2022/12/26 01:37:41 by houtworm ### ########.fr */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void rainbowscale2(t_varlist *vl, int r, int g, int b)
{
while (g - vl->cscale + 1 >= 0)
{
g = g - vl->cscale + 1;
vl->colors[vl->csha] = (r << 24 | g << 16 | b << 8 | 255);
vl->csha++;
}
while (r + vl->cscale - 1 <= 255)
{
r = r + vl->cscale - 1;
vl->colors[vl->csha] = (r << 24 | g << 16 | b << 8 | 255);
vl->csha++;
}
while (b - vl->cscale + 1 >= 0)
{
b = b - vl->cscale + 1;
vl->colors[vl->csha] = (r << 24 | g << 16 | b << 8 | 255);
vl->csha++;
}
}
void rainbowscale(t_varlist *vl, int r, int g, int b)
{
while (g + vl->cscale - 1 <= 255)
{
g = g + vl->cscale - 1;
vl->colors[vl->csha] = (r << 24 | g << 16 | b << 8 | 255);
vl->csha++;
}
while (r - vl->cscale + 1 >= 0)
{
r = r - vl->cscale + 1;
vl->colors[vl->csha] = (r << 24 | g << 16 | b << 8 | 255);
vl->csha++;
}
while (b + vl->cscale - 1 <= 255)
{
b = b + vl->cscale - 1;
vl->colors[vl->csha] = (r << 24 | g << 16 | b << 8 | 255);
vl->csha++;
}
rainbowscale2(vl, r, g, b);
}
void rgbscale(t_varlist *vl, int red, int green, int blue)
{
int r;
int g;
int b;
r = 1;
g = 1;
b = 1;
while (r + red <= 255 && g + green <= 255 && b + blue <= 255)
{
r = r + red;
g = g + green;
b = b + blue;
vl->colors[vl->csha] = (r << 24 | g << 16 | b << 8 | 255);
vl->csha++;
}
while (r != 1 || b != 1 || g != 1)
{
r = r - red;
g = g - green;
b = b - blue;
vl->colors[vl->csha] = (r << 24 | g << 16 | b << 8 | 255);
vl->csha++;
}
}
void colorschemestring(t_varlist *vl)
{
vl->cschemeid = vl->cschemeid % 8;
if (vl->cschemeid == 0)
vl->cscheme = "Rainbow";
if (vl->cschemeid == 1)
vl->cscheme = "Red";
if (vl->cschemeid == 2)
vl->cscheme = "Green";
if (vl->cschemeid == 3)
vl->cscheme = "Blue";
if (vl->cschemeid == 4)
vl->cscheme = "Cyan";
if (vl->cschemeid == 5)
vl->cscheme = "Magenta";
if (vl->cschemeid == 6)
vl->cscheme = "Yellow";
if (vl->cschemeid == 7)
vl->cscheme = "Greyscale";
}
void setcolorscheme(t_varlist *vl)
{
int r;
int g;
int b;
r = 255;
g = 0;
b = 0;
vl->csha = 0;
colorschemestring(vl);
if (vl->cschemeid == 0)
rainbowscale(vl, r, g, b);
else if (vl->cschemeid == 1)
rgbscale(vl, vl->cscale, 0, 0);
else if (vl->cschemeid == 2)
rgbscale(vl, 0, vl->cscale, 0);
else if (vl->cschemeid == 3)
rgbscale(vl, 0, 0, vl->cscale);
else if (vl->cschemeid == 4)
rgbscale(vl, 0, vl->cscale, vl->cscale);
else if (vl->cschemeid == 5)
rgbscale(vl, vl->cscale, 0, vl->cscale);
else if (vl->cschemeid == 6)
rgbscale(vl, vl->cscale, vl->cscale, 0);
else if (vl->cschemeid == 7)
rgbscale(vl, vl->cscale, vl->cscale, vl->cscale);
}

View File

@ -1,41 +0,0 @@
/* ************************************************************************** */
/* */
/* .--. _ */
/* error.c |o_o || | */
/* |:_/ || |_ _ ___ __ */
/* By: djonker <djonker@student.codam.nl> // \ \ __| | | \ \/ / */
/* (| | )|_| |_| |> < */
/* Created: 2022/12/29 03:26:26 by djonker /'\_ _/`\__|\__,_/_/\_\ */
/* Updated: 2022/12/29 06:23:51 by djonker \___)=(___/ */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void ft_error(int r)
{
if (r == 1)
ft_putstr_fd("mlx is not happy\n", 2);
if (r == 3)
ft_putstr_fd("pthread error\n", 2);
else if (r == 2)
{
ft_putstr_fd("No or Incorrect parameters\n", 1);
ft_putstr_fd("\nUsage:\n./fract-ol FRACTAL_NAME [ITERATIONS] ", 1);
ft_putstr_fd("[COLORSCHEME]\n", 1);
ft_putstr_fd("\nExamples:\n./fract-ol mandelbrot\n./fract-ol ", 1);
ft_putstr_fd("julia 200\n./fract-ol burningship 300 1\n", 1);
ft_putstr_fd("\nOptions:\nmandelbrot\nmandelcloud\n", 1);
ft_putstr_fd("mandelfeather\nmandelpower\njulia\nburningship\n", 1);
ft_putstr_fd("tricorn\nrorschach\npowerflower\n", 1);
ft_putstr_fd("\nHotkeys:\nKey\t\tAction\nH\t\tShow Help\nScroll\t", 1);
ft_putstr_fd("\tZoom\nArrows\t\tMove\nA/Z\t\t+/- Iterations\n", 1);
ft_putstr_fd("S\t\tShift Colors by 1\nX\t\tNext Colorscheme\n", 1);
ft_putstr_fd("D/C\t\t+/- Colorshades\nI\t\tShow info\nP\t\t", 1);
ft_putstr_fd("Psychedelic Mode\nR\t\tReset Fractal\n1 - 9\t\t", 1);
ft_putstr_fd("Select Fractal\nF/V\t\tChange C value on X axis\n", 1);
ft_putstr_fd("G/B\t\tChange C value on Y axis\nClick\t\tSet C ", 1);
ft_putstr_fd("value on X and Y axis\nN\t\tIncrease Power by 1\n", 1);
}
exit(EXIT_FAILURE);
}

View File

@ -1,129 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractal.c |o_o || | */
/* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 08:03:26 by houtworm #+# #+# */
/* Updated: 2023/03/09 09:55:01 by djonker \___)=(___/ */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void setfractalname(t_varlist *vl)
{
if (vl->fractalid == 1)
vl->fractal = "mandelbrot";
else if (vl->fractalid == 2)
vl->fractal = "mandelcloud";
else if (vl->fractalid == 3)
vl->fractal = "mandelfeather";
else if (vl->fractalid == 4)
vl->fractal = "julia";
else if (vl->fractalid == 5)
vl->fractal = "mandelpower";
else if (vl->fractalid == 6)
vl->fractal = "burningship";
else if (vl->fractalid == 7)
vl->fractal = "tricorn";
else if (vl->fractalid == 8)
vl->fractal = "rorschach";
else if (vl->fractalid == 11)
vl->fractal = "powerflower";
}
void selectfractal(t_varlist *vl, int x, int y, t_cnbr c)
{
setfractalname(vl);
if (vl->fractalid == 1)
mandelbrot(vl, x, y, c);
else if (vl->fractalid == 2)
mandelcloud(vl, x, y, c);
else if (vl->fractalid == 3)
mandelfeather(vl, x, y, c);
else if (vl->fractalid == 4)
julia(vl, x, y, c);
else if (vl->fractalid == 5)
mandelpower(vl, x, y, c);
else if (vl->fractalid == 6)
burningship(vl, x, y, c);
else if (vl->fractalid == 7)
tricorn(vl, x, y, c);
else if (vl->fractalid == 8)
rorschach(vl, x, y, c);
else if (vl->fractalid == 9)
powerflower(vl, x, y, c);
else
ft_error(2);
}
void fractal(t_varlist *vl)
{
int y;
int x;
t_cnbr c;
y = 1;
while (vl->h > y)
{
x = 1;
while (vl->w > x)
{
c.re = vl->xmin + (long double)x * (vl->xmax - vl->xmin) / vl->w;
c.im = vl->ymin + (long double)y * (vl->ymax - vl->ymin) / vl->h;
selectfractal(vl, x, y, c);
x++;
}
y++;
}
}
void redrawimage(t_varlist *vl)
{
vl->redraw = 0;
while (vl->fontnbr > 0)
{
mlx_delete_image(vl->mlx, vl->font[vl->fontnbr - 1]);
vl->fontnbr--;
}
mlx_delete_image(vl->mlx, vl->img);
vl->calc = 0;
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
fractal(vl);
if (!vl->img || (mlx_image_to_window(vl->mlx, vl->img, 0, 0) < 0))
ft_error(1);
if (vl->info % 2)
showinfo(vl);
if (vl->help % 2)
showhelp(vl);
}
void resetfractal(t_varlist *vl)
{
vl->xmin = -4;
vl->ymin = -4;
vl->xmax = 4;
vl->ymax = 4;
if (vl->w > vl->h)
{
vl->ymax = vl->ymin + (vl->xmax - vl->xmin) * vl->h / vl->w;
vl->ymin = vl->ymin + (vl->w / vl->h);
vl->ymax = vl->ymax + (vl->w / vl->h);
}
if (vl->w < vl->h)
{
vl->xmax = vl->xmin + (vl->ymax - vl->ymin) * vl->w / vl->h;
vl->xmin = vl->xmin + (vl->h / vl->w);
vl->xmax = vl->xmax + (vl->h / vl->w);
}
vl->psycho = 0;
vl->cshi = 0;
vl->iter = 128;
vl->xscale = 8;
vl->yscale = 8;
vl->julre = 0;
vl->julim = 0;
vl->power = 1;
}

View File

@ -1,124 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractals1.c |o_o || | */
/* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 08:03:09 by houtworm #+# #+# */
/* Updated: 2022/12/29 06:51:10 by djonker \___)=(___/ */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void mandelfeather(t_varlist *vl, int x, int y, t_cnbr c)
{
t_cnbr z;
t_cnbr t;
int i;
i = 0;
z = c;
while (vl->iter > i && ((z.re < 2 && z.re > -2) || (z.im < 2 && z.im > -2)))
{
t.re = z.re * z.re - z.im * z.im + c.re;
t.im = 2 * z.im * z.re + c.im;
z = t;
i++;
}
if (vl->iter == i)
mlx_put_pixel(vl->img, x, y, 0x000000FF);
else
mlx_put_pixel(vl->img, x, y, vl->colors[(i + vl->cshi) % vl->csha]);
}
void mandelcloud(t_varlist *vl, int x, int y, t_cnbr c)
{
t_cnbr z;
t_cnbr t;
int i;
i = 0;
z = c;
while (vl->iter > i && ((z.re < 2 && z.re > -2) && (z.im < 2 && z.im > -2)))
{
t.re = z.re * z.re - z.im * z.im + c.re;
t.im = 2 * z.im * z.re + c.im;
z = t;
i++;
}
if (vl->iter == i)
mlx_put_pixel(vl->img, x, y, 0x000000FF);
else
mlx_put_pixel(vl->img, x, y, vl->colors[(i + vl->cshi) % vl->csha]);
}
void mandelbrot(t_varlist *vl, int x, int y, t_cnbr c)
{
t_cnbr z;
t_cnbr t;
int i;
i = 0;
z = c;
while (vl->iter > i && (z.re * z.re + z.im * z.im < 100))
{
t.re = z.re * z.re - z.im * z.im + c.re;
t.im = 2 * z.im * z.re + c.im;
z = t;
i++;
vl->calc++;
}
vl->calc++;
if (vl->iter == i)
mlx_put_pixel(vl->img, x, y, 0x000000FF);
else
mlx_put_pixel(vl->img, x, y, vl->colors[(i + vl->cshi) % vl->csha]);
}
void julia(t_varlist *vl, int x, int y, t_cnbr z)
{
t_cnbr t;
int i;
i = 0;
while (vl->iter > i && (z.re * z.re + z.im * z.im < 100))
{
t.re = z.re * z.re - z.im * z.im;
z.im = 2 * z.im * z.re + vl->julim;
z.re = t.re + vl->julre;
i++;
vl->calc++;
}
vl->calc++;
if (vl->iter == i)
mlx_put_pixel(vl->img, x, y, 0x000000FF);
else
mlx_put_pixel(vl->img, x, y, vl->colors[(i + vl->cshi) % vl->csha]);
}
void burningship(t_varlist *vl, int x, int y, t_cnbr c)
{
t_cnbr t;
t_cnbr z;
int i;
i = 0;
z = c;
while (vl->iter > i && (z.re * z.re + z.im * z.im < 100))
{
t.re = z.re * z.re - z.im * z.im + c.re;
t.im = fabs(2 * (double)z.im * (double)z.re) + c.im;
if (t.im < 0)
t.im = t.im * -1;
z = t;
i++;
vl->calc++;
}
vl->calc++;
if (vl->iter == i)
mlx_put_pixel(vl->img, x, y, 0x000000FF);
else
mlx_put_pixel(vl->img, x, y, vl->colors[(i + vl->cshi) % vl->csha]);
}

View File

@ -1,113 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractals2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/26 22:05:33 by houtworm #+# #+# */
/* Updated: 2022/12/29 18:38:12 by houtworm ### ########.fr */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void mandelpower(t_varlist *vl, int x, int y, t_cnbr c)
{
t_cnbr z;
t_cnbr t;
t_cnbr r;
int i;
i = 0;
z = c;
while (vl->iter > i && (z.re * z.re + z.im * z.im < 100))
{
r.re = sqrt(z.re * z.re + z.im * z.im);
r.im = atan2(z.im, z.re);
r.re = powl(r.re, vl->power);
r.im = vl->power * r.im;
t.re = r.re * cos(r.im) + c.re;
t.im = r.re * sin(r.im) + c.im;
z = t;
i++;
vl->calc++;
}
vl->calc++;
if (vl->iter == i)
mlx_put_pixel(vl->img, x, y, 0x000000FF);
else
mlx_put_pixel(vl->img, x, y, vl->colors[(i + vl->cshi) % vl->csha]);
}
void tricorn(t_varlist *vl, int x, int y, t_cnbr c)
{
t_cnbr z;
t_cnbr t;
int i;
i = 0;
z = c;
while (vl->iter > i && (z.re * z.re + z.im * z.im < 100))
{
t.re = z.re * z.re - z.im * z.im + c.re;
t.im = -2 * z.re * z.im + c.im;
z = t;
i++;
vl->calc++;
}
vl->calc++;
if (vl->iter == i)
mlx_put_pixel(vl->img, x, y, 0x000000FF);
else
mlx_put_pixel(vl->img, x, y, vl->colors[(i + vl->cshi) % vl->csha]);
}
void rorschach(t_varlist *vl, int x, int y, t_cnbr c)
{
t_cnbr z;
t_cnbr t;
int i;
i = 0;
z = c;
while (vl->iter > i && (z.re * z.re + z.im * z.im < 100))
{
t.re = fabsl(z.re);
z.re = z.re * z.re - z.im * z.im - c.re;
z.im = 2 * z.im * t.re - c.im;
i++;
vl->calc++;
}
vl->calc++;
if (vl->iter == i)
mlx_put_pixel(vl->img, x, y, 0x000000FF);
else
mlx_put_pixel(vl->img, x, y, vl->colors[(i + vl->cshi) % vl->csha]);
}
void powerflower(t_varlist *vl, int x, int y, t_cnbr z)
{
t_cnbr t;
t_cnbr r;
int i;
i = 0;
while (vl->iter > i && (z.re * z.re + z.im * z.im < 100))
{
r.re = sqrt(z.re * z.re + z.im * z.im);
r.im = atan2(z.im, z.re);
r.re = powl(r.re, vl->power);
r.im = vl->power * r.im;
t.re = (r.re + vl->julre) * cos(r.im);
t.im = (r.re + vl->julim) * sin(r.im);
z = t;
i++;
vl->calc++;
}
vl->calc++;
if (vl->iter == i)
mlx_put_pixel(vl->img, x, y, 0x000000FF);
else
mlx_put_pixel(vl->img, x, y, vl->colors[(i + vl->cshi) % vl->csha]);
}

View File

@ -1,146 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* keyhooks.c |o_o || | */
/* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 08:32:24 by houtworm #+# #+# */
/* Updated: 2022/12/29 03:51:56 by djonker \___)=(___/ */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void keyhookmove(void *param)
{
t_varlist *vl;
vl = param;
if (mlx_is_key_down(vl->mlx, MLX_KEY_LEFT) && vl->xmin > -32)
{
justmove(vl, 'l');
vl->redraw = 1;
}
if (mlx_is_key_down(vl->mlx, MLX_KEY_RIGHT) && vl->xmax < 32)
{
justmove(vl, 'r');
vl->redraw = 1;
}
if (mlx_is_key_down(vl->mlx, MLX_KEY_UP) && vl->ymin > -32)
{
justmove(vl, 'u');
vl->redraw = 1;
}
if (mlx_is_key_down(vl->mlx, MLX_KEY_DOWN) && vl->ymax < 32)
{
justmove(vl, 'd');
vl->redraw = 1;
}
}
void keyhook(mlx_key_data_t kd, void *param)
{
t_varlist *vl;
vl = param;
if (kd.key == MLX_KEY_S && kd.action == MLX_PRESS)
vl->cshi++;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_R))
resetfractal(vl);
else if (kd.key == MLX_KEY_P && kd.action == MLX_PRESS)
vl->psycho++;
else if (kd.key == MLX_KEY_I && kd.action == MLX_PRESS)
vl->info++;
else if (kd.key == MLX_KEY_H && kd.action == MLX_PRESS)
vl->help++;
else if (kd.key == MLX_KEY_X && kd.action == MLX_PRESS)
vl->cschemeid++;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_N))
vl->power = vl->power + 1;
else if (kd.key == MLX_KEY_C && kd.action == MLX_PRESS && vl->cscale != 128)
vl->cscale = (vl->cscale) * 2;
else if (kd.key == MLX_KEY_D && kd.action == MLX_PRESS && vl->cscale != 2)
vl->cscale = (vl->cscale) / 2;
else
return ;
setcolorscheme(vl);
redrawimage(vl);
}
void resizehook(int x, int y, void *param)
{
t_varlist *vl;
vl = param;
vl->h = y;
vl->w = x;
vl->mlx->height = y;
vl->mlx->width = x;
if (vl->w > vl->h)
{
vl->xmax = vl->xmin + (vl->ymax - vl->ymin) * vl->w / vl->h;
}
else
{
vl->ymax = vl->ymin + (vl->xmax - vl->xmin) * vl->h / vl->w;
}
redrawimage(vl);
}
void keyhookfractal(void *param)
{
t_varlist *vl;
vl = param;
if (mlx_is_key_down(vl->mlx, MLX_KEY_1))
vl->fractalid = 1;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_2))
vl->fractalid = 2;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_3))
vl->fractalid = 3;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_4))
vl->fractalid = 4;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_5))
vl->fractalid = 5;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_6))
vl->fractalid = 6;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_7))
vl->fractalid = 7;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_8))
vl->fractalid = 8;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_9))
vl->fractalid = 9;
else
return ;
redrawimage(vl);
}
void keyhookextra(void *param)
{
t_varlist *vl;
vl = param;
if (mlx_is_key_down(vl->mlx, MLX_KEY_ESCAPE))
{
mlx_close_window(vl->mlx);
return ;
}
else if (mlx_is_key_down(vl->mlx, MLX_KEY_A))
vl->iter++;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_Z) && vl->iter > 0)
vl->iter--;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_F) && vl->julre < 4)
vl->julre = vl->julre + 0.01;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_V) && vl->julre > -4)
vl->julre = vl->julre - 0.01;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_G) && vl->julim < 4)
vl->julim = vl->julim + 0.01;
else if (mlx_is_key_down(vl->mlx, MLX_KEY_B) && vl->julim > -4)
vl->julim = vl->julim - 0.01;
else if (vl->psycho % 2)
vl->cshi++;
else if (vl->redraw == 0)
return ;
redrawimage(vl);
}

View File

@ -1,116 +1,43 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* main.c |o_o || | */ /* main.c :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */ /* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 08:03:00 by houtworm #+# #+# */ /* Created: 2022/12/13 08:03:00 by houtworm #+# #+# */
/* Updated: 2022/12/29 06:35:31 by djonker \___)=(___/ */ /* Updated: 2023/10/26 10:44:41 by houtworm ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../fractol.h" #include "../cub3d.h"
int charactercheck(char *argument) t_varlist initvarlist(void)
{
int i;
i = 0;
while (argument[i] != '\0')
{
if (argument[i] < '0' || argument[i] > '9')
return (1);
i++;
if (i > 7)
return (1);
}
return (0);
}
void parseargs2(t_varlist *vl, char **argv)
{
if (argv[2] != NULL)
{
if (charactercheck(argv[2]))
ft_error(2);
else
vl->iter = ft_atol(argv[2]);
if (argv[3] != NULL)
{
if (charactercheck(argv[3]))
ft_error(2);
else
vl->cschemeid = ft_atol(argv[3]);
}
}
}
void parseargs(t_varlist *vl, char **argv)
{
if (ft_strncmp("mandelbrot", vl->fractal, 10) == 0)
vl->fractalid = 1;
if (ft_strncmp("mandelcloud", vl->fractal, 11) == 0)
vl->fractalid = 2;
if (ft_strncmp("mandelfeather", vl->fractal, 13) == 0)
vl->fractalid = 3;
if (ft_strncmp("julia", vl->fractal, 5) == 0)
vl->fractalid = 4;
if (ft_strncmp("mandelpower", vl->fractal, 11) == 0)
vl->fractalid = 5;
if (ft_strncmp("burningship", vl->fractal, 11) == 0)
vl->fractalid = 6;
if (ft_strncmp("tricorn", vl->fractal, 7) == 0)
vl->fractalid = 7;
if (ft_strncmp("rorschach", vl->fractal, 9) == 0)
vl->fractalid = 8;
if (ft_strncmp("powerjulia", vl->fractal, 10) == 0)
vl->fractalid = 9;
parseargs2(vl, argv);
}
t_varlist initvarlist(char **argv)
{ {
t_varlist vl; t_varlist vl;
char *title;
vl.fontnbr = 0;
vl.w = 600; vl.w = 600;
vl.h = 600; vl.h = 600;
vl.cschemeid = 0; vl.mlx = mlx_init(vl.w, vl.h, "Cub3D", true);
vl.fractal = argv[1];
resetfractal(&vl);
parseargs(&vl, argv);
title = "Fractol - ";
title = ft_strjoin(title, argv[1]);
vl.mlx = mlx_init(vl.w, vl.h, title, true);
if (!vl.mlx) if (!vl.mlx)
ft_error(1); exit(1);
vl.img = mlx_new_image(vl.mlx, vl.w, vl.h); vl.img = mlx_new_image(vl.mlx, vl.w, vl.h);
vl.cscale = 16;
free (title);
return (vl); return (vl);
} }
int32_t main(int argc, char **argv) void redrawimage(t_varlist *vl)
{
mlx_delete_image(vl->mlx, vl->img);
vl->img = mlx_new_image(vl->mlx, vl->w, vl->h);
}
int32_t main(void)
{ {
t_varlist vl; t_varlist vl;
if (argc > 4 || argc < 2) vl = initvarlist();
ft_error(2);
vl = initvarlist(argv);
setcolorscheme(&vl);
fractal(&vl);
if (!vl.img || (mlx_image_to_window(vl.mlx, vl.img, 0, 0) < 0)) if (!vl.img || (mlx_image_to_window(vl.mlx, vl.img, 0, 0) < 0))
ft_error(1); exit (1);
showhelp(&vl);
mlx_key_hook(vl.mlx, &keyhook, &vl);
mlx_scroll_hook(vl.mlx, &scrollhook, &vl);
mlx_resize_hook(vl.mlx, &resizehook, &vl);
mlx_loop_hook(vl.mlx, &mousehook, &vl);
mlx_loop_hook(vl.mlx, &keyhookmove, &vl);
mlx_loop_hook(vl.mlx, &keyhookextra, &vl);
mlx_loop_hook(vl.mlx, &keyhookfractal, &vl);
mlx_loop(vl.mlx); mlx_loop(vl.mlx);
mlx_delete_image(vl.mlx, vl.img); mlx_delete_image(vl.mlx, vl.img);
mlx_terminate(vl.mlx); mlx_terminate(vl.mlx);

View File

@ -1,44 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mousehooks.c |o_o || | */
/* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/25 10:29:26 by houtworm #+# #+# */
/* Updated: 2022/12/29 00:02:44 by djonker \___)=(___/ */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void scrollhook(double xdelta, double ydelta, void *param)
{
t_varlist *vl;
vl = param;
xdelta++;
if (ydelta > 0)
if (vl->xscale > 0.00000000000000001)
if (vl->yscale > 0.00000000000000001)
zoomtomouse(vl);
if (ydelta < 0 && vl->xscale < 32)
zoomfrommouse(vl);
redrawimage(vl);
}
void mousehook(void *param)
{
t_varlist *vl;
int32_t x;
int32_t y;
vl = param;
if (mlx_is_mouse_down(vl->mlx, MLX_MOUSE_BUTTON_LEFT))
{
mlx_get_mouse_pos(vl->mlx, &x, &y);
vl->julre = vl->xmin + (long double)x * (vl->xmax - vl->xmin) / vl->w;
vl->julim = vl->ymin + (long double)y * (vl->ymax - vl->ymin) / vl->h;
vl->redraw = 1;
}
}

View File

@ -1,124 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print.c |o_o || | */
/* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 08:03:05 by houtworm #+# #+# */
/* Updated: 2022/12/29 06:15:16 by djonker \___)=(___/ */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void freeprint(t_varlist *vl, char *s, int y, int f)
{
vl->fontnbr++;
vl->font[vl->fontnbr - 1] = mlx_put_string(vl->mlx, s, 10, y);
if (f == 1)
free(s);
}
void showinfo3(t_varlist *vl, char *temp, char *print)
{
if (vl->fractalid == 4 || vl->fractalid == 9)
{
temp = ft_lftoa(vl->julre);
print = ft_strjoin("CX value: ", temp);
freeprint(vl, print, 190, 1);
free(temp);
temp = ft_lftoa(vl->julim);
print = ft_strjoin("CY value: ", temp);
freeprint(vl, print, 210, 1);
free(temp);
}
if (vl->fractalid == 5)
{
temp = ft_itoa(vl->power);
print = ft_strjoin("Power: ", temp);
freeprint(vl, print, 190, 1);
free(temp);
}
if (vl->fractalid == 9)
{
temp = ft_itoa(vl->power);
print = ft_strjoin("Power: ", temp);
freeprint(vl, print, 230, 1);
free(temp);
}
}
void showinfo2(t_varlist *vl, char *temp, char *print)
{
temp = ft_itoa(vl->csha);
if (vl->cschemeid == 0)
print = ft_strjoin("Colors: ", temp);
if (vl->cschemeid > 0)
print = ft_strjoin("Shades: ", temp);
freeprint(vl, print, 110, 1);
free(temp);
temp = ft_itoa(vl->w);
print = ft_strjoin("Width: ", temp);
freeprint(vl, print, 130, 1);
free(temp);
temp = ft_itoa(vl->h);
print = ft_strjoin("Height: ", temp);
freeprint(vl, print, 150, 1);
free(temp);
print = ft_strjoin("Fractal: ", vl->fractal);
freeprint(vl, print, 170, 1);
showinfo3(vl, "empty", "empty");
}
void showinfo(t_varlist *vl)
{
char *print;
char *temp;
temp = ft_lftoa(vl->xscale);
print = ft_strjoin("X Scale: ", temp);
freeprint(vl, print, 10, 1);
free(temp);
temp = ft_lftoa(vl->yscale);
print = ft_strjoin("Y Scale: ", temp);
freeprint(vl, print, 30, 1);
free(temp);
temp = ft_ltoa(vl->calc);
print = ft_strjoin("Calculations: ", temp);
freeprint(vl, print, 50, 1);
free(temp);
temp = ft_itoa(vl->iter);
print = ft_strjoin("Iterations: ", temp);
freeprint(vl, print, 70, 1);
free(temp);
print = ft_strjoin("Scheme: ", vl->cscheme);
freeprint(vl, print, 90, 1);
showinfo2(vl, "empty", "empty");
}
void showhelp(t_varlist *vl)
{
if (vl->fractalid == 4 || vl->fractalid == 9)
{
freeprint(vl, "F/V +/- C on the X axis", vl->h - 310, 0);
freeprint(vl, "G/B +/- C on the Y axis", vl->h - 290, 0);
freeprint(vl, "Click Set C on the X and Y axis", vl->h - 270, 0);
}
if (vl->fractalid == 5)
freeprint(vl, "N Increase Power by 1", vl->h - 270, 0);
if (vl->fractalid == 9)
freeprint(vl, "N Increase Power by 1", vl->h - 330, 0);
freeprint(vl, "Scroll Zoom in/out", vl->h - 250, 0);
freeprint(vl, "Arrows Move Around", vl->h - 230, 0);
freeprint(vl, "A/Z +/- Iterations", vl->h - 210, 0);
freeprint(vl, "X Next Color Scheme", vl->h - 190, 0);
freeprint(vl, "S Shift Colors by 1", vl->h - 170, 0);
freeprint(vl, "D/C Change Colorscale", vl->h - 150, 0);
freeprint(vl, "P Psychedelic Mode", vl->h - 130, 0);
freeprint(vl, "H Show Help Screen", vl->h - 110, 0);
freeprint(vl, "I Show Info Screen", vl->h - 90, 0);
freeprint(vl, "1 - 9 Select Fractal", vl->h - 70, 0);
freeprint(vl, "R Reset Fractal", vl->h - 50, 0);
freeprint(vl, "Esc Quit Program", vl->h - 30, 0);
}

View File

@ -1,131 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zoommove.c |o_o || | */
/* +:+ +:+ +:+ */
/* By: houtworm <codam@houtworm.net> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/25 11:14:13 by houtworm #+# #+# */
/* Updated: 2023/03/09 20:30:01 by djonker \___)=(___/ */
/* */
/* ************************************************************************** */
#include "../fractol.h"
void justmove(t_varlist *vl, char dir)
{
if (dir == 'l')
{
vl->xmin = vl->xmin + vl->xscale * -1 / 100;
vl->xmax = vl->xmax + vl->xscale * -1 / 100;
}
if (dir == 'r')
{
vl->xmin = vl->xmin - vl->xscale * -1 / 100;
vl->xmax = vl->xmax - vl->xscale * -1 / 100;
}
if (dir == 'u')
{
vl->ymin = vl->ymin + vl->yscale * -1 / 100;
vl->ymax = vl->ymax + vl->yscale * -1 / 100;
}
if (dir == 'd')
{
vl->ymin = vl->ymin - vl->yscale * -1 / 100;
vl->ymax = vl->ymax - vl->yscale * -1 / 100;
}
}
void moveout(t_varlist *vl, long double zoomx, long double zoomy)
{
if (vl->xcur < 0)
{
vl->xmin = vl->xmin + zoomx * ((long double)vl->xcur * -1 / vl->w);
vl->xmax = vl->xmax + zoomx * ((long double)vl->xcur * -1 / vl->w);
}
else
{
vl->xmin = vl->xmin - zoomx * ((long double)vl->xcur / vl->w);
vl->xmax = vl->xmax - zoomx * ((long double)vl->xcur / vl->w);
}
if (vl->ycur < 0)
{
vl->ymin = vl->ymin + zoomy * ((long double)vl->ycur * -1 / vl->w);
vl->ymax = vl->ymax + zoomy * ((long double)vl->ycur * -1 / vl->w);
}
else
{
vl->ymin = vl->ymin - zoomy * ((long double)vl->ycur / vl->w);
vl->ymax = vl->ymax - zoomy * ((long double)vl->ycur / vl->w);
}
}
void movein(t_varlist *vl, long double zoomx, long double zoomy)
{
if (vl->xcur < 0)
{
vl->xmin = vl->xmin - zoomx * ((long double)vl->xcur * -1 / vl->w);
vl->xmax = vl->xmax - zoomx * ((long double)vl->xcur * -1 / vl->w);
}
else
{
vl->xmin = vl->xmin + zoomx * ((long double)vl->xcur / vl->w);
vl->xmax = vl->xmax + zoomx * ((long double)vl->xcur / vl->w);
}
if (vl->ycur < 0)
{
vl->ymin = vl->ymin - zoomy * ((long double)vl->ycur * -1 / vl->w);
vl->ymax = vl->ymax - zoomy * ((long double)vl->ycur * -1 / vl->w);
}
else
{
vl->ymin = vl->ymin + zoomy * ((long double)vl->ycur / vl->w);
vl->ymax = vl->ymax + zoomy * ((long double)vl->ycur / vl->w);
}
}
void zoomtomouse(t_varlist *vl)
{
long double zoomx;
long double zoomy;
vl->xscale = vl->xmin - vl->xmax;
vl->yscale = vl->ymax - vl->ymin;
zoomx = 0.9 * vl->xscale;
zoomy = 0.9 * vl->yscale;
vl->xmax = vl->xmax + (vl->xscale - zoomx) / 2;
vl->xmin = vl->xmax + zoomx;
vl->ymin = vl->ymin + (vl->yscale - zoomy) / 2;
vl->ymax = vl->ymin + zoomy;
mlx_get_mouse_pos(vl->mlx, &vl->xcur, &vl->ycur);
vl->xcur = vl->xcur - (vl->w / 2);
vl->ycur = vl->ycur - (vl->h / 2);
vl->xscale = vl->xmax - vl->xmin;
vl->yscale = vl->ymax - vl->ymin;
zoomx = 0.1111111111111111111111111111111111111111 * vl->xscale;
zoomy = 0.1111111111111111111111111111111111111111 * vl->yscale;
movein(vl, zoomx, zoomy);
}
void zoomfrommouse(t_varlist *vl)
{
long double zoomx;
long double zoomy;
vl->xscale = vl->xmin - vl->xmax;
vl->yscale = vl->ymax - vl->ymin;
zoomx = 1.1 * vl->xscale;
zoomy = 1.1 * vl->yscale;
vl->xmax = vl->xmax + (vl->xscale - zoomx) / 2;
vl->xmin = vl->xmax + zoomx;
vl->ymin = vl->ymin + (vl->yscale - zoomy) / 2;
vl->ymax = vl->ymin + zoomy;
mlx_get_mouse_pos(vl->mlx, &vl->xcur, &vl->ycur);
vl->xcur = vl->xcur - vl->w / 2;
vl->ycur = vl->ycur - vl->h / 2;
vl->xscale = vl->xmax - vl->xmin;
vl->yscale = vl->ymax - vl->ymin;
zoomx = 0.0909090909090909090909090909090909090909 * vl->xscale;
zoomy = 0.0909090909090909090909090909090909090909 * vl->yscale;
moveout(vl, zoomx, zoomy);
}