From b72b63e0575da360b8acae253278abe5d52f0460 Mon Sep 17 00:00:00 2001 From: blz Date: Sun, 8 Mar 2026 04:13:03 +0100 Subject: [PATCH] Color setup + Doc update --- README.md | 33 +++++++++++++++++-- glisseur_10.c | 89 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 102 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 2b509a7..1027d6e 100644 --- a/README.md +++ b/README.md @@ -47,16 +47,45 @@ $ ./sdl-glisseur_10 $ top (or ps ax) ---> get PID of the glider proccess $ kill -9 PID ``` -or try to CTRL+C many times +or try many times to close window - - - - - - - # Adjust image size -Update WIDTH and HEIGHT on lines 36 and 37 + +Update WIDTH and HEIGHT on ``` +// Canvas height and width // #define WIDTH 640 #define HEIGHT 480 ``` +- - - - - - - +# Set up the 4 colors + +``` +// Canvas height and width // +#define WIDTH 640 +#define HEIGHT 480 +``` + +- - - - - - - +# Set up the 4 colors +``` +// 4 colors definition // +#define COLOR_0_R 254 +#define COLOR_0_G 254 +#define COLOR_0_B 254 +#define COLOR_1_R 254 +#define COLOR_1_G 0 +#define COLOR_1_B 0 +#define COLOR_2_R 0 +#define COLOR_2_G 254 +#define COLOR_2_B 0 +#define COLOR_3_R 0 +#define COLOR_3_G 0 +#define COLOR_3_B 254 +``` + - - - - - - - # Change glider moving rules Update the direction adding parameters, check examples from line 158 to line 205 diff --git a/glisseur_10.c b/glisseur_10.c index 51a0425..188c569 100644 --- a/glisseur_10.c +++ b/glisseur_10.c @@ -33,9 +33,39 @@ /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// +// Canvas height and width // #define WIDTH 640 #define HEIGHT 480 +// 4 colors definition // +#define COLOR_0_R 254 +#define COLOR_0_G 254 +#define COLOR_0_B 254 +#define COLOR_1_R 254 +#define COLOR_1_G 0 +#define COLOR_1_B 0 +#define COLOR_2_R 0 +#define COLOR_2_G 254 +#define COLOR_2_B 0 +#define COLOR_3_R 0 +#define COLOR_3_G 0 +#define COLOR_3_B 254 +/* +#define COLOR_0_R 254 +#define COLOR_0_G 254 +#define COLOR_0_B 254 +#define COLOR_1_R 0 +#define COLOR_1_G 0 +#define COLOR_1_B 0 +#define COLOR_2_R 240 +#define COLOR_2_G 240 +#define COLOR_2_B 0 +#define COLOR_3_R 254 +#define COLOR_3_G 0 +#define COLOR_3_B 0 +*/ +// END - 4 colors definition // + Uint32 getpixel(SDL_Surface *surface,int x,int y) { @@ -121,14 +151,18 @@ int main(int argc, char * argv[]) //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0xff, 0xff, 0xff)); SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 254, 254, 254)); + //i=320; //j=240; i = floor(WIDTH / 2); j = floor(HEIGHT / 2); + direction=1; //for (j = 0; j < screen->h; j++) { //for (i = 0; i < screen->w; i++) { - + + + // for (n = 0; n < 2000; n++) { while (0!=1) { @@ -145,13 +179,17 @@ while (0!=1) { printf("g=%i - ",g); printf("b=%i - ",b); */ - if ((r==254) && (g==254) && (b==254)) + //if ((r==254) && (g==254) && (b==254)) + if ((r==COLOR_0_R) && (g==COLOR_0_G) && (b==COLOR_0_B)) couleur=0; - else if (r==254 && g==0 && b==0) + //else if (r==254 && g==0 && b==0) + else if (r==COLOR_1_R && g==COLOR_1_G && b==COLOR_1_B) couleur=1; - else if (r==0 && g==254 && b==0) + //else if (r==0 && g==254 && b==0) + else if (r==COLOR_2_R && g==COLOR_2_G && b==COLOR_2_B) couleur=2; - else if (r==0 && g==0 && b==254) + //else if (r==0 && g==0 && b==254) + else if (r==COLOR_3_R && g==COLOR_3_G && b==COLOR_3_B) couleur=3; @@ -159,6 +197,7 @@ while (0!=1) { //printf("direction=%i - ",direction); + // ----- Glider moving rules ----- // /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// for different gliders /// /// on each 4 following cases /// @@ -189,7 +228,7 @@ while (0!=1) { /// --- 1: geometric shape: /// - switch(couleur){ + switch(couleur){ case 0: new_couleur=1; direction=direction+3; @@ -251,6 +290,7 @@ while (0!=1) { break; } */ + // END ----- Glider moving rules ----- // @@ -262,24 +302,36 @@ while (0!=1) { //SDL_LockSurface(screen); switch(new_couleur){ case 0: - nr=254; - ng=254; - nb=254; + //nr=254; + //ng=254; + //nb=254; + nr=COLOR_0_R; + ng=COLOR_0_G; + nb=COLOR_0_B; break; case 1: - nr=254; - ng=0; - nb=0; + //nr=254; + //ng=0; + //nb=0; + nr=COLOR_1_R; + ng=COLOR_1_G; + nb=COLOR_1_B; break; case 2: - nr=0; - ng=254; - nb=0; + //nr=0; + //ng=254; + //nb=0; + nr=COLOR_2_R; + ng=COLOR_2_G; + nb=COLOR_2_B; break; case 3: - nr=0; - ng=0; - nb=254; + //nr=0; + //ng=0; + //nb=254; + nr=COLOR_3_R; + ng=COLOR_3_G; + nb=COLOR_3_B; break; } putPixel(screen, i, j, SDL_MapRGB(screen->format, nr, ng, nb)); @@ -352,6 +404,7 @@ while (0!=1) { //SDL_UnlockSurface(screen); SDL_Flip(screen); + } //} //sleep(5);