void one_game() { int i, players_moved; board = calloc(HEIGHT*(WIDTH-MENU_WIDTH), sizeof(short)); for(i = 0; i<l; i++) { p[i].dir = (rand()%4) * 90; p[i].x = rand()%(W - 40) + 20; p[i].y = rand()%(HEIGHT - 40) + 20; p[i].playing = 1; color_pixel(p[i].x, p[i].y, i); } update_window(); SDL_Delay(1000); do { players_moved = 0; for(i = 0; i<l; i++) { move(&p[i], i, &players_moved); } SDL_Delay(10); update_window(); } while(end == 0 && players_moved>1); free(board); }
int triangle(t_all *all) { int nb; if (AH->init_fractal) init_first_triangle(all); init_triangle(all); while (++(AF->iter) <= AF->iter_max) { color_pixel(all, AF->iter); if ((nb = abs(rand() % 3)) == 0) { AP->x = ((AP->x + AF->x1) / 2.0) + AH->motion; AP->y = ((AP->y + AF->y1) / 2.0) - AH->motion; } else if (nb == 1) { AP->x = ((AP->x + AF->x2) / 2.0) - AH->motion; AP->y = ((AP->y + AF->y2) / 2.0) + AH->motion; } else if (nb == 2) { AP->x = ((AP->x + AF->x3) / 2.0) + AH->motion; AP->y = ((AP->y + AF->y3) / 2.0) - AH->motion; } } return (0); }
int move(struct player *p_current, int i, int *moved) { if(p_current->playing == 0) { return 0; } if(is_killed(p_current->x, p_current->y)) { p_current->playing = 0; add_points(); return 1; } (*moved)++; color_pixel(p_current->x, p_current->y, i); board[p_current->x + Y(p_current->y)] = i + 1; switch(p_current->dir) { case(0): p_current->y--; break; case(90): p_current->x++; break; case(180): p_current->y++; break; case(270): p_current->x--; break; } return 0; }
int julia3(t_all *all) { if (AH->init_fractal) init_fractale(all); AP->x = -1; while (++(AP->x) < IMGW) { AP->y = -1; while (++(AP->y) < IMGH) { init2(all); while (++(AF->iter) < AF->iter_max && (AF->zr * AF->zr + AF->zi * AF->zi) < 4) { AF->t = AF->zr; AF->zr = (AF->zr * AF->zr * AF->zr * AF->zr) - 6 * (AF->zr * AF->zr) * (AF->zi * AF->zi) + (AF->zi * AF->zi * AF->zi * AF->zi) + AF->cr; AF->zi = ((4 * (AF->t * AF->t * AF->t)) * AF->zi) - 4 * AF->t * (AF->zi * AF->zi * AF->zi) + AF->ci; } if (AF->iter != AF->iter_max) color_pixel(all, AF->iter); } } return (0); }
int julia(t_all *all) { if (AH->init_fractal) init_fractale(all); AH->init_fractal = 0; AP->x = -1; while (++(AP->x) < IMGW) { AP->y = -1; while (++(AP->y) < IMGH) { init2(all); while (sqrt(AF->zr * AF->zr + AF->zi * AF->zi) < 4 && ++(AF->iter) < AF->iter_max) { AF->t = AF->zr; AF->zr = (AF->zr * AF->zr - AF->zi * AF->zi + AF->cr); AF->zi = (2 * AF->zi * AF->t + AF->ci); } if (AF->iter != AF->iter_max) color_pixel(all, AF->iter); } } return (0); }
void color_pixel_rgb(int x, int y, u8 r, u8 g, u8 b, u8* screen) { Color hulp; hulp.r = r; hulp.g = g; hulp.b = b; color_pixel(x, y, hulp, screen); }
void draw_square(int x, int y, int width, int height, Color color, u8* screen) { int i, j; for(i = 0; i < width && i >= 0; i++) { for(j = 0; j < height && i >= 0; j++) { color_pixel(x + i, y + j, color, screen); } } }
void display_pixel(t_img *img, int x, int y, t_ray *rayon) { t_data *d; t_vector b; t_vector ray_dir; int color; d = data_init(); vector_set(&b, x - (d->win_size_x / 2), y - (d->win_size_y / 2), 0); vector_set(&ray_dir, b.x - d->cam->x, b.y - d->cam->y, b.z - d->cam->z); vector_normalize(&ray_dir); vector_set(rayon->o, d->cam->x, d->cam->y, d->cam->z); vector_set(rayon->d, ray_dir.x, ray_dir.y, ray_dir.z); vector_normalize(rayon->d); color = color_pixel(rayon, 200000, DEPTH); eb_debug(ft_concat2("couleur du pixel : ", ft_lutohex(color)), 1); eb_put_pixel_to_img(img, x, y, color); }
double mandelbrot(IMAGE *img, int maxiters, REAL x1, REAL x2, REAL y1, REAL y2) { int i,j,count; REAL dx = (x2-x1)/img->nx, dy = (y2-y1)/img->ny; REAL x,y; double flops=0; for (j = 0; j < img->ny; ++j) { for (i = 0; i < img->nx; ++i) { x = x1+dx*i; y = y1+dy*j; count = iterate(x,y,maxiters); color_pixel(img,i,j,count,maxiters); flops += 4+count*8; } } img->cspace=TYPE_HSV; return flops; }
void init_video(void) { char * datas = ((char*) PROGRAM_BASE_ADDR); datas += 100000; datas -= 512; assets = (Game_Assets*)datas; //color_screen(0x3f); // write_string_position(5, "wowowow", 5, 5); // write_string_position(5, hu, 5, 15); // write_string_position(5, katana, 5, 25); draw_bullet(6, 11, 15, 5); draw_player(15, 35); draw_enemy(0, 15, 55); draw_enemy(1, 15, 70); /* TODO: Do any video display initialization you might want to do, such * as clearing the screen, initializing static variable state, etc. */ // Clear Screen - not yet debugged. // clearScreen(); #if 0 //TEST~nico~~ #if 0 write_string_offset(RED, string, 10); #endif // TEST 2~~nico~~~~ color_pixel(RED, 50); color_pixel(BLUE, 52); color_pixel(YELLOW, 54); color_pixel(WHITE, 210); color_pixel(GREEN, 212); color_pixel(CYAN, 214); #endif }
void ppm_read_write_bits (int height, int width, int row_bytes, FILE *fp, uint8 *bits) { int max_cmp_value; uint8 *dst; if (pixmap_p) fscanf (fp, "%d", &max_cmp_value); { int r, b, p; for (dst = bits, r = 0; r < height; r ++) { for (b = 0; b < row_bytes; b ++) { uint8 pixel = 0; for (p = 1 << (3 - log2_bpp); p; p --) { if (pixmap_p) { uint32 red, green, blue; struct splash_screen_color color; fscanf (fp, "%d %d %d", &red, &green, &blue); color.red = CW ((red * 65535) / max_cmp_value); color.green = CW ((green * 65535) / max_cmp_value); color.blue = CW ((blue * 65535) / max_cmp_value); pixel = (pixel << bpp) | color_pixel (&color); } else { int bit; #if 0 /* this didn't work on beaut */ fscanf (fp, "%1d", &bit); #else { int c; do c = fgetc (fp); while (c != EOF && c != '0' && c != '1'); switch (c) { case '0': bit = 0; break; case '1': bit = 1; break; default: abort (); break; } } #endif if (bpp != 1) abort (); switch (bit) { case 0: pixel = pixel << 1; break; case 1: pixel = (pixel << 1) | bit; break; default: abort (); } } } *dst++ = pixel; } } } }
int main (int argc, char *argv[]) { char *paramfile; char splashfile[1024], buttonfile[1024], outfile[1024]; int splashfd, buttonfd, outfd, paramfd; FILE *splashfp, *buttonfp, *paramfp; char buf[1024]; int splash_width, splash_height; int button_width, button_height; struct splash_screen_header header; int splash_row_bytes, button_row_bytes; uint8 *splash_bits, *button_bits; int retval, i; if (argc != 2) { fprintf (stderr, "usage: %s paramfile\n", *argv); exit (-1); } paramfile = argv[1]; paramfd = open (paramfile, O_RDONLY); if (paramfd == -1) errno_fatal ("open %s", paramfile); paramfp = fdopen (paramfd, "r"); if (paramfp == NULL) errno_fatal ("fdopen"); fscanf (paramfp, "splash %s\n", splashfile); fscanf (paramfp, "button %s\n", buttonfile); fscanf (paramfp, "out %s\n", outfile); fprintf (stderr, "\ splash file `%s'\n\ button file `%s'\n\ output file `%s'\n", splashfile, buttonfile, outfile); splashfd = open (splashfile, O_RDONLY); if (splashfd == -1) errno_fatal ("open %s", splashfile); splashfp = fdopen (splashfd, "r"); if (splashfp == NULL) errno_fatal ("fdopen"); buttonfd = open (buttonfile, O_RDONLY); if (buttonfd == -1) errno_fatal ("open %s", buttonfile); buttonfp = fdopen (buttonfd, "r"); if (buttonfp == NULL) errno_fatal ("fdopen"); outfd = open (outfile, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (outfd == -1) errno_fatal ("open %s", outfile); fscanf (paramfp, "bpp %d\n", &bpp); switch (bpp) { case 8: log2_bpp = 3; break; case 4: log2_bpp = 2; break; case 2: log2_bpp = 1; break; case 1: log2_bpp = 0; break; default: abort (); } { int16 n_buttons; fscanf (paramfp, "n_buttons %hd\n", &n_buttons); for (i = 0; i < n_buttons; i ++) { int16 top, left, bottom, right; struct splash_screen_rect *rect; fscanf (paramfp, "rect %hd %hd %hd %hd\n", &top, &left, &bottom, &right); rect = &header.button_rects[i]; rect->top = CW (top); rect->left = CW (left); rect->bottom = CW (bottom); rect->right = CW (right); } header.n_buttons = CW (n_buttons); } init_color_buf (); { uint32 red, green, blue; struct splash_screen_color color; fscanf (paramfp, "bk_color %d %d %d", &red, &green, &blue); color.red = CW (red); color.green = CW (green); color.blue = CW (blue); header.bg_pixel = color_pixel (&color); } fscanf (splashfp, "%s", buf); if (! strcmp (buf, "P3")) pixmap_p = TRUE; else if (! strcmp (buf, "P1")) pixmap_p = FALSE; else { fprintf (stderr, "ppm type must be `P3' or `P1'\n"); exit (-1); } fscanf (splashfp, "%d %d", &splash_width, &splash_height); if (splash_width != SPLASH_SCREEN_WIDTH || splash_height != SPLASH_SCREEN_HEIGHT) { fprintf (stderr, "ppm width and height must be %d and %d, respectively\n", SPLASH_SCREEN_WIDTH, SPLASH_SCREEN_HEIGHT); exit (-1); } splash_row_bytes = splash_width >> (3 - log2_bpp); splash_bits = malloc (splash_row_bytes * splash_height); if (splash_bits == NULL) { fprintf (stderr, "unable to allocate `%d' bytes for bits buffer\n", splash_row_bytes * splash_height); exit (-1); } ppm_read_write_bits (splash_height, splash_width, splash_row_bytes, splashfp, splash_bits); fscanf (buttonfp, "%s", buf); if (! strcmp (buf, "P3")) pixmap_p = TRUE; else if (! strcmp (buf, "P1")) pixmap_p = FALSE; else { fprintf (stderr, "ppm type must be `P3' or `P1'\n"); exit (-1); } fscanf (buttonfp, "%d %d", &button_width, &button_height); if (button_width > splash_width || button_height > splash_height) { fprintf (stderr, "button image cannot be larger than splash image\n"); exit (-1); } if (button_width & ((1 << (3 - log2_bpp)) - 1)) { fprintf (stderr, "button but be intergral number of bytes wide"); exit (-1); } button_row_bytes = button_width >> (3 - log2_bpp); button_bits = malloc (button_row_bytes * button_height); if (button_bits == NULL) { fprintf (stderr, "unable to allocate `%d' bytes for bits buffer\n", button_row_bytes * button_height); exit (-1); } ppm_read_write_bits (button_height, button_width, button_row_bytes, buttonfp, button_bits); header.button_height = CW (button_height); header.button_y = CW (splash_height - 12 - button_height); header.button_x_byte = CW ((splash_width - 16 - button_width) >> (3 - log2_bpp)); header.button_row_bytes = CL (button_row_bytes); header.bpp = CL (bpp); header.log2_bpp = CL (log2_bpp); header.color_count = CL (1 << bpp); header.color_offset = CL (sizeof header); header.splash_bits_offset = CL (sizeof header + (sizeof *color_buf << bpp)); header.button_bits_offset = CL (CL (header.splash_bits_offset) + splash_row_bytes * splash_height); retval = write (outfd, &header, sizeof header); if (retval != sizeof header) errno_fatal ("write"); retval = write (outfd, color_buf, sizeof *color_buf << bpp); if (retval != sizeof *color_buf << bpp) errno_fatal ("write"); retval = write (outfd, splash_bits, splash_row_bytes * splash_height); if (retval != splash_row_bytes * splash_height) errno_fatal ("%d = write", retval); retval = write (outfd, button_bits, button_row_bytes * button_height); if (retval != button_row_bytes * button_height) errno_fatal ("%d = write", retval); fclose (splashfp); fclose (buttonfp); close (splashfd); close (buttonfd); close (outfd); exit (EXIT_SUCCESS); }