Changeset 151
- Timestamp:
- Nov 11, 2003, 11:22:19 AM (20 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/libee/Makefile.am
r147 r151 11 11 math.c \ 12 12 line.c \ 13 box.c \ 13 14 conic.c \ 14 15 triangle.c \ -
libcaca/trunk/libee/conic.c
r147 r151 50 50 } 51 51 52 void ee_ draw_ellipse(int xo, int yo, int a, int b, char c)52 void ee_fill_ellipse(int xo, int yo, int a, int b, char c) 53 53 { 54 54 int d2; … … 57 57 int d1 = b*b - (a*a*b) + (a*a/4); 58 58 59 while( a*a*y - a*a/2 > b*b*(x+1)) 60 { 61 if(d1 < 0) 62 { 63 d1 += b*b*(2*x+1); /* XXX: "Computer Graphics" has + 3 here. */ 64 } 65 else 66 { 67 d1 += b*b*(2*x*1) + a*a*(-2*y+2); 68 ee_draw_line(xo - x, yo - y, xo + x, yo - y, c); 69 ee_draw_line(xo - x, yo + y, xo + x, yo + y, c); 70 y--; 71 } 72 x++; 73 } 74 75 ee_draw_line(xo - x, yo - y, xo + x, yo - y, c); 76 ee_draw_line(xo - x, yo + y, xo + x, yo + y, c); 77 78 d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; 79 while(y > 0) 80 { 81 if(d2 < 0) 82 { 83 d2 += b*b*(2*x+2) + a*a*(-2*y+3); 84 x++; 85 } 86 else 87 { 88 d2 += a*a*(-2*y+3); 89 } 90 91 y--; 92 ee_draw_line(xo - x, yo - y, xo + x, yo - y, c); 93 ee_draw_line(xo - x, yo + y, xo + x, yo + y, c); 94 } 95 } 96 97 void ee_draw_ellipse(int xo, int yo, int a, int b, char c) 98 { 99 int d2; 100 int x = 0; 101 int y = b; 102 int d1 = b*b - (a*a*b) + (a*a/4); 103 59 104 ellipsepoints(xo, yo, x, y, c); 60 105 … … 89 134 y--; 90 135 ellipsepoints(xo, yo, x, y, c); 136 } 137 } 138 139 void ee_draw_thin_ellipse(int xo, int yo, int a, int b) 140 { 141 /* FIXME: this is not correct */ 142 int d2; 143 int x = 0; 144 int y = b; 145 int d1 = b*b - (a*a*b) + (a*a/4); 146 147 ellipsepoints(xo, yo, x, y, '-'); 148 149 while( a*a*y - a*a/2 > b*b*(x+1)) 150 { 151 if(d1 < 0) 152 { 153 d1 += b*b*(2*x+1); /* XXX: "Computer Graphics" has + 3 here. */ 154 } 155 else 156 { 157 d1 += b*b*(2*x*1) + a*a*(-2*y+2); 158 y--; 159 } 160 x++; 161 ellipsepoints(xo, yo, x, y, '-'); 162 } 163 164 d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; 165 while(y > 0) 166 { 167 if(d2 < 0) 168 { 169 d2 += b*b*(2*x+2) + a*a*(-2*y+3); 170 x++; 171 } 172 else 173 { 174 d2 += a*a*(-2*y+3); 175 } 176 177 y--; 178 ellipsepoints(xo, yo, x, y, '|'); 91 179 } 92 180 } -
libcaca/trunk/libee/ee.h
r147 r151 59 59 void ee_draw_line(int, int, int, int, char); 60 60 void ee_draw_thin_line(int, int, int, int); 61 61 62 void ee_draw_circle(int, int, int, char); 62 63 void ee_draw_ellipse(int, int, int, int, char); 64 void ee_draw_thin_ellipse(int, int, int, int); 65 void ee_fill_ellipse(int, int, int, int, char); 66 67 void ee_draw_box(int, int, int, int, char); 68 void ee_draw_thin_box(int, int, int, int); 69 void ee_fill_box(int, int, int, int, char); 70 71 void ee_draw_triangle(int, int, int, int, int, int, char); 72 void ee_draw_thin_triangle(int, int, int, int, int, int); 63 73 void ee_fill_triangle(int, int, int, int, int, int, char); 64 74 -
libcaca/trunk/libee/triangle.c
r147 r151 32 32 33 33 #include "ee.h" 34 35 void ee_draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c) 36 { 37 ee_draw_line(x1, y1, x2, y2, c); 38 ee_draw_line(x2, y2, x3, y3, c); 39 ee_draw_line(x3, y3, x1, y1, c); 40 } 41 42 void ee_draw_thin_triangle(int x1, int y1, int x2, int y2, int x3, int y3) 43 { 44 ee_draw_thin_line(x1, y1, x2, y2); 45 ee_draw_thin_line(x2, y2, x3, y3); 46 ee_draw_thin_line(x3, y3, x1, y1); 47 } 34 48 35 49 void ee_fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c) -
libcaca/trunk/test/demo.c
r147 r151 34 34 static void demo_dots(void); 35 35 static void demo_lines(void); 36 static void demo_thin_lines(void); 37 static void demo_circles(void); 36 static void demo_boxes(void); 38 37 static void demo_ellipses(void); 39 38 static void demo_triangles(void); 40 static void demo_outlined_triangles(void);41 39 static void demo_sprites(void); 42 40 43 41 int force_clipping = 0; 42 int outline = 0; 43 int thin = 0; 44 44 struct ee_sprite *sprite = NULL; 45 45 … … 88 88 ee_clear(); 89 89 demo = demo_lines; 90 thin = 0; 90 91 break; 91 92 case '3': 92 93 ee_clear(); 93 demo = demo_thin_lines; 94 demo = demo_lines; 95 thin = 1; 94 96 break; 95 97 case '4': 96 98 ee_clear(); 97 demo = demo_circles; 99 demo = demo_boxes; 100 outline = 0; 98 101 break; 99 102 case '5': 100 103 ee_clear(); 104 demo = demo_boxes; 105 outline = 1; 106 break; 107 case '6': 108 ee_clear(); 101 109 demo = demo_ellipses; 102 110 break; 103 case ' 6':111 case '7': 104 112 ee_clear(); 105 113 demo = demo_triangles; 106 break; 107 case '7': 108 ee_clear(); 109 demo = demo_outlined_triangles; 114 outline = 0; 110 115 break; 111 116 case '8': 117 ee_clear(); 118 demo = demo_triangles; 119 outline = 1; 120 break; 121 case '9': 112 122 ee_clear(); 113 123 demo = demo_sprites; … … 146 156 ee_putstr(4, 8, "2: lines demo"); 147 157 ee_putstr(4, 9, "3: thin lines demo"); 148 ee_putstr(4, 10, "4: circles demo"); 149 ee_putstr(4, 11, "5: ellipses demo"); 150 ee_putstr(4, 12, "6: triangles demo"); 151 ee_putstr(4, 13, "7: outlined triangles demo"); 152 ee_putstr(4, 14, "8: sprites demo"); 158 ee_putstr(4, 10, "4: boxes demo"); 159 ee_putstr(4, 11, "5: outlined boxes demo"); 160 ee_putstr(4, 12, "6: ellipses demo"); 161 ee_putstr(4, 13, "7: triangles demo"); 162 ee_putstr(4, 14, "8: outlined triangles demo"); 163 ee_putstr(4, 15, "9: sprites demo"); 153 164 154 165 ee_putstr(4, yo - 2, "q: quit"); … … 179 190 } 180 191 192 j = 15 + sin(0.03*i) * 8; 181 193 ee_color(EE_WHITE); 182 for(j = 15 + sin(0.03*i) * 8; j--;) 183 { 184 ee_draw_circle(xo, yo, j, '#'); 185 } 186 194 ee_fill_ellipse(xo, yo, j, j / 2, '#'); 187 195 ee_color(EE_YELLOW); 188 ee_draw_ circle(xo, yo, 15 + sin(0.03*i) * 8, '#');196 ee_draw_ellipse(xo, yo, j, j / 2, '#'); 189 197 190 198 /* Draw the pyramid */ … … 204 212 ee_fill_triangle(xo, yo, x2, y2, x1, y1, '%'); 205 213 ee_color(EE_YELLOW); 206 ee_draw_thin_line(xo, yo, x2, y2); 207 ee_draw_thin_line(x2, y2, x1, y1); 208 ee_draw_thin_line(x1, y1, xo, yo); 214 ee_draw_thin_triangle(xo, yo, x2, y2, x1, y1); 209 215 210 216 ee_color(EE_RED); 211 217 ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#'); 212 218 ee_color(EE_YELLOW); 213 ee_draw_thin_line(x1, y1, x2, y2); 214 ee_draw_thin_line(x2, y2, x3, y3); 215 ee_draw_thin_line(x3, y3, x1, y1); 219 ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3); 216 220 217 221 ee_color(EE_BLUE); 218 222 ee_fill_triangle(xo, yo, x2, y2, x3, y3, '%'); 219 223 ee_color(EE_YELLOW); 220 ee_draw_thin_line(xo, yo, x2, y2); 221 ee_draw_thin_line(x2, y2, x3, y3); 222 ee_draw_thin_line(x3, y3, xo, yo); 224 ee_draw_thin_triangle(xo, yo, x2, y2, x3, y3); 223 225 224 226 /* Draw a background triangle */ … … 232 234 y3 = ee_get_height() - 3; 233 235 234 ee_color(EE_BLUE);235 // ee_fill_triangle(x1, y1, x2, y2, x3, y3, '.');236 236 ee_color(EE_CYAN); 237 ee_draw_thin_line(x1, y1, x3, y3); 238 ee_draw_thin_line(x2, y2, x1, y1); 239 ee_draw_thin_line(x3, y3, x2, y2); 237 ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3); 240 238 241 239 xo = ee_get_width() / 2 + cos(0.027*i) * ee_get_width() / 3; … … 246 244 ee_draw_thin_line(x3, y3, xo, yo); 247 245 248 /* Draw a sprite behindthe pyramid */246 /* Draw a sprite on the pyramid */ 249 247 ee_draw_sprite(xo, yo, sprite); 250 248 … … 288 286 int w = ee_get_width(); 289 287 int h = ee_get_height(); 290 291 /* Draw lines */ 288 int x1, y1, x2, y2; 289 290 if(force_clipping) 291 { 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); 294 } 295 else 296 { 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 292 301 ee_color(ee_rand(1, 10)); 293 if(force_clipping) 294 { 295 ee_draw_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), 296 ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#'); 297 } 302 if(thin) 303 ee_draw_thin_line(x1, y1, x2, y2); 298 304 else 299 { 300 ee_draw_line(ee_rand(0, w - 1), ee_rand(0, h - 1), 301 ee_rand(0, w - 1), ee_rand(0, h - 1), '#'); 302 } 303 ee_refresh(); 304 } 305 306 static void demo_thin_lines(void) 305 ee_draw_line(x1, y1, x2, y2, '#'); 306 307 ee_refresh(); 308 } 309 310 static void demo_boxes(void) 307 311 { 308 312 int w = ee_get_width(); 309 313 int h = ee_get_height(); 310 311 /* Draw lines */ 314 int x1, y1, x2, y2; 315 316 if(force_clipping) 317 { 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); 320 } 321 else 322 { 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 312 327 ee_color(ee_rand(1, 10)); 313 if(force_clipping) 314 { 315 ee_draw_thin_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), 316 ee_rand(- w, 2 * w), ee_rand(- h, 2 * h)); 317 } 318 else 319 { 320 ee_draw_thin_line(ee_rand(0, w), ee_rand(0, h), 321 ee_rand(0, w), ee_rand(0, h)); 322 } 323 ee_refresh(); 324 } 325 326 static void demo_circles(void) 328 ee_fill_box(x1, y1, x2, y2, '#'); 329 330 if(outline) 331 { 332 ee_color(ee_rand(1, 10)); 333 ee_draw_thin_box(x1, y1, x2, y2); 334 } 335 336 ee_refresh(); 337 } 338 339 static void demo_ellipses(void) 327 340 { 328 341 int w = ee_get_width(); 329 342 int h = ee_get_height(); 330 331 /* Draw circles */ 343 int x, y, a, b; 344 332 345 if(force_clipping) 333 346 { 347 x = ee_rand(- w, 2 * w); y = ee_rand(- h, 2 * h); 348 a = ee_rand(0, w); b = ee_rand(0, h); 349 } 350 else 351 { 352 do 353 { 354 x = ee_rand(0, w); y = ee_rand(0, h); 355 a = ee_rand(0, w); b = ee_rand(0, h); 356 357 } while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h); 358 } 359 360 ee_color(ee_rand(1, 10)); 361 ee_fill_ellipse(x, y, a, b, '#'); 362 363 if(outline) 364 { 334 365 ee_color(ee_rand(1, 10)); 335 ee_draw_circle(ee_rand(- w, 2 * w), 336 ee_rand(- h, 2 * h), 337 ee_rand(0, (w + h) / 2), 338 '#'); 339 } 340 else 341 { 342 int x = ee_rand(0, w); 343 int y = ee_rand(0, h); 344 int r = ee_rand(0, (w + h) / 2); 345 346 if(x - r < 0 || x + r >= w || y - r < 0 || y + r >= h) 347 { 348 demo_circles(); 349 return; 350 } 351 352 ee_color(ee_rand(1, 10)); 353 ee_draw_circle(x, y, r, '#'); 354 } 355 356 ee_refresh(); 357 } 358 359 static void demo_ellipses(void) 360 { 361 int w = ee_get_width(); 362 int h = ee_get_height(); 363 364 /* Draw circles */ 365 if(force_clipping) 366 { 367 ee_color(ee_rand(1, 10)); 368 ee_draw_ellipse(ee_rand(- w, 2 * w), 369 ee_rand(- h, 2 * h), 370 ee_rand(0, w), 371 ee_rand(0, h), 372 '#'); 373 } 374 else 375 { 376 int x = ee_rand(0, w); 377 int y = ee_rand(0, h); 378 int a = ee_rand(0, w); 379 int b = ee_rand(0, h); 380 381 if(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h) 382 { 383 demo_ellipses(); 384 return; 385 } 386 387 ee_color(ee_rand(1, 10)); 388 ee_draw_ellipse(x, y, a, b, '#'); 366 ee_draw_thin_ellipse(x, y, a, b); 389 367 } 390 368 … … 393 371 394 372 static void demo_triangles(void) 395 {396 int w = ee_get_width();397 int h = ee_get_height();398 399 /* Draw lines */400 ee_color(ee_rand(1, 10));401 if(force_clipping)402 {403 ee_fill_triangle(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),404 ee_rand(- w, 2 * w), ee_rand(- h, 2 * h),405 ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#');406 }407 else408 {409 ee_fill_triangle(ee_rand(0, w - 1), ee_rand(0, h - 1),410 ee_rand(0, w - 1), ee_rand(0, h - 1),411 ee_rand(0, w - 1), ee_rand(0, h - 1), '#');412 }413 ee_refresh();414 }415 416 static void demo_outlined_triangles(void)417 373 { 418 374 int w = ee_get_width(); … … 420 376 int x1, y1, x2, y2, x3, y3; 421 377 422 /* Draw lines */ 378 if(force_clipping) 379 { 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); 383 } 384 else 385 { 386 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 423 392 ee_color(ee_rand(1, 10)); 424 if(force_clipping)425 {426 x1 = ee_rand(- w, 2 * w);427 y1 = ee_rand(- h, 2 * h);428 x2 = ee_rand(- w, 2 * w);429 y2 = ee_rand(- h, 2 * h);430 x3 = ee_rand(- w, 2 * w);431 y3 = ee_rand(- h, 2 * h);432 }433 else434 {435 436 x1 = ee_rand(0, w - 1);437 y1 = ee_rand(0, h - 1);438 x2 = ee_rand(0, w - 1);439 y2 = ee_rand(0, h - 1);440 x3 = ee_rand(0, w - 1);441 y3 = ee_rand(0, h - 1);442 }443 444 393 ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#'); 445 394 446 ee_color(ee_rand(1, 10)); 447 ee_draw_thin_line(x1, y1, x2, y2); 448 ee_draw_thin_line(x2, y2, x3, y3); 449 ee_draw_thin_line(x3, y3, x1, y1); 395 if(outline) 396 { 397 ee_color(ee_rand(1, 10)); 398 ee_draw_thin_triangle(x1, y1, x2, y2, x3, y3); 399 } 450 400 451 401 ee_refresh(); … … 459 409 } 460 410 461 static void demo_pyramid(void)462 {463 static int i = 0;464 465 int xo, yo, x1, y1, x2, y2, x3, y3;466 467 i++;468 469 xo = ee_get_width() * 5 / 8;470 yo = 2;471 472 x1 = ee_get_width() / 8 + sin(0.03*i) * 5;473 y1 = ee_get_height() / 2 + cos(0.03*i) * 5;474 475 x2 = ee_get_width() - 10 - cos(0.02*i) * 10;476 y2 = ee_get_height() - 5 + sin(0.02*i) * 5;477 478 x3 = ee_get_width() / 4 - sin(0.02*i) * 5;479 y3 = ee_get_height() + cos(0.02*i) * 5;480 481 ee_clear();482 483 ee_color(EE_GREEN);484 ee_fill_triangle(xo, yo, x2, y2, x1, y1, '%');485 ee_color(EE_YELLOW);486 ee_draw_thin_line(xo, yo, x2, y2);487 ee_draw_thin_line(x2, y2, x1, y1);488 ee_draw_thin_line(x1, y1, xo, yo);489 490 ee_color(EE_RED);491 ee_fill_triangle(x1, y1, x2, y2, x3, y3, '#');492 ee_color(EE_YELLOW);493 ee_draw_thin_line(x1, y1, x2, y2);494 ee_draw_thin_line(x2, y2, x3, y3);495 ee_draw_thin_line(x3, y3, x1, y1);496 497 ee_color(EE_BLUE);498 ee_fill_triangle(xo, yo, x2, y2, x3, y3, '%');499 ee_color(EE_YELLOW);500 ee_draw_thin_line(xo, yo, x2, y2);501 ee_draw_thin_line(x2, y2, x3, y3);502 ee_draw_thin_line(x3, y3, xo, yo);503 504 ee_refresh();505 }506
Note: See TracChangeset
for help on using the changeset viewer.