Changeset 1038
- Timestamp:
- Sep 17, 2006, 1:34:18 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/cacademo.c
r1037 r1038 64 64 #define OFFSET_Y(i) (i*2)+1 65 65 66 float star[] = {67 0.000000, -1.000000,68 0.308000,-0.349000,69 0.992000,-0.244000,70 0.500000,0.266000,71 0.632000,0.998000,72 0.008000,0.659000,73 -0.601000,0.995000,74 -0.496000,0.275000,75 -0.997000,-0.244000,76 -0.313000,-0.34900077 };78 79 float star_rot[sizeof(star)/sizeof(*star)];80 81 66 /* Global variables */ 82 67 static int frame = 0; … … 212 197 void do_transition(cucul_canvas_t *mask, int transition, float time) 213 198 { 214 float mulx = time*cucul_get_canvas_width(mask); 215 float muly = time*cucul_get_canvas_height(mask); 199 static float const star[] = 200 { 201 0.000000, -1.000000, 202 0.308000, -0.349000, 203 0.992000, -0.244000, 204 0.500000, 0.266000, 205 0.632000, 0.998000, 206 0.008000, 0.659000, 207 -0.601000, 0.995000, 208 -0.496000, 0.275000, 209 -0.997000, -0.244000, 210 -0.313000, -0.349000 211 }; 212 static float star_rot[sizeof(star)/sizeof(*star)]; 213 214 float mulx = time * cucul_get_canvas_width(mask); 215 float muly = time * cucul_get_canvas_height(mask); 216 216 int w2 = cucul_get_canvas_width(mask) / 2; 217 217 int h2 = cucul_get_canvas_height(mask) / 2; … … 438 438 static double offset[360 + 80]; 439 439 440 int p, angle;440 int n, angle; 441 441 442 442 switch(action) … … 444 444 case PREPARE: 445 445 /* Make the palette eatable by libcaca */ 446 for( p = 0; p < 256; p++)447 r[ p] = g[p] = b[p] = a[p] = 0x0;446 for(n = 0; n < 256; n++) 447 r[n] = g[n] = b[n] = a[n] = 0x0; 448 448 r[255] = g[255] = b[255] = 0xfff; 449 449 … … 451 451 create_ball(); 452 452 453 for( p = 0; p < METABALLS; p++)454 { 455 dd[ p] = cucul_rand(0, 100);456 di[ p] = (float)cucul_rand(500, 4000) / 6000.0;457 dj[ p] = (float)cucul_rand(500, 4000) / 6000.0;458 dk[ p] = (float)cucul_rand(500, 4000) / 6000.0;459 } 460 461 for( p = 0; p < 360 + 80; p++)462 offset[ p] = 1.0 + sin((double)(p* M_PI / 60));453 for(n = 0; n < METABALLS; n++) 454 { 455 dd[n] = cucul_rand(0, 100); 456 di[n] = (float)cucul_rand(500, 4000) / 6000.0; 457 dj[n] = (float)cucul_rand(500, 4000) / 6000.0; 458 dk[n] = (float)cucul_rand(500, 4000) / 6000.0; 459 } 460 461 for(n = 0; n < 360 + 80; n++) 462 offset[n] = 1.0 + sin((double)(n * M_PI / 60)); 463 463 break; 464 464 … … 475 475 476 476 /* Crop the palette */ 477 for( p = CROPBALL; p < 255; p++)477 for(n = CROPBALL; n < 255; n++) 478 478 { 479 479 int t1, t2, t3; … … 482 482 double c3 = offset[angle + 80]; 483 483 484 t1 = p < 0x40 ? 0 : p < 0xc0 ? (p- 0x40) * 0x20 : 0xfff;485 t2 = p < 0xe0 ? 0 : (p- 0xe0) * 0x80;486 t3 = p < 0x40 ? p* 0x40 : 0xfff;487 488 r[ p] = (c1 * t1 + c2 * t2 + c3 * t3) / 4;489 g[ p] = (c1 * t2 + c2 * t3 + c3 * t1) / 4;490 b[ p] = (c1 * t3 + c2 * t1 + c3 * t2) / 4;484 t1 = n < 0x40 ? 0 : n < 0xc0 ? (n - 0x40) * 0x20 : 0xfff; 485 t2 = n < 0xe0 ? 0 : (n - 0xe0) * 0x80; 486 t3 = n < 0x40 ? n * 0x40 : 0xfff; 487 488 r[n] = (c1 * t1 + c2 * t2 + c3 * t3) / 4; 489 g[n] = (c1 * t2 + c2 * t3 + c3 * t1) / 4; 490 b[n] = (c1 * t3 + c2 * t1 + c3 * t2) / 4; 491 491 } 492 492 … … 495 495 496 496 /* Silly paths for our balls */ 497 for( p = 0; p < METABALLS; p++)498 { 499 float u = di[ p] * i + dj[p] * j + dk[p] * sin(di[p] * k);500 float v = dd[ p] + di[p] * j + dj[p] * k + dk[p] * sin(dk[p] * i);497 for(n = 0; n < METABALLS; n++) 498 { 499 float u = di[n] * i + dj[n] * j + dk[n] * sin(di[n] * k); 500 float v = dd[n] + di[n] * j + dj[n] * k + dk[n] * sin(dk[n] * i); 501 501 u = sin(i + u * 2.1) * (1.0 + sin(u)); 502 502 v = sin(j + v * 1.9) * (1.0 + sin(v)); 503 x[ p] = (XSIZ - METASIZE) / 2 + u * (XSIZ - METASIZE) / 4;504 y[ p] = (YSIZ - METASIZE) / 2 + v * (YSIZ - METASIZE) / 4;503 x[n] = (XSIZ - METASIZE) / 2 + u * (XSIZ - METASIZE) / 4; 504 y[n] = (YSIZ - METASIZE) / 2 + v * (YSIZ - METASIZE) / 4; 505 505 } 506 506 … … 511 511 memset(screen, 0, XSIZ * YSIZ); 512 512 513 /* Here is all the trick. Maybe if you're that 514 * clever you'll understand. */ 515 for(p = 0; p < METABALLS; p++) 516 draw_ball(screen, x[p], y[p]); 513 for(n = 0; n < METABALLS; n++) 514 draw_ball(screen, x[n], y[n]); 517 515 break; 518 516 … … 531 529 } 532 530 533 /* Generate ball sprite534 * You should read the comments, I already wrote that before ... */535 531 static void create_ball(void) 536 532 { … … 548 544 } 549 545 550 /* You missed the trick ? */551 546 static void draw_ball(uint8_t *screen, unsigned int bx, unsigned int by) 552 547 { … … 579 574 580 575 static void put_disc(uint8_t *, int, int); 581 static void draw_disc(int, char);582 576 static void draw_line(int, int, char); 583 577 … … 602 596 /* Fill the circle */ 603 597 for(i = DISCSIZ * 2; i > 0; i -= DISCTHICKNESS) 604 draw_disc(i, (i / DISCTHICKNESS) % 2); 598 { 599 int t, dx, dy; 600 601 for(t = 0, dx = 0, dy = i; dx <= dy; dx++) 602 { 603 draw_line(dx / 3, dy / 3, (i / DISCTHICKNESS) % 2); 604 draw_line(dy / 3, dx / 3, (i / DISCTHICKNESS) % 2); 605 606 t += t > 0 ? dx - dy-- : dx; 607 } 608 } 605 609 606 610 break; … … 658 662 { 659 663 screen[i + XSIZ * j] ^= src[i + DISCSIZ * j]; 660 }661 }662 663 static void draw_disc(int r, char color)664 {665 int t, dx, dy;666 667 for(t = 0, dx = 0, dy = r; dx <= dy; dx++)668 {669 draw_line(dx / 3, dy / 3, color);670 draw_line(dy / 3, dx / 3, color);671 672 t += t > 0 ? dx - dy-- : dx;673 664 } 674 665 } … … 781 772 #define MAXLEN 30 782 773 783 struct drop784 {785 int x, y, speed, len;786 char str[MAXLEN];787 }788 drop[MAXDROPS];789 790 774 void matrix(enum action action, cucul_canvas_t *cv) 791 775 { 792 static int w, h; 793 794 int i, j; 776 static struct drop 777 { 778 int x, y, speed, len; 779 char str[MAXLEN]; 780 } 781 drop[MAXDROPS]; 782 783 int w, h, i, j; 795 784 796 785 switch(action) … … 827 816 828 817 case RENDER: 818 w = cucul_get_canvas_width(cv); 819 h = cucul_get_canvas_height(cv); 820 829 821 cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK); 830 822 cucul_clear_canvas(cv);
Note: See TracChangeset
for help on using the changeset viewer.