JNIEXPORT void JNICALL Java_org_zoy_caca_Canvas_canvasFillTriangle(JNIEnv *env, jclass cls, jlong ptr, jint x1, jint y1, jint x2, jint y2, jint x3, jint y3, jint ch) { caca_fill_triangle((caca_canvas_t *)ptr, x1, y1, x2, y2, x3, y3, ch); }
int main(void) { caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev; // Create canvas and display cv = caca_create_canvas(100,80); if(!cv) return 1; dp = caca_create_display_with_driver(cv, "ncurses"); if(!dp) return 1; caca_set_display_title(dp, "WPC 66"); caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK); // Tree stump caca_fill_box (cv, 47, 50, 6, 4, '|'); // Tree body caca_draw_thin_triangle (cv,50,10,10,50,90,50); // Pot caca_fill_triangle(cv, 35, 53, 40, 60, 40, 53, '@'); caca_fill_box(cv, 40, 53, 19, 8, '@'); caca_fill_triangle(cv, 59, 60, 64, 53, 59, 53, '@'); // Balls int balls[] = {50, 25, 35, 35, 25, 43, 58, 32, 68, 41, 50, 46}; for (int i = 0; i <= 10; i += 2) caca_draw_thin_ellipse(cv, balls[i], balls[i+1], 2, 2); // Sparkly stuff int sparks[] = {54, 20, 42, 30, 40, 45, 46, 38, 60, 43, 75, 48}; for (int i = 0; i <= 10; i += 2) { caca_put_char(cv, sparks[i], sparks[i+1], '*'); caca_put_char(cv, sparks[i]-1, sparks[i+1], '<'); caca_put_char(cv, sparks[i]+1, sparks[i+1], '>'); caca_put_char(cv, sparks[i], sparks[i+1]-1, '^'); caca_put_char(cv, sparks[i], sparks[i+1]+1, 'v'); } // Guirlandes caca_draw_thin_line(cv, 32, 44, 70, 35); caca_draw_thin_line(cv, 17, 49, 30, 46); caca_draw_thin_line(cv, 60, 47, 80, 43); caca_draw_thin_line(cv, 43, 35, 52, 33); caca_draw_thin_line(cv, 55, 28, 60, 27); caca_draw_thin_line(cv, 40, 25, 45, 24); // Star outline caca_fill_triangle(cv, 50, 16, 40, 10, 60, 10, ' '); int star_x[] = {50, 45, 40, 45, 40, 45, 50, 55, 60, 55, 60, 55, 50}; int star_y[] = { 4, 7, 7, 10, 13, 13, 16, 13, 13, 10, 7, 7, 4}; caca_draw_thin_polyline(cv, star_x, star_y, 12); // Inside of star int star[] = {50,8,50,9,50,10,50,11,50,12,49,9,48,9,51,9,52,9,49,10,51,10,49,11,48,11,51,11,52,11}; for (int i = 0; i <= 29; i += 2) caca_put_char(cv, star[i], star[i+1], '*'); // Display and wait for key press caca_refresh_display(dp); caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); caca_free_display(dp); return 0; }
/* 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; } }