Skip to content

Instantly share code, notes, and snippets.

@ExtReMLapin
Created February 15, 2016 13:48
Show Gist options
  • Save ExtReMLapin/8d3a2dcedde62018b300 to your computer and use it in GitHub Desktop.
Save ExtReMLapin/8d3a2dcedde62018b300 to your computer and use it in GitHub Desktop.
plasma minilibx
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pfichepo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/11 17:07:38 by pfichepo #+# #+# */
/* Updated: 2016/01/11 17:07:41 by pfichepo ### ########.fr */
/* */
/* ************************************************************************** */
#include <time.h>
#include "include/fdf.h"
#include "minilibx_macos/mlx.h"
int pixel_size = 1;
int t;
static float hypt(float a,float b)
{
return sqrt(pow(a,2)+ pow(b,2));
}
static int plasma(float x,float y,float w,float h,float t)
{
float tx = sin(t*1.3)*100;
float ty = cos(t*0.8)*120;
float px = x/300;
float py = y/100;
float pass1 = (90 + 89 * ( sin( hypt( w/2-x+ty, h/2-y+tx )/64 + t) ));
float pass2 = (90 + 89 * sin(px*cos(py+tx/100)+t)*sin(py*cos(px+ty/100)+t));
return pass1+pass2;
}
static void drawmap(t_env *env)
{
int x = 0;
int y = 0;
int w = 1600;
int h = 900;
int tmp;
int color;
t = clock();
while (x < w)
{
y = 0;
while (y < h)
{
tmp = plasma(x,y,w,h,t)-1;
color = createRGB(tmp, tmp, tmp);
drawbox(x, y, pixel_size, pixel_size, color, env);
y = y + pixel_size;
}
x = x + pixel_size;
}
return;
t_point *dickbutt;
dickbutt = env->grid;
while (dickbutt != NULL)
{
//mlx_pixel_put(env->mlx, env->win, dickbutt->x * env->zoom, dickbutt->y * env->zoom, createRGB(dickbutt->z * 10,dickbutt->z * 10,dickbutt->z * 10));
drawbox(dickbutt->x * env->zoom, dickbutt->y * env->zoom, env->zoom, env->zoom, createRGB(dickbutt->z * 10,dickbutt->z * 10,dickbutt->z * 10), env);
dickbutt = dickbutt->next;
}
}
static int draw(t_env *env)
{
if (!env->mlx)
error("MLX IS NULL");
mlx_clear_window(env->mlx, env->win);
ft_putstr("Cleared\n");
drawmap(env);
t_point *pt = (t_point*)(malloc(sizeof(t_point)));
pt->y_2d = 20;
pt->x_2d = 20;
t_point *pt2 = (t_point*)(malloc(sizeof(t_point)));
pt2->y_2d = 50;
pt2->x_2d = 2000;
//ft_drawline(env, pt2, pt);
return (1);
}
static void initenv(t_env *env, char *file)
{
env->zoom = 50;
env->w = 1600;
env->h = 900;
env->mlx = mlx_init();
env->win = mlx_new_window(env->mlx, env->w, env->h, "FdF");
env->img = mlx_new_image(env->mlx, env->w, env->h);
char **tbl =file_totbl(file) ;
tbl = cleartbl(tbl);
int **itbl = charrtointt(tbl);
reallocint(itbl);
t_point *pts = chrrtocor(itbl);
env->grid = pts;
}
int main(int agc, char** argc)
{
t_env *env;
if (agc != 2)
error("only one argument is allowed");
env = (t_env *)malloc(sizeof(t_env));
initenv(env, argc[1]);
ft_putstr("Inited\n");
mlx_expose_hook(env->win, draw, env);
mlx_loop(env->mlx);
exit(1);
return (1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment