Changeset 1099 for toilet/trunk/src


Ignore:
Timestamp:
Sep 23, 2006, 9:27:19 PM (17 years ago)
Author:
Sam Hocevar
Message:
  • Added -m/--metal flag. Pretty ugly.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • toilet/trunk/src/main.c

    r1087 r1099  
    3333/* Canvas special effects */
    3434static void filter_autocrop(cucul_canvas_t *);
     35static void filter_metal(cucul_canvas_t *);
    3536static void filter_gay(cucul_canvas_t *);
    3637
     
    4748    char const *export = "utf8";
    4849    unsigned flag_gay = 0;
     50    unsigned flag_metal = 0;
    4951
    5052#if defined(HAVE_GETOPT_H)
     
    5759        {
    5860            /* Long option, needs arg, flag, short option */
     61            { "metal", 0, NULL, 'm' },
    5962            { "gay", 0, NULL, 'g' },
    6063            { "irc", 0, NULL, 'i' },
     
    6467        };
    6568
    66         int c = getopt_long(argc, argv, "gihv", long_options, &option_index);
     69        int c = getopt_long(argc, argv, "gmihv", long_options, &option_index);
    6770#   else
    6871#       define MOREINFO "Try `%s -h' for more information.\n"
    69         int c = getopt(argc, argv, "gihv");
     72        int c = getopt(argc, argv, "gmihv");
    7073#   endif
    7174        if(c == -1)
     
    7578        {
    7679        case 'h': /* --help */
    77             printf("Usage: %s [ -gihv ] [ message ]\n", argv[0]);
     80            printf("Usage: %s [ -gmihv ] [ message ]\n", argv[0]);
    7881#   ifdef HAVE_GETOPT_LONG
    7982            printf("  -g, --gay        add a rainbow effect to the text\n");
     83            printf("  -m, --metal      add a metal effect to the text\n");
    8084            printf("  -i, --irc        output IRC colour codes\n");
    8185            printf("  -h, --help       display this help and exit\n");
     
    8387#   else
    8488            printf("  -g    add a rainbow effect to the text\n");
     89            printf("  -m    add a metal effect to the text\n");
    8590            printf("  -i    output IRC colour codes\n");
    8691            printf("  -h    display this help and exit\n");
     
    8893#   endif
    8994            return 0;
     95        case 'm': /* --metal */
     96            flag_metal = 1;
     97            break;
    9098        case 'g': /* --gay */
    9199            flag_gay = 1;
     
    148156    cv = cuculize_big(string, length);
    149157    filter_autocrop(cv);
     158    if(flag_metal)
     159        filter_metal(cv);
    150160    if(flag_gay)
    151161        filter_gay(cv);
     
    260270}
    261271
     272static void filter_metal(cucul_canvas_t *cv)
     273{
     274    static struct
     275    {
     276        char ch[6];
     277        unsigned char fg, bg;
     278    }
     279    const palette[] =
     280    {
     281        { " ", CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_LIGHTBLUE },
     282        { "░", CUCUL_COLOR_BLUE, CUCUL_COLOR_LIGHTBLUE },
     283        { "▒", CUCUL_COLOR_BLUE, CUCUL_COLOR_LIGHTBLUE },
     284        { "░", CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLUE },
     285        { " ", CUCUL_COLOR_BLUE, CUCUL_COLOR_BLUE },
     286        { " ", CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_LIGHTGRAY },
     287        { "░", CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY },
     288        { "▒", CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY },
     289        { "░", CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY },
     290        { " ", CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_DARKGRAY },
     291    };
     292
     293    unsigned int x, y, w, h;
     294
     295    w = cucul_get_canvas_width(cv);
     296    h = cucul_get_canvas_height(cv);
     297
     298    for(y = 0; y < h; y++)
     299        for(x = 0; x < w; x++)
     300    {
     301        int i;
     302
     303        if(cucul_getchar(cv, x, y) == (unsigned char)' ')
     304            continue;
     305
     306        i = y * 10 / h;
     307        cucul_set_color(cv, palette[i].fg, palette[i].bg);
     308        cucul_putstr(cv, x, y, palette[i].ch);
     309    }
     310}
     311
    262312static void filter_gay(cucul_canvas_t *cv)
    263313{
Note: See TracChangeset for help on using the changeset viewer.