Changeset 160 for ttyvaders


Ignore:
Timestamp:
Nov 12, 2003, 10:18:50 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • libee/ee.h: + Added ee_color_names[] containing our 16 color names.
  • libee/ee.c: + Extended our color set to the full 16 instead of 10. + Precalculate ncurses attributes.
  • libee/graphics.c: + Clip color value in ee_set_color(). + Clip characters in ee_putchar(). + Partially clip characters in ee_putstr(), overflows aren't checked yet.
  • libee/ee_internals.h: + New file to share extern variables within libee.
  • test/demo.c: + Added a simple demo_color() to output all colors. + Replaced four ee_draw_line() with ee_draw_thin_box(). + Replaced x1, y1, x2 etc. with xa, ya, xb etc. because <math.h> already

defines y1.

+ Randomized colours from 0 to 15 instead of 1 to 10.

  • src/Makefiles.am: + Added -lm to the ttyvaders linking flags because of the intro.
  • README BUGS TODO: + Updated.
Location:
ttyvaders/trunk
Files:
2 added
18 edited

Legend:

Unmodified
Added
Removed
  • ttyvaders/trunk/Makefile.am

    r118 r160  
    66DIST_SUBDIRS = $(SUBDIRS) autotools data debian
    77
    8 EXTRA_DIST = doc/shapes.txt bootstrap
     8EXTRA_DIST = BUGS doc/shapes.txt bootstrap
    99AUTOMAKE_OPTIONS = foreign dist-bzip2
    1010
  • ttyvaders/trunk/README

    • Property svn:keywords set to Id
    r158 r160  
     1$Id$
    12
    23Building ttyvaders
    3 ==================
    44
    5    Run configure then make. Configure flags are:
     5   o  Run configure then make. Useful configure flags are:
    66
    7     --enable-slang: use the SLang library (default)
    8     --enable-ncurses: use the ncurses library
    9     --enable-conio: use MS-DOS conio.h
     7     --enable-slang: use the SLang library (default)
     8     --enable-ncurses: use the ncurses library
     9     --enable-conio: use MS-DOS conio.h
    1010
    11    Cross-compilation example:
    12     ./configure --enable-conio --host=i386-pc-msdosdjgpp
     11   o  Cross-compilation example:
     12 
     13     ./configure --enable-conio --host=i386-pc-msdosdjgpp
    1314
    1415
    1516History of textmode games
    16 =========================
    1717
    18 http://www.textmodegames.com/
     18   o  http://www.textmodegames.com/
    1919
    2020
    2121Other terminal-based games
    22 ==========================
    2322
    24  * moon-buggy: http://www.mathematik.uni-kl.de/~wwwstoch/voss/comp/moon-buggy.html
    25     extremely simple, extremely addictive
     23   o  moon-buggy: extremely simple, extremely addictive
     24      http://www.mathematik.uni-kl.de/~wwwstoch/voss/comp/moon-buggy.html
    2625
    27  * 0verkill: http://artax.karlin.mff.cuni.cz/~brain/0verkill/
     26   o 0verkill: http://artax.karlin.mff.cuni.cz/~brain/0verkill/
    2827
    29  * nInvaders: http://dettus.dyndns.org/ninvaders/
    30     real space invaders clone
     28   o nInvaders: http://dettus.dyndns.org/ninvaders/
     29      real space invaders clone
    3130
    32  * Stardork: http://www.seekrut.com/rk/stardork.html
    33     more strategy than arcade
     31   o Stardork: http://www.seekrut.com/rk/stardork.html
     32      more strategy than arcade
    3433
    35  * Nethack: http://www.nethack.org/
     34   o Nethack: http://www.nethack.org/
    3635
    37  * Tetrinet: http://www.secret.com.au/games/tetrinet/
     36   o Tetrinet: http://www.secret.com.au/games/tetrinet/
    3837
    39  * MyMan: http://geocities.com/bsittler/
    40     pacman clone
     38   o MyMan: http://geocities.com/bsittler/
     39      pacman clone
    4140
    42  * Tornado: http://home.kcore.de/~kiza/linux/tornado/
     41   o Tornado: http://home.kcore.de/~kiza/linux/tornado/
    4342
    44  * David's Perl games: http://davidsperlgames.sourceforge.net/
     43   o David's Perl games: http://davidsperlgames.sourceforge.net/
    4544
    46  * ascii-invaders: http://www.ip9.org/munro/invaders/index.html
     45   o ascii-invaders: http://www.ip9.org/munro/invaders/index.html
    4746
  • ttyvaders/trunk/TODO

    • Property svn:keywords set to Id
    r70 r160  
    1 Things to do
     1$Id$
    22
    3  * let the ship pick up bonuses
     3TODO for libee
    44
    5  DONE 23 Dec 2002: handle life
     5   o  Sprite library
    66
    7  * alien swarms, programmed behaviour
     7   o  Clip graphics
    88
    9  * sprite library
     9   o  Fix the thin ellipse rendering
    1010
    11  DONE 23 Dec 2002: mega ball
     11   o  Write a Linux console output for the drawing library
     12      See also BUGS as to why it's very slow in console mode
    1213
    13  * spiral weapon (vertical sine)
     14   o  DONE 12 Nov 2003: Port to conio.h
    1415
    15  DONE 23 Dec 2002: fragmentation bomb (merge with mega-ball?)
    1616
    17  * stick aliens to tunnel
     17TODO for ttyvaders
    1818
    19  * change tunnel colour
     19   o  Let the ship pick up bonuses
    2020
    21  DONE Dec 23 2002: fill holes in the tunnel when |step| > 2
     21   o  Alien swarms, programmed behaviour
    2222
    23  DONE Dec 18 2002: draw a 3rd alien type
     23   o  Spiral weapon (vertical sine)
    2424
    25  * draw bosses
     25   o  Stick aliens to tunnel
    2626
    27  * port to conio.h
     27   o  Change tunnel colour
    2828
    29  * clip graphics
     29   o  Draw bosses
    3030
    31  * promote precision for all coordinates except screen
     31   o  Promote precision for all coordinates except screen
    3232
    33  DONE Dec 19 2002: tunnel sometimes doesn't get drawn on the left
     33   o  Animate the ship
    3434
    35  * write a generic drawing library with automatic clipping
     35   o  The nuke should break the tunnel
     36      Or at least a bit
    3637
    37  * write a linux console output for the drawing library
     38   o  The laser stays alive when the ship explodes
    3839
    39  * animate the ship
     40   o  DONE 12 Nov 2003: Write a generic drawing library with automatic clipping
     41   o  DONE 23 Dec 2002: Handle life
     42   o  DONE 23 Dec 2002: Mega ball
     43   o  DONE 23 Dec 2002: Fragmentation bomb (merge with mega-ball?)
     44   o  DONE 23 Dec 2002: Fill holes in the tunnel when |step| > 2
     45   o  DONE 19 Dec 2002: Tunnel sometimes doesn't get drawn on the left
     46   o  DONE 18 Dec 2002: Draw a 3rd alien type
    4047
    41  * the nuke should break the tunnel
    42 
    43  * the laser stays alive when the ship explodes
    44 
  • ttyvaders/trunk/libee/Makefile.am

    r152 r160  
    77        ee.c \
    88        ee.h \
     9        ee_internals.h \
    910        graphics.c \
    1011        io.c \
  • ttyvaders/trunk/libee/box.c

    r154 r160  
    2323#include "config.h"
    2424
    25 #ifdef USE_SLANG
    26 #   include <slang.h>
    27 #elif USE_NCURSES
    28 #   include <curses.h>
    29 #endif
    30 
    3125#include <stdlib.h>
    3226
    3327#include "ee.h"
     28#include "ee_internals.h"
    3429
    3530void ee_draw_box(int x1, int y1, int x2, int y2, char c)
  • ttyvaders/trunk/libee/conic.c

    r156 r160  
    2222
    2323#include "config.h"
    24 
    25 #ifdef USE_SLANG
    26 #   include <slang.h>
    27 #elif USE_NCURSES
    28 #   include <curses.h>
    29 #endif
    3024
    3125#ifdef HAVE_INTTYPES_H
     
    3832
    3933#include "ee.h"
     34#include "ee_internals.h"
    4035
    4136static void ellipsepoints(int, int, int, int, char);
  • ttyvaders/trunk/libee/ee.c

    r158 r160  
    4444
    4545#include "ee.h"
     46#include "ee_internals.h"
     47
     48/* Global array with color names */
     49char *ee_color_names[16] =
     50{
     51    "black",
     52    "blue",
     53    "green",
     54    "cyan",
     55    "red",
     56    "magenta",
     57    "brown",
     58    "lightgray",
     59    "darkgray",
     60    "lightblue",
     61    "lightgreen",
     62    "lightcyan",
     63    "lightred",
     64    "lightmagenta",
     65    "yellow",
     66    "white",
     67};
    4668
    4769static int _ee_delay;
     70
     71#if defined(USE_NCURSES)
     72int _ee_attr[16];
     73#endif
     74
    4875#if defined(USE_CONIO)
    4976static struct text_info ti;
    50 char *_screen_buffer;
     77char *_ee_screen;
    5178#endif
    5279
     
    5481{
    5582#if defined(USE_SLANG)
    56     static char * colors[] = { "black", "green", "yellow", "white",
    57         "red", "gray", "lightgray", "blue", "cyan", "magenta", NULL };
     83    static char *slang_colors[16] =
     84    {
     85        "black",
     86        "blue",
     87        "green",
     88        "cyan",
     89        "red",
     90        "magenta",
     91        "brown",
     92        "lightgray",
     93        "gray",
     94        "brightblue",
     95        "brightgreen",
     96        "brightcyan",
     97        "brightred",
     98        "brightmagenta",
     99        "yellow",
     100        "white",
     101    };
     102
    58103    int i;
    59104
     
    82127    SLsmg_refresh();
    83128
    84     for(i = 0; colors[i]; i++)
    85     {
    86         SLtt_set_color(i + 1, NULL, colors[i], "black");
    87     }
    88 
    89 #elif defined(USE_NCURSES)
    90     /* Initialize ncurses library */
     129    for(i = 0; i < 16; i++)
     130        SLtt_set_color(i + 1, NULL, slang_colors[i], "black");
     131
     132#elif defined(USE_NCURSES)
     133    int i;
     134
    91135    initscr();
    92136    keypad(stdscr, TRUE);
     
    99143    start_color();
    100144
    101     init_pair(EE_BLACK, COLOR_BLACK, COLOR_BLACK);
    102     init_pair(EE_GREEN, COLOR_GREEN, COLOR_BLACK);
    103     init_pair(EE_YELLOW, COLOR_YELLOW, COLOR_BLACK);
    104     init_pair(EE_WHITE, COLOR_WHITE, COLOR_BLACK);
    105     init_pair(EE_RED, COLOR_RED, COLOR_BLACK);
    106     init_pair(EE_GRAY, COLOR_WHITE, COLOR_BLACK); // XXX
    107     init_pair(EE_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK); // XXX
    108     init_pair(EE_BLUE, COLOR_BLUE, COLOR_BLACK);
    109     init_pair(EE_CYAN, COLOR_CYAN, COLOR_BLACK);
    110     init_pair(EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
     145    init_pair(1 + EE_BLACK,        COLOR_BLACK,   COLOR_BLACK);
     146    init_pair(1 + EE_BLUE,         COLOR_BLUE,    COLOR_BLACK);
     147    init_pair(1 + EE_GREEN,        COLOR_GREEN,   COLOR_BLACK);
     148    init_pair(1 + EE_CYAN,         COLOR_CYAN,    COLOR_BLACK);
     149    init_pair(1 + EE_RED,          COLOR_RED,     COLOR_BLACK);
     150    init_pair(1 + EE_MAGENTA,      COLOR_MAGENTA, COLOR_BLACK);
     151    init_pair(1 + EE_BROWN,        COLOR_YELLOW,  COLOR_BLACK);
     152    init_pair(1 + EE_LIGHTGRAY,    COLOR_WHITE,   COLOR_BLACK);
     153    init_pair(1 + EE_DARKGRAY,     COLOR_BLACK,   COLOR_BLACK);
     154    init_pair(1 + EE_LIGHTBLUE,    COLOR_BLUE,    COLOR_BLACK);
     155    init_pair(1 + EE_LIGHTGREEN,   COLOR_GREEN,   COLOR_BLACK);
     156    init_pair(1 + EE_LIGHTCYAN,    COLOR_CYAN,    COLOR_BLACK);
     157    init_pair(1 + EE_LIGHTRED,     COLOR_RED,     COLOR_BLACK);
     158    init_pair(1 + EE_LIGHTMAGENTA, COLOR_MAGENTA, COLOR_BLACK);
     159    init_pair(1 + EE_YELLOW,       COLOR_YELLOW,  COLOR_BLACK);
     160    init_pair(1 + EE_WHITE,        COLOR_WHITE,   COLOR_BLACK);
     161
     162    for(i = 0; i < 8; i++)
     163    {
     164        _ee_attr[i] = COLOR_PAIR(1 + i);
     165        _ee_attr[i + 8] = A_BOLD | COLOR_PAIR(1 + i);
     166    }
    111167
    112168#elif defined(USE_CONIO)
     
    115171    clrscr();
    116172    gettextinfo(&ti);
    117     _screen_buffer = malloc(ee_get_width() * ee_get_height() * 2);
    118     ScreenRetrieve(_screen_buffer);
     173    _ee_screen = malloc(2 * ti.screenwidth * ti.screenheight);
     174#   if defined(SCREENUPDATE_IN_PC_H)
     175    ScreenRetrieve(_ee_screen);
     176#   else
     177    /* FIXME */
     178#   endif
    119179
    120180#endif
     
    188248    refresh();
    189249#elif defined(USE_CONIO)
    190     ScreenUpdate(_screen_buffer);
     250#   if defined(SCREENUPDATE_IN_PC_H)
     251    ScreenUpdate(_ee_screen);
     252#   else
     253    /* FIXME */
     254#   endif
    191255#endif
    192256
     
    215279    endwin();
    216280#elif defined(USE_CONIO)
    217     ScreenUpdate(_screen_buffer);
    218281    _wscroll = 1;
    219282    textcolor((enum COLORS)WHITE);
  • ttyvaders/trunk/libee/ee.h

    r154 r160  
    3232 * Colors
    3333 */
    34 #define EE_BLACK 1
    35 #define EE_GREEN 2
    36 #define EE_YELLOW 3
    37 #define EE_WHITE 4
    38 #define EE_RED 5
    39 #define EE_GRAY 6
    40 #define EE_LIGHTGRAY 7
    41 #define EE_BLUE 8
    42 #define EE_CYAN 9
    43 #define EE_MAGENTA 10
     34enum ee_colors
     35{
     36    EE_BLACK = 0,
     37    EE_BLUE = 1,
     38    EE_GREEN = 2,
     39    EE_CYAN = 3,
     40    EE_RED = 4,
     41    EE_MAGENTA = 5,
     42    EE_BROWN = 6,
     43    EE_LIGHTGRAY = 7,
     44    EE_DARKGRAY = 8,
     45    EE_LIGHTBLUE = 9,
     46    EE_LIGHTGREEN = 10,
     47    EE_LIGHTCYAN = 11,
     48    EE_LIGHTRED = 12,
     49    EE_LIGHTMAGENTA = 13,
     50    EE_YELLOW = 14,
     51    EE_WHITE = 15
     52};
     53
     54extern char *ee_color_names[16];
    4455
    4556/*
  • ttyvaders/trunk/libee/graphics.c

    r158 r160  
    3737
    3838#include "ee.h"
     39#include "ee_internals.h"
    3940
    4041static int ee_color = 0;
    41 #if defined(USE_CONIO)
    42 static enum COLORS dos_colors[] = {
    43     0,
    44     BLACK,
    45     GREEN,
    46     YELLOW,
    47     WHITE,
    48     RED,
    49     DARKGRAY,
    50     LIGHTGRAY,
    51     BLUE,
    52     CYAN,
    53     MAGENTA
    54 };
    55 #endif
    5642
    5743void ee_set_color(int color)
    5844{
     45    if(color < 0 || color > 15)
     46        return;
     47
    5948    ee_color = color;
    6049#if defined(USE_SLANG)
    61     SLsmg_set_color(color);
     50    SLsmg_set_color(color + 1);
    6251#elif defined(USE_NCURSES)
    63     attrset(COLOR_PAIR(color));
     52    attrset(_ee_attr[color]);
    6453#elif defined(USE_CONIO)
    65     if(color >= 1 && color <= 10)
    66         textcolor(dos_colors[color]);
     54    textcolor(color);
    6755#endif
    6856}
     
    7361}
    7462
    75 extern char *_screen_buffer;
    76 
    7763void ee_putchar(int x, int y, char c)
    7864{
     65    if(x < 0 || x >= ee_get_width() || y < 0 || y >= ee_get_height())
     66        return;
     67
    7968#if defined(USE_SLANG)
    80     SLsmg_gotorc(y,x);
     69    SLsmg_gotorc(y, x);
    8170    SLsmg_write_char(c);
    8271#elif defined(USE_NCURSES)
    83     move(y,x);
     72    move(y, x);
    8473    addch(c);
    8574#elif defined(USE_CONIO)
    86     if(x<0 || x>=ee_get_width() || y<0 || y>=ee_get_height())
    87         return;
    88     _screen_buffer[2 * (x + y * ee_get_width())] = c;
    89     _screen_buffer[2 * (x + y * ee_get_width()) + 1] = dos_colors[ee_color];
    90 //    gotoxy(x+1,y+1);
     75    _ee_screen[2 * (x + y * ee_get_width())] = c;
     76    _ee_screen[2 * (x + y * ee_get_width()) + 1] = ee_color;
     77//    gotoxy(x + 1, y + 1);
    9178//    putch(c);
    9279#endif
     
    9582void ee_putstr(int x, int y, char *s)
    9683{
    97     if(y<0 || y>=ee_get_height())
     84    int len;
     85
     86    if(y < 0 || y >= ee_get_height())
    9887        return;
     88
     89    len = strlen(s);
     90
     91    if(x < 0)
     92    {
     93        len -= -x;
     94        if(len < 0)
     95            return;
     96        s += -x;
     97        x = 0;
     98    }
     99
    99100#if defined(USE_SLANG)
    100     SLsmg_gotorc(y,x);
     101    SLsmg_gotorc(y, x);
    101102    SLsmg_write_string(s);
    102103#elif defined(USE_NCURSES)
    103     move(y,x);
     104    move(y, x);
    104105    addstr(s);
    105106#elif defined(USE_CONIO)
    106     char *buf = _screen_buffer + 2 * (x + y * ee_get_width());
     107    char *buf = _ee_screen + 2 * (x + y * ee_get_width());
    107108    while(*s)
    108109    {
    109110        *buf++ = *s++;
    110         *buf++ = dos_colors[ee_color];
     111        *buf++ = ee_color;
    111112    }
    112 //    gotoxy(x+1,y+1);
     113//    gotoxy(x + 1, y + 1);
    113114//    cputs(s);
    114115#endif
     
    118119{
    119120    /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
    120     int x = ee_get_width(), y = ee_get_height();
     121    int x = ee_get_width();
     122    int y = ee_get_height();
    121123    char *empty_line = malloc((x + 1) * sizeof(char));
    122124
  • ttyvaders/trunk/libee/io.c

    r156 r160  
    2323#include "config.h"
    2424
    25 #ifdef USE_SLANG
     25#if defined(USE_SLANG)
    2626#   include <slang.h>
    27 #elif USE_NCURSES
     27#elif defined(USE_NCURSES)
    2828#   include <curses.h>
    29 #elif USE_CONIO
     29#elif defined(USE_CONIO)
    3030#   include <conio.h>
    3131#else
     
    3434
    3535#include "ee.h"
     36#include "ee_internals.h"
    3637
    3738char ee_get_key(void)
    3839{
    39 #ifdef USE_SLANG
    40     if(SLang_input_pending(0))
    41     {
    42         return SLang_getkey();
    43     }
    44 #elif USE_NCURSES
     40#if defined(USE_SLANG)
     41    return SLang_input_pending(0) ? SLang_getkey() : 0;
     42
     43#elif defined(USE_NCURSES)
    4544    char key = getch();
     45    return key != ERR ? key : 0;
    4646
    47     if(key != ERR)
    48     {
    49         return key;
    50     }
    51 #elif USE_CONIO
     47#elif defined(USE_CONIO)
    5248    return _conio_kbhit() ? getch() : 0;
    5349
    5450#endif
    55 
    56     return 0;
    5751}
    5852
  • ttyvaders/trunk/libee/line.c

    r156 r160  
    2222
    2323#include "config.h"
    24 
    25 #ifdef USE_SLANG
    26 #   include <slang.h>
    27 #elif USE_NCURSES
    28 #   include <curses.h>
    29 #endif
    3024
    3125#ifdef HAVE_INTTYPES_H
     
    3832
    3933#include "ee.h"
     34#include "ee_internals.h"
    4035
    4136struct line
  • ttyvaders/trunk/libee/math.c

    r148 r160  
    2323#include "config.h"
    2424
    25 #ifdef USE_SLANG
    26 #   include <slang.h>
    27 #elif USE_NCURSES
    28 #   include <curses.h>
    29 #endif
    30 
    3125#include <stdlib.h>
    3226
    3327#include "ee.h"
     28#include "ee_internals.h"
    3429
    3530int ee_rand(int min, int max)
  • ttyvaders/trunk/libee/sprite.c

    r154 r160  
    2323#include "config.h"
    2424
    25 #ifdef USE_SLANG
    26 #   include <slang.h>
    27 #elif USE_NCURSES
    28 #   include <curses.h>
    29 #endif
    30 
    3125#include <stdio.h>
    3226#include <stdlib.h>
     
    3428
    3529#include "ee.h"
     30#include "ee_internals.h"
    3631
    3732struct ee_frame
  • ttyvaders/trunk/libee/triangle.c

    r152 r160  
    2323#include "config.h"
    2424
    25 #ifdef USE_SLANG
    26 #   include <slang.h>
    27 #elif USE_NCURSES
    28 #   include <curses.h>
    29 #endif
    30 
    3125#include <stdlib.h>
    3226
    3327#include "ee.h"
     28#include "ee_internals.h"
    3429
    3530void ee_draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)
  • ttyvaders/trunk/src/Makefile.am

    r154 r160  
    3030        weapons.c \
    3131        $(NULL)
    32 ttyvaders_LDADD = ../libee/libee.a $(LDFLAGS_slang) $(LDFLAGS_ncurses)
     32ttyvaders_LDADD = ../libee/libee.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm
    3333
  • ttyvaders/trunk/src/overlay.c

    r154 r160  
    3333
    3434    /* Draw life jauge */
    35     ee_set_color(EE_GRAY);
     35    ee_set_color(EE_DARKGRAY);
    3636    ee_putstr(4, 1, dots30);
    3737
     
    5656
    5757    /* Draw weapon jauge */
    58     ee_set_color(EE_GRAY);
     58    ee_set_color(EE_DARKGRAY);
    5959    ee_putstr(42, 1, dots30 + 10);
    6060
  • ttyvaders/trunk/src/weapons.c

    r154 r160  
    7070                break;
    7171            case WEAPON_BOMB:
    72                 ee_set_color(EE_GRAY);
     72                ee_set_color(EE_DARKGRAY);
    7373                ee_putchar((wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4, '.');
    7474                ee_putchar((wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4, '.');
  • ttyvaders/trunk/test/demo.c

    r154 r160  
    2525#include <math.h>
    2626#include <string.h>
     27#include <stdio.h>
    2728
    2829#include "ee.h"
     
    3233static void demo_all(void);
    3334
     35static void demo_color(void);
    3436static void demo_dots(void);
    3537static void demo_lines(void);
     
    7779                quit = 1;
    7880                break;
     81            case 'c':
     82                ee_clear();
     83                demo = demo_color;
     84                break;
    7985            case '0':
    8086                ee_clear();
     
    144150    ee_clear();
    145151    ee_set_color(EE_WHITE);
    146     ee_draw_line(xo, yo, 1, yo, '.');
    147     ee_draw_line(1, yo, 1, 1, ':');
    148     ee_draw_line(xo, 1, xo, yo, ':');
    149     ee_draw_line(1, 1, xo, 1, '.');
     152    ee_draw_thin_box(1, 1, xo, yo);
    150153
    151154    ee_putstr((xo - strlen("libee demo")) / 2, 3, "libee demo");
     
    172175    static int i = 0;
    173176
    174     int j, xo, yo, x1, y1, x2, y2, x3, y3;
     177    int j, xo, yo, xa, ya, xb, yb, xc, yc;
    175178
    176179    i++;
     
    185188    for(j = 0; j < 16; j++)
    186189    {
    187         x1 = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8);
    188         y1 = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8);
    189         ee_draw_thin_line(xo, yo, x1, y1);
     190        xa = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8);
     191        ya = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8);
     192        ee_draw_thin_line(xo, yo, xa, ya);
    190193    }
    191194
     
    200203    yo = 2;
    201204
    202     x1 = ee_get_width() / 8 + sin(0.03*i) * 5;
    203     y1 = ee_get_height() / 2 + cos(0.03*i) * 5;
    204 
    205     x2 = ee_get_width() - 10 - cos(0.02*i) * 10;
    206     y2 = ee_get_height() * 3 / 4 - 5 + sin(0.02*i) * 5;
    207 
    208     x3 = ee_get_width() / 4 - sin(0.02*i) * 5;
    209     y3 = ee_get_height() * 3 / 4 + cos(0.02*i) * 5;
     205    xa = ee_get_width() / 8 + sin(0.03*i) * 5;
     206    ya = ee_get_height() / 2 + cos(0.03*i) * 5;
     207
     208    xb = ee_get_width() - 10 - cos(0.02*i) * 10;
     209    yb = ee_get_height() * 3 / 4 - 5 + sin(0.02*i) * 5;
     210
     211    xc = ee_get_width() / 4 - sin(0.02*i) * 5;
     212    yc = ee_get_height() * 3 / 4 + cos(0.02*i) * 5;
    210213
    211214    ee_set_color(EE_GREEN);
    212     ee_fill_triangle(xo, yo, x2, y2, x1, y1, '%');
     215    ee_fill_triangle(xo, yo, xb, yb, xa, ya, '%');
    213216    ee_set_color(EE_YELLOW);
    214     ee_draw_thin_triangle(xo, yo, x2, y2, x1, y1);
     217    ee_draw_thin_triangle(xo, yo, xb, yb, xa, ya);
    215218
    216219    ee_set_color(EE_RED);
    217     ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
     220    ee_fill_triangle(xa, ya, xb, yb, xc, yc, '#');
    218221    ee_set_color(EE_YELLOW);
    219     ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3);
     222    ee_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
    220223
    221224    ee_set_color(EE_BLUE);
    222     ee_fill_triangle(xo, yo, x2, y2, x3, y3, '%');
     225    ee_fill_triangle(xo, yo, xb, yb, xc, yc, '%');
    223226    ee_set_color(EE_YELLOW);
    224     ee_draw_thin_triangle(xo, yo, x2, y2, x3, y3);
     227    ee_draw_thin_triangle(xo, yo, xb, yb, xc, yc);
    225228
    226229    /* Draw a background triangle */
    227     x1 = 2;
    228     y1 = 2;
    229 
    230     x2 = ee_get_width() - 3;
    231     y2 = ee_get_height() / 2;
    232 
    233     x3 = ee_get_width() / 3;
    234     y3 = ee_get_height() - 3;
     230    xa = 2;
     231    ya = 2;
     232
     233    xb = ee_get_width() - 3;
     234    yb = ee_get_height() / 2;
     235
     236    xc = ee_get_width() / 3;
     237    yc = ee_get_height() - 3;
    235238
    236239    ee_set_color(EE_CYAN);
    237     ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3);
     240    ee_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
    238241
    239242    xo = ee_get_width() / 2 + cos(0.027*i) * ee_get_width() / 3;
    240243    yo = ee_get_height() / 2 - sin(0.027*i) * ee_get_height() / 2;
    241244
    242     ee_draw_thin_line(x1, y1, xo, yo);
    243     ee_draw_thin_line(x2, y2, xo, yo);
    244     ee_draw_thin_line(x3, y3, xo, yo);
     245    ee_draw_thin_line(xa, ya, xo, yo);
     246    ee_draw_thin_line(xb, yb, xo, yo);
     247    ee_draw_thin_line(xc, yc, xo, yo);
    245248
    246249    /* Draw a sprite on the pyramid */
     
    251254    {
    252255        int delta = ee_rand(-5, 5);
    253         ee_set_color(ee_rand(1, 10));
     256        ee_set_color(ee_rand(0, 15));
    254257        ee_putchar(ee_get_width() / 2
    255258                    + cos(0.02*j) * (delta + ee_get_width() / 4),
     
    276279    {
    277280        /* Putpixel */
    278         ee_set_color(ee_rand(1, 10));
     281        ee_set_color(ee_rand(0, 15));
    279282        ee_putchar(ee_rand(0, xmax), ee_rand(0, ymax), '#');
     283    }
     284    ee_refresh();
     285}
     286
     287static void demo_color(void)
     288{
     289    int i;
     290    char buf[BUFSIZ];
     291
     292    ee_clear();
     293    for(i = 0; i < 16; i++)
     294    {
     295        sprintf(buf, "color %i (%s)\n", i, ee_color_names[i]);
     296        ee_set_color(EE_WHITE);
     297        ee_putstr(4, i + 3, buf);
     298        ee_set_color(i);
     299        ee_putstr(40, i + 3, "XXXXXXXXXX-XX--X----------");
    280300    }
    281301    ee_refresh();
     
    286306    int w = ee_get_width();
    287307    int h = ee_get_height();
    288     int x1, y1, x2, y2;
     308    int xa, ya, xb, yb;
    289309
    290310    if(force_clipping)
    291311    {
    292         x1 = ee_rand(- w, 2 * w); y1 = ee_rand(- h, 2 * h);
    293         x2 = ee_rand(- w, 2 * w); y2 = ee_rand(- h, 2 * h);
     312        xa = ee_rand(- w, 2 * w); ya = ee_rand(- h, 2 * h);
     313        xb = ee_rand(- w, 2 * w); yb = ee_rand(- h, 2 * h);
    294314    }
    295315    else
    296316    {
    297         x1 = ee_rand(0, w - 1); y1 = ee_rand(0, h - 1);
    298         x2 = ee_rand(0, w - 1); y2 = ee_rand(0, h - 1);
    299     }
    300 
    301     ee_set_color(ee_rand(1, 10));
     317        xa = ee_rand(0, w - 1); ya = ee_rand(0, h - 1);
     318        xb = ee_rand(0, w - 1); yb = ee_rand(0, h - 1);
     319    }
     320
     321    ee_set_color(ee_rand(0, 15));
    302322    if(thin)
    303         ee_draw_thin_line(x1, y1, x2, y2);
     323        ee_draw_thin_line(xa, ya, xb, yb);
    304324    else
    305         ee_draw_line(x1, y1, x2, y2, '#');
     325        ee_draw_line(xa, ya, xb, yb, '#');
    306326
    307327    ee_refresh();
     
    312332    int w = ee_get_width();
    313333    int h = ee_get_height();
    314     int x1, y1, x2, y2;
     334    int xa, ya, xb, yb;
    315335
    316336    if(force_clipping)
    317337    {
    318         x1 = ee_rand(- w, 2 * w); y1 = ee_rand(- h, 2 * h);
    319         x2 = ee_rand(- w, 2 * w); y2 = ee_rand(- h, 2 * h);
     338        xa = ee_rand(- w, 2 * w); ya = ee_rand(- h, 2 * h);
     339        xb = ee_rand(- w, 2 * w); yb = ee_rand(- h, 2 * h);
    320340    }
    321341    else
    322342    {
    323         x1 = ee_rand(0, w - 1); y1 = ee_rand(0, h - 1);
    324         x2 = ee_rand(0, w - 1); y2 = ee_rand(0, h - 1);
    325     }
    326 
    327     ee_set_color(ee_rand(1, 10));
    328     ee_fill_box(x1, y1, x2, y2, '#');
     343        xa = ee_rand(0, w - 1); ya = ee_rand(0, h - 1);
     344        xb = ee_rand(0, w - 1); yb = ee_rand(0, h - 1);
     345    }
     346
     347    ee_set_color(ee_rand(0, 15));
     348    ee_fill_box(xa, ya, xb, yb, '#');
    329349
    330350    if(outline)
    331351    {
    332         ee_set_color(ee_rand(1, 10));
    333         ee_draw_thin_box(x1, y1, x2, y2);
     352        ee_set_color(ee_rand(0, 15));
     353        ee_draw_thin_box(xa, ya, xb, yb);
    334354    }
    335355
     
    358378    }
    359379
    360     ee_set_color(ee_rand(1, 10));
     380    ee_set_color(ee_rand(0, 15));
    361381    ee_fill_ellipse(x, y, a, b, '#');
    362382
    363383    if(outline)
    364384    {
    365         ee_set_color(ee_rand(1, 10));
     385        ee_set_color(ee_rand(0, 15));
    366386        ee_draw_thin_ellipse(x, y, a, b);
    367387    }
     
    374394    int w = ee_get_width();
    375395    int h = ee_get_height();
    376     int x1, y1, x2, y2, x3, y3;
     396    int xa, ya, xb, yb, xc, yc;
    377397
    378398    if(force_clipping)
    379399    {
    380         x1 = ee_rand(- w, 2 * w); y1 = ee_rand(- h, 2 * h);
    381         x2 = ee_rand(- w, 2 * w); y2 = ee_rand(- h, 2 * h);
    382         x3 = ee_rand(- w, 2 * w); y3 = ee_rand(- h, 2 * h);
     400        xa = ee_rand(- w, 2 * w); ya = ee_rand(- h, 2 * h);
     401        xb = ee_rand(- w, 2 * w); yb = ee_rand(- h, 2 * h);
     402        xc = ee_rand(- w, 2 * w); yc = ee_rand(- h, 2 * h);
    383403    }
    384404    else
    385405    {
    386406
    387         x1 = ee_rand(0, w - 1); y1 = ee_rand(0, h - 1);
    388         x2 = ee_rand(0, w - 1); y2 = ee_rand(0, h - 1);
    389         x3 = ee_rand(0, w - 1); y3 = ee_rand(0, h - 1);
    390     }
    391 
    392     ee_set_color(ee_rand(1, 10));
    393     ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');
     407        xa = ee_rand(0, w - 1); ya = ee_rand(0, h - 1);
     408        xb = ee_rand(0, w - 1); yb = ee_rand(0, h - 1);
     409        xc = ee_rand(0, w - 1); yc = ee_rand(0, h - 1);
     410    }
     411
     412    ee_set_color(ee_rand(0, 15));
     413    ee_fill_triangle(xa, ya, xb, yb, xc, yc, '#');
    394414
    395415    if(outline)
    396416    {
    397         ee_set_color(ee_rand(1, 10));
    398         ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3);
     417        ee_set_color(ee_rand(0, 15));
     418        ee_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
    399419    }
    400420
Note: See TracChangeset for help on using the changeset viewer.