/* Transitions */ void transition(caca_canvas_t *mask, int tmode, int completed) { static float const star[] = { 0.000000, -1.000000, 0.308000, -0.349000, 0.992000, -0.244000, 0.500000, 0.266000, 0.632000, 0.998000, 0.008000, 0.659000, -0.601000, 0.995000, -0.496000, 0.275000, -0.997000, -0.244000, -0.313000, -0.349000 }; static float star_rot[sizeof(star)/sizeof(*star)]; static float const square[] = { -1, -1, 1, -1, 1, 1, -1, 1 }; static float square_rot[sizeof(square)/sizeof(*square)]; float mulx = 0.0075f * completed * caca_get_canvas_width(mask); float muly = 0.0075f * completed * caca_get_canvas_height(mask); int w2 = caca_get_canvas_width(mask) / 2; int h2 = caca_get_canvas_height(mask) / 2; float angle = (0.0075f * completed * 360) * 3.14 / 180, x, y; unsigned int i; int w = caca_get_canvas_width(mask); int h = caca_get_canvas_height(mask); switch(tmode) { case TRANSITION_SQUARE: /* Compute rotated coordinates */ for(i = 0; i < (sizeof(square) / sizeof(*square)) / 2; i++) { x = square[i * 2]; y = square[i * 2 + 1]; square_rot[i * 2] = x * cos(angle) - y * sin(angle); square_rot[i * 2 + 1] = y * cos(angle) + x * sin(angle); } mulx *= 1.8; muly *= 1.8; caca_fill_triangle(mask, square_rot[0*2] * mulx + w2, square_rot[0*2+1] * muly + h2, \ square_rot[1*2] * mulx + w2, square_rot[1*2+1] * muly + h2, \ square_rot[2*2] * mulx + w2, square_rot[2*2+1] * muly + h2, '#'); caca_fill_triangle(mask, square_rot[0*2] * mulx + w2, square_rot[0*2+1] * muly + h2, \ square_rot[2*2] * mulx + w2, square_rot[2*2+1] * muly + h2, \ square_rot[3*2] * mulx + w2, square_rot[3*2+1] * muly + h2, '#'); break; case TRANSITION_STAR: /* Compute rotated coordinates */ for(i = 0; i < (sizeof(star) / sizeof(*star)) / 2; i++) { x = star[i * 2]; y = star[i * 2 + 1]; star_rot[i * 2] = x * cos(angle) - y * sin(angle); star_rot[i * 2 + 1] = y * cos(angle) + x * sin(angle); } mulx *= 1.8; muly *= 1.8; #define DO_TRI(a, b, c) \ caca_fill_triangle(mask, \ star_rot[(a)*2] * mulx + w2, star_rot[(a)*2+1] * muly + h2, \ star_rot[(b)*2] * mulx + w2, star_rot[(b)*2+1] * muly + h2, \ star_rot[(c)*2] * mulx + w2, star_rot[(c)*2+1] * muly + h2, '#') DO_TRI(0, 1, 9); DO_TRI(1, 2, 3); DO_TRI(3, 4, 5); DO_TRI(5, 6, 7); DO_TRI(7, 8, 9); DO_TRI(9, 1, 5); DO_TRI(9, 5, 7); DO_TRI(1, 3, 5); break; case TRANSITION_CIRCLE: caca_fill_ellipse(mask, w2, h2, mulx, muly, '#'); break; case TRANSITION_VLINES: for(i = 0; i < 8; i++) { int z = ((i & 1) ? w : (-w)/2) * (100 - completed) / 100; caca_fill_box(mask, i * w / 8, z , (w / 8) + 1, z + h, '#'); } break; case TRANSITION_HLINES: for(i = 0; i < 6; i++) { int z = ((i & 1) ? w : (-w)/2) * (100 - completed) / 100; caca_fill_box(mask, z, i * h / 6, z + w, (h / 6) + 1, '#'); } break; } }
int main(int argc, char *argv[]) { caca_canvas_t *cv; caca_dither_t *dither; void *buffer; char *file, *format; char const * const * exports, * const * p; size_t len; int x, y; exports = caca_get_export_list(); if(argc < 2 || argc > 3) { fprintf(stderr, "%s: wrong argument count\n", argv[0]); fprintf(stderr, "usage: %s [file] <format>\n", argv[0]); fprintf(stderr, "where <format> is one of:\n"); for(p = exports; *p; p += 2) fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1)); exit(-1); } if(argc == 2) { file = NULL; format = argv[1]; } else { file = argv[1]; format = argv[2]; } for(p = exports; *p; p += 2) if(!strcasecmp(format, *p)) break; if(!*p) { fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format); fprintf(stderr, "please use one of:\n"); for(p = exports; *p; p += 2) fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1)); exit(-1); } if(file) { cv = caca_create_canvas(0, 0); if(caca_import_canvas_from_file(cv, file, "") < 0) { fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file); exit(-1); } } else { cv = caca_create_canvas(WIDTH, HEIGHT); for(y = 0; y < 256; y++) { for(x = 0; x < 256; x++) { uint32_t r = x; uint32_t g = (255 - y + x) / 2; uint32_t b = y * (255 - x) / 256; pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0); } } dither = caca_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); if(!strcmp(format, "ansi") || !strcmp(format, "utf8")) caca_set_dither_charset(dither, "shades"); caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv), caca_get_canvas_height(cv), dither, pixels); caca_free_dither(dither); caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK); caca_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1); caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE); caca_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, ' '); caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK); caca_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 6, " lightgray on black "); caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT); caca_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 5, " default on transparent "); caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE); caca_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 4, " black on white "); caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE); caca_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]"); caca_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]"); caca_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); caca_put_str(cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>"); caca_set_attr(cv, CACA_BOLD); caca_put_str(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold"); caca_set_attr(cv, CACA_BLINK); caca_put_str(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink"); caca_set_attr(cv, CACA_ITALICS); caca_put_str(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics"); caca_set_attr(cv, CACA_UNDERLINE); caca_put_str(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline"); caca_set_attr(cv, 0); caca_set_color_ansi(cv, CACA_WHITE, CACA_LIGHTBLUE); caca_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); for(x = 0; x < 16; x++) { caca_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4)); caca_put_char(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 6, '#'); } } buffer = caca_export_canvas_to_memory(cv, format, &len); fwrite(buffer, len, 1, stdout); free(buffer); caca_free_canvas(cv); return 0; }
JNIEXPORT void JNICALL Java_org_zoy_caca_Canvas_canvasFillEllipse(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y, jint a, jint b, jint ch) { caca_fill_ellipse((caca_canvas_t *)ptr, x, y, a, b, ch); }