make it easier to change the color theme for svg and tty - chess-puzzles - chess puzzle book generator
 (HTM) git clone git://git.codemadness.org/chess-puzzles
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit cbf34cae81cb9545e3854c19eb15040f106ab02f
 (DIR) parent b55e73ad95fbbe333cdac344ca25a84dc61151b0
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Wed, 20 Dec 2023 21:16:42 +0100
       
       make it easier to change the color theme for svg and tty
       
       Diffstat:
         M fen_to_svg.c                        |      33 ++++++++++++++-----------------
       
       1 file changed, 15 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/fen_to_svg.c b/fen_to_svg.c
       @@ -19,6 +19,13 @@ static int enpassantsquare[2] = { -1, -1 };
        static int movenumber = 1;
        static int halfmove = 0;
        
       +/* lichess default theme colors */
       +static const int border[] = { 0x70, 0x49, 0x2d };
       +static const int darksquare[] = { 0xb5, 0x88, 0x63 };
       +static const int lightsquare[] = { 0xf0, 0xd9, 0xb5 };
       +static const int darksquarehi[] = { 0xaa, 0xa2, 0x3a };
       +static const int lightsquarehi[] = { 0xcd, 0xd2, 0x6a };
       +
        static const int showcoords = 1; /* config: show board coordinates? */
        
        int
       @@ -151,12 +158,7 @@ svg_showpiece(int c)
        void
        svg_showboard(void)
        {
       -        /* lichess default theme colors */
       -        const char *darksquare = "#b58863";
       -        const char *lightsquare = "#f0d9b5";
       -        const char *darksquarehi = "#aaa23a";
       -        const char *lightsquarehi = "#cdd26a";
       -        const char *color;
       +        const int *color;
                int x, y, piece;
        
                fputs("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
       @@ -182,8 +184,8 @@ svg_showboard(void)
                                                color = highlight[y][x] ? lightsquarehi : lightsquare;
                                }
        
       -                        printf("<g><rect x=\"%d\" y=\"%d\" width=\"45\" height=\"45\" fill=\"%s\"/></g>\n",
       -                                x * 45, y * 45, color);
       +                        printf("<g><rect x=\"%d\" y=\"%d\" width=\"45\" height=\"45\" fill=\"#%02x%02x%02x\"/></g>\n",
       +                                x * 45, y * 45, color[0], color[1], color[2]);
        
                                piece = getpiece(x, y);
                                if (piece) {
       @@ -201,8 +203,8 @@ svg_showboard(void)
                                        color = highlight[y][x] ? lightsquarehi : lightsquare;
                                else
                                        color = highlight[y][x] ? darksquarehi : darksquare;
       -                        printf("<text x=\"%d\" y=\"%d\" fill=\"%s\" text-anchor=\"end\" style=\"font-family: sans-serif; font-size: 10px\">%c</text>\n",
       -                                (x + 1) * 45 - 2, (y * 45) + 10, color, '8' - y);
       +                        printf("<text x=\"%d\" y=\"%d\" fill=\"#%02x%02x%02x\" text-anchor=\"end\" style=\"font-family: sans-serif; font-size: 10px\">%c</text>\n",
       +                                (x + 1) * 45 - 2, (y * 45) + 10, color[0], color[1], color[2], '8' - y);
                        }
                        y = 7;
                        for (x = 0; x < 8; x++) {
       @@ -210,8 +212,8 @@ svg_showboard(void)
                                        color = highlight[y][x] ? lightsquarehi : lightsquare;
                                else
                                        color = highlight[y][x] ? darksquarehi : darksquare;
       -                        printf("<text x=\"%d\" y=\"%d\" fill=\"%s\" text-anchor=\"start\" style=\"font-family: sans-serif; font-size: 10px\">%c</text>\n",
       -                                (x * 45) + 2, (y + 1) * 45 - 3, color, x + 'a');
       +                        printf("<text x=\"%d\" y=\"%d\" fill=\"#%02x%02x%02x\" text-anchor=\"start\" style=\"font-family: sans-serif; font-size: 10px\">%c</text>\n",
       +                                (x * 45) + 2, (y + 1) * 45 - 3, color[0], color[1], color[2], x + 'a');
                        }
                }
        
       @@ -252,12 +254,7 @@ tty_showpiece(int c)
        void
        tty_showboard(void)
        {
       -        int *color;
       -        int border[] = { 0x70, 0x49, 0x2d };
       -        int darksquare[] = { 0xb5, 0x88, 0x63 };
       -        int lightsquare[] = { 0xf0, 0xd9, 0xb5 };
       -        int darksquarehi[] = { 0xaa, 0xa2, 0x3a };
       -        int lightsquarehi[] = { 0xcd, 0xd2, 0x6a };
       +        const int *color;
                int x, y, piece;
        
                printf("Board FEN:\n");