Color setup + Doc update

This commit is contained in:
blz
2026-03-08 04:13:03 +01:00
parent b47ad96af2
commit b72b63e057
2 changed files with 102 additions and 20 deletions

View File

@@ -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

View File

@@ -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 ///
@@ -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);