Changeset 193
- Timestamp:
- Nov 16, 2003, 4:20:17 PM (19 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/examples/Makefile.am
r190 r193 4 4 5 5 AM_CPPFLAGS = -I$(top_srcdir)/src 6 7 EXTRA_DIST = caca.txt 6 8 7 9 if USE_SLANG -
libcaca/trunk/examples/demo.c
r192 r193 67 67 68 68 /* Initialize data */ 69 sprite = caca_load_sprite("data/barboss.txt"); 69 sprite = caca_load_sprite("caca.txt"); 70 if(!sprite) 71 sprite = caca_load_sprite("examples/caca.txt"); 70 72 71 73 gdk_init (&argc, &argv); … … 73 75 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/badge1.jpeg", NULL); 74 76 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/union.png", NULL); 75 pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/pikachu.jpeg", NULL); 77 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/pikachu.jpeg", NULL); 78 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/pix/gradient.png", NULL); 79 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/artwork/aboire.png", NULL); 80 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/web/sam.zoy.org/artwork/goret.png", NULL); 81 //pixbuf = gdk_pixbuf_new_from_file("/home/sam/lilkim02.jpg", NULL); 82 pixbuf = gdk_pixbuf_new_from_file("/home/sam/etw.bmp", NULL); 76 83 if(!pixbuf) return -2; 77 84 pixels = gdk_pixbuf_get_pixels(pixbuf); … … 163 170 demo(); 164 171 165 caca_set_color( EE_WHITE);172 caca_set_color(CACA_COLOR_WHITE); 166 173 caca_draw_thin_box(1, 1, caca_get_width() - 2, caca_get_height() - 2); 167 174 caca_printf(4, 1, "[%i.%i fps]----", … … 185 192 186 193 caca_clear(); 187 caca_set_color( EE_WHITE);194 caca_set_color(CACA_COLOR_WHITE); 188 195 caca_draw_thin_box(1, 1, xo, yo); 189 196 … … 222 229 223 230 /* Draw the sun */ 224 caca_set_color( EE_YELLOW);231 caca_set_color(CACA_COLOR_YELLOW); 225 232 xo = caca_get_width() / 4; 226 233 yo = caca_get_height() / 4 + 5 * sin(0.03*i); … … 234 241 235 242 j = 15 + sin(0.03*i) * 8; 236 caca_set_color( EE_WHITE);243 caca_set_color(CACA_COLOR_WHITE); 237 244 caca_fill_ellipse(xo, yo, j, j / 2, '#'); 238 caca_set_color( EE_YELLOW);245 caca_set_color(CACA_COLOR_YELLOW); 239 246 caca_draw_ellipse(xo, yo, j, j / 2, '#'); 240 247 … … 252 259 yc = caca_get_height() * 3 / 4 + cos(0.02*i) * 5; 253 260 254 caca_set_color( EE_GREEN);261 caca_set_color(CACA_COLOR_GREEN); 255 262 caca_fill_triangle(xo, yo, xb, yb, xa, ya, '%'); 256 caca_set_color( EE_YELLOW);263 caca_set_color(CACA_COLOR_YELLOW); 257 264 caca_draw_thin_triangle(xo, yo, xb, yb, xa, ya); 258 265 259 caca_set_color( EE_RED);266 caca_set_color(CACA_COLOR_RED); 260 267 caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#'); 261 caca_set_color( EE_YELLOW);268 caca_set_color(CACA_COLOR_YELLOW); 262 269 caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc); 263 270 264 caca_set_color( EE_BLUE);271 caca_set_color(CACA_COLOR_BLUE); 265 272 caca_fill_triangle(xo, yo, xb, yb, xc, yc, '%'); 266 caca_set_color( EE_YELLOW);273 caca_set_color(CACA_COLOR_YELLOW); 267 274 caca_draw_thin_triangle(xo, yo, xb, yb, xc, yc); 268 275 … … 277 284 yc = caca_get_height() - 3; 278 285 279 caca_set_color( EE_CYAN);286 caca_set_color(CACA_COLOR_CYAN); 280 287 caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc); 281 288 … … 331 338 { 332 339 sprintf(buf, "'%c': %i (%s)", 'a' + i, i, caca_get_color_name(i)); 333 caca_set_color( EE_WHITE);340 caca_set_color(CACA_COLOR_WHITE); 334 341 caca_putstr(4, i + 3, buf); 335 342 caca_set_color(i); … … 458 465 static void demo_blit(void) 459 466 { 460 caca_set_color(EE_LIGHTGRAY);461 467 caca_blit(6, 4, caca_get_width() - 6, caca_get_height() - 4, pixels, bufx, bufy); 462 468 } -
libcaca/trunk/examples/spritedit.c
r192 r193 77 77 caca_clear(); 78 78 79 caca_set_color( EE_WHITE);79 caca_set_color(CACA_COLOR_WHITE); 80 80 caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1); 81 81 … … 97 97 xb = xa + 1 + caca_get_sprite_width(sprite, frame); 98 98 yb = ya + 1 + caca_get_sprite_height(sprite, frame); 99 caca_set_color( EE_BLACK);99 caca_set_color(CACA_COLOR_BLACK); 100 100 caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' '); 101 caca_set_color( EE_WHITE);101 caca_set_color(CACA_COLOR_WHITE); 102 102 caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb); 103 103 caca_draw_sprite(57, 10, sprite, frame); -
libcaca/trunk/src/blit.c
r192 r193 35 35 #include "caca_internals.h" 36 36 37 #include <stdio.h> 37 static enum caca_dithering _caca_dithering = CACA_DITHER_NONE; 38 39 void caca_set_dithering(enum caca_dithering dither) 40 { 41 if(dither < 0 || dither > 1) 42 return; 43 44 _caca_dithering = dither; 45 } 46 38 47 void caca_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h) 39 48 { 40 char foo[] = { ' ', '.', ':', ';', '=', ' $', '%', '@', '#', '8', 'W' };49 char foo[] = { ' ', '.', ':', ';', '=', '%', '$', 'W', '#', '8', '@' }; 41 50 int x, y, pitch; 42 51 … … 56 65 for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= (int)caca_get_width(); x++) 57 66 { 67 static int light_colors[] = {CACA_COLOR_LIGHTMAGENTA, CACA_COLOR_LIGHTRED, CACA_COLOR_YELLOW, CACA_COLOR_LIGHTGREEN, CACA_COLOR_LIGHTCYAN, CACA_COLOR_LIGHTBLUE, CACA_COLOR_LIGHTMAGENTA}; 68 static int dark_colors[] = {CACA_COLOR_MAGENTA, CACA_COLOR_RED, CACA_COLOR_BROWN, CACA_COLOR_GREEN, CACA_COLOR_CYAN, CACA_COLOR_BLUE, CACA_COLOR_MAGENTA}; 58 69 int fromx = w * (x - x1) / (x2 - x1 + 1); 59 70 int fromy = h * (y - y1) / (y2 - y1 + 1); … … 61 72 int g = ((unsigned char *)pixels)[3 * fromx + 1 + pitch * fromy]; 62 73 int b = ((unsigned char *)pixels)[3 * fromx + 2 + pitch * fromy]; 74 int hue, sat, val; 63 75 64 if(r == g && g == b) 76 int min = r, max = r, delta; 77 if(min > g) min = g; if(max < g) max = g; 78 if(min > b) min = b; if(max < b) max = b; 79 80 delta = max - min; 81 val = max; /* 0 - 255 */ 82 sat = max ? 256 * delta / max : 0; /* 0 - 255 */ 83 84 if(sat > caca_rand(64, 128)) 65 85 { 66 caca_set_color(EE_LIGHTGRAY); 86 /* XXX: Values are automatically clipped between 0 and 6 87 * because of delta/2 */ 88 if( r == max ) 89 hue = 1 + (float)(g - b + delta / 2 + caca_rand(-40, 40)) / delta; 90 else if( g == max ) 91 hue = 3 + (float)(b - r + delta / 2 + caca_rand(-40, 40)) / delta; 92 else 93 hue = 5 + (float)(r - g + delta / 2 + caca_rand(-40, 40)) / delta; 94 95 if(val > caca_rand(128, 192)) 96 caca_set_color(light_colors[hue]); 97 else 98 caca_set_color(dark_colors[hue]); 67 99 } 68 100 else 69 101 { 70 static int foo_colors[6] = {EE_LIGHTRED, EE_YELLOW, EE_LIGHTGREEN, EE_LIGHTCYAN, EE_LIGHTBLUE, EE_LIGHTMAGENTA}; 71 float min = r, max = r, delta, hue, sat; 72 if(min > g) min = g; if(max < g) max = g; 73 if(min > b) min = b; if(max < b) max = b; 74 75 delta = max - min; 76 77 sat = max / delta; 78 79 if(delta > 20) 80 { 81 if( r == max ) 82 hue = (g - b) / delta; // between yellow & magenta 83 else if( g == max ) 84 hue = 2 + (b - r) / delta; // between cyan & yellow 85 else 86 hue = 4 + (r - g) / delta; // between magenta & cyan 87 88 hue *= 60; // degrees 89 if( hue < 0 ) 90 hue += 360; 91 92 caca_set_color(foo_colors[(int)(hue + 30) / 60]); 93 } 94 else 95 { 96 caca_set_color(EE_LIGHTGRAY); 97 } 102 caca_set_color(CACA_COLOR_LIGHTGRAY); 98 103 } 99 104 100 caca_putchar(x, y, foo[(r + g + b ) / 3 / 25]);105 caca_putchar(x, y, foo[(r + g + b + caca_rand(-10, 10)) / 3 / 25]); 101 106 } 102 107 } -
libcaca/trunk/src/caca.c
r192 r193 126 126 start_color(); 127 127 128 init_pair(1 + EE_BLACK, COLOR_BLACK, COLOR_BLACK);129 init_pair(1 + EE_BLUE, COLOR_BLUE, COLOR_BLACK);130 init_pair(1 + EE_GREEN, COLOR_GREEN, COLOR_BLACK);131 init_pair(1 + EE_CYAN, COLOR_CYAN, COLOR_BLACK);132 init_pair(1 + EE_RED, COLOR_RED, COLOR_BLACK);133 init_pair(1 + EE_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);134 init_pair(1 + EE_BROWN, COLOR_YELLOW, COLOR_BLACK);135 init_pair(1 + EE_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK);136 init_pair(1 + EE_DARKGRAY, COLOR_BLACK, COLOR_BLACK);137 init_pair(1 + EE_LIGHTBLUE, COLOR_BLUE, COLOR_BLACK);138 init_pair(1 + EE_LIGHTGREEN, COLOR_GREEN, COLOR_BLACK);139 init_pair(1 + EE_LIGHTCYAN, COLOR_CYAN, COLOR_BLACK);140 init_pair(1 + EE_LIGHTRED, COLOR_RED, COLOR_BLACK);141 init_pair(1 + EE_LIGHTMAGENTA, COLOR_MAGENTA, COLOR_BLACK);142 init_pair(1 + EE_YELLOW, COLOR_YELLOW, COLOR_BLACK);143 init_pair(1 + EE_WHITE, COLOR_WHITE, COLOR_BLACK);128 init_pair(1 + CACA_COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); 129 init_pair(1 + CACA_COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); 130 init_pair(1 + CACA_COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); 131 init_pair(1 + CACA_COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); 132 init_pair(1 + CACA_COLOR_RED, COLOR_RED, COLOR_BLACK); 133 init_pair(1 + CACA_COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); 134 init_pair(1 + CACA_COLOR_BROWN, COLOR_YELLOW, COLOR_BLACK); 135 init_pair(1 + CACA_COLOR_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK); 136 init_pair(1 + CACA_COLOR_DARKGRAY, COLOR_BLACK, COLOR_BLACK); 137 init_pair(1 + CACA_COLOR_LIGHTBLUE, COLOR_BLUE, COLOR_BLACK); 138 init_pair(1 + CACA_COLOR_LIGHTGREEN, COLOR_GREEN, COLOR_BLACK); 139 init_pair(1 + CACA_COLOR_LIGHTCYAN, COLOR_CYAN, COLOR_BLACK); 140 init_pair(1 + CACA_COLOR_LIGHTRED, COLOR_RED, COLOR_BLACK); 141 init_pair(1 + CACA_COLOR_LIGHTMAGENTA, COLOR_MAGENTA, COLOR_BLACK); 142 init_pair(1 + CACA_COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); 143 init_pair(1 + CACA_COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); 144 144 145 145 for(i = 0; i < 8; i++) -
libcaca/trunk/src/caca.h
r192 r193 22 22 */ 23 23 24 #ifndef __ EE_H__25 #define __ EE_H__24 #ifndef __CACA_H__ 25 #define __CACA_H__ 26 26 27 27 #ifdef __cplusplus … … 33 33 * Colors 34 34 */ 35 enum caca_color s35 enum caca_color 36 36 { 37 EE_BLACK = 0, 38 EE_BLUE = 1, 39 EE_GREEN = 2, 40 EE_CYAN = 3, 41 EE_RED = 4, 42 EE_MAGENTA = 5, 43 EE_BROWN = 6, 44 EE_LIGHTGRAY = 7, 45 EE_DARKGRAY = 8, 46 EE_LIGHTBLUE = 9, 47 EE_LIGHTGREEN = 10, 48 EE_LIGHTCYAN = 11, 49 EE_LIGHTRED = 12, 50 EE_LIGHTMAGENTA = 13, 51 EE_YELLOW = 14, 52 EE_WHITE = 15 37 CACA_COLOR_BLACK = 0, 38 CACA_COLOR_BLUE = 1, 39 CACA_COLOR_GREEN = 2, 40 CACA_COLOR_CYAN = 3, 41 CACA_COLOR_RED = 4, 42 CACA_COLOR_MAGENTA = 5, 43 CACA_COLOR_BROWN = 6, 44 CACA_COLOR_LIGHTGRAY = 7, 45 CACA_COLOR_DARKGRAY = 8, 46 CACA_COLOR_LIGHTBLUE = 9, 47 CACA_COLOR_LIGHTGREEN = 10, 48 CACA_COLOR_LIGHTCYAN = 11, 49 CACA_COLOR_LIGHTRED = 12, 50 CACA_COLOR_LIGHTMAGENTA = 13, 51 CACA_COLOR_YELLOW = 14, 52 CACA_COLOR_WHITE = 15 53 }; 54 55 /* 56 * Dithering modes 57 */ 58 enum caca_dithering 59 { 60 CACA_DITHER_NONE = 0, 61 CACA_DITHER_RANDOM = 1 53 62 }; 54 63 … … 63 72 int caca_init(void); 64 73 void caca_set_delay(unsigned int); 74 void caca_set_dithering(enum caca_dithering); 65 75 unsigned int caca_get_rendertime(void); 66 76 unsigned int caca_get_width(void); … … 72 82 char caca_get_key(void); 73 83 74 void caca_set_color( int);75 intcaca_get_color(void);84 void caca_set_color(enum caca_color); 85 enum caca_color caca_get_color(void); 76 86 void caca_putchar(int, int, char); 77 87 void caca_putstr(int, int, const char *); … … 115 125 #endif 116 126 117 #endif /* __ EE_H__ */127 #endif /* __CACA_H__ */ -
libcaca/trunk/src/caca_internals.h
r192 r193 22 22 */ 23 23 24 #ifndef __ EE_INTERNALS_H__25 #define __ EE_INTERNALS_H__24 #ifndef __CACA_INTERNALS_H__ 25 #define __CACA_INTERNALS_H__ 26 26 27 27 #if defined(USE_NCURSES) … … 36 36 extern char *_caca_scratch_line; 37 37 38 #endif /* __ EE_INTERNALS_H__ */38 #endif /* __CACA_INTERNALS_H__ */ -
libcaca/trunk/src/graphics.c
r192 r193 41 41 #include "caca_internals.h" 42 42 43 static int _caca_color = 0;43 static enum caca_color _caca_color = CACA_COLOR_WHITE; 44 44 45 void caca_set_color( intcolor)45 void caca_set_color(enum caca_color color) 46 46 { 47 47 if(color < 0 || color > 15) … … 58 58 } 59 59 60 intcaca_get_color(void)60 enum caca_color caca_get_color(void) 61 61 { 62 62 return _caca_color;
Note: See TracChangeset
for help on using the changeset viewer.