Skip to content
Snippets Groups Projects
Select Git revision
  • f59a58bf3c3997c650d746e0965ee5c17483c850
  • master default protected
2 results

lbm.c

Blame
  • Forked from orestis.malaspin / boltzmann_sur_reseau_concurrent
    Source project has a limited visibility.
    lbm.c 1.27 KiB
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include "gfx.h"
    
    #define MAXCOLOR 255
    
    void show_pixels(struct gfx_context_t* context, int nx, int ny) {
        gfx_clear(context, COLOR_BLACK);
    
        for(int ix = 0; ix < nx; ++ix) {
    		for(int iy = 0; iy < ny; ++iy){
                int px = rand() % MAXCOLOR;
    
                uint32_t color = MAKE_COLOR(px, px, px);
    
                gfx_putpixel(context, ix, iy, color);
            }
        }
        gfx_present(context);
    }
    
    int main()
    { 
        int nx = 600;
        int ny = 400;
        struct gfx_context_t* context = gfx_create("Random Image", nx, ny);
        if (!context) {
            fprintf(stderr, "Graphic mode initialization failed!\n");
            EXIT_FAILURE;
        }
    
        SDL_ShowCursor(SDL_ENABLE); // needed to se the cursor
        SDL_Keycode key_pressed = 0; // escape keyy needed
    
        int max_iter = 100000;
    
        int it = 0;
        point p;
        while (it < max_iter) { // press escape to exit the loop
            SDL_PumpEvents();
    
            key_pressed = gfx_keypressed();
            if (key_pressed == SDLK_ESCAPE) {
                break;
            }
    
            show_pixels(context, nx, ny);
            int id = gfx_left_right_mouse_pressed(&p);
            if (id) {
                printf("A valid mouse clic was performed.\n");
            }
    
            it += 1;
        }
    
    	return EXIT_SUCCESS;
    }