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; }
int main(int argc, char *argv[]) { textentry entries[TEXT_ENTRIES]; caca_canvas_t *cv; caca_display_t *dp; unsigned int i, e = 0, running = 1; cv = caca_create_canvas(0, 0); if(cv == NULL) { printf("Can't create canvas\n"); return -1; } dp = caca_create_display(cv); if(dp == NULL) { printf("Can't create display\n"); return -1; } caca_set_cursor(dp, 1); caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE); caca_put_str(cv, 1, 1, "Text entries - press tab to cycle"); for(i = 0; i < TEXT_ENTRIES; i++) { entries[i].buffer[0] = 0; entries[i].size = 0; entries[i].cursor = 0; entries[i].changed = 1; caca_printf(cv, 3, 3 * i + 4, "[entry %i]", i + 1); } /* Put Unicode crap in the last text entry */ entries[TEXT_ENTRIES - 1].buffer[0] = 'A'; entries[TEXT_ENTRIES - 1].buffer[1] = 'b'; entries[TEXT_ENTRIES - 1].buffer[2] = caca_utf8_to_utf32("Ç", NULL); entries[TEXT_ENTRIES - 1].buffer[3] = caca_utf8_to_utf32("đ", NULL); entries[TEXT_ENTRIES - 1].buffer[4] = caca_utf8_to_utf32("ボ", NULL); entries[TEXT_ENTRIES - 1].buffer[5] = CACA_MAGIC_FULLWIDTH; entries[TEXT_ENTRIES - 1].buffer[6] = caca_utf8_to_utf32("♥", NULL); entries[TEXT_ENTRIES - 1].size = 7; while(running) { caca_event_t ev; for(i = 0; i < TEXT_ENTRIES; i++) { unsigned int j, start, size; if(!entries[i].changed) continue; caca_set_color_ansi(cv, CACA_BLACK, CACA_LIGHTGRAY); caca_fill_box(cv, 2, 3 * i + 5, BUFFER_SIZE + 1, 1, ' '); start = 0; size = entries[i].size; for(j = 0; j < size; j++) { caca_put_char(cv, 2 + j, 3 * i + 5, entries[i].buffer[start + j]); } entries[i].changed = 0; } /* Put the cursor on the active textentry */ caca_gotoxy(cv, 2 + entries[e].cursor, 3 * e + 5); caca_refresh_display(dp); if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1) == 0) continue; switch(caca_get_event_key_ch(&ev)) { case CACA_KEY_ESCAPE: running = 0; break; case CACA_KEY_TAB: case CACA_KEY_RETURN: e = (e + 1) % TEXT_ENTRIES; break; case CACA_KEY_HOME: entries[e].cursor = 0; break; case CACA_KEY_END: entries[e].cursor = entries[e].size; break; case CACA_KEY_LEFT: if(entries[e].cursor) entries[e].cursor--; break; case CACA_KEY_RIGHT: if(entries[e].cursor < entries[e].size) entries[e].cursor++; break; case CACA_KEY_DELETE: if(entries[e].cursor < entries[e].size) { memmove(entries[e].buffer + entries[e].cursor, entries[e].buffer + entries[e].cursor + 1, (entries[e].size - entries[e].cursor + 1) * 4); entries[e].size--; entries[e].changed = 1; } break; case CACA_KEY_BACKSPACE: if(entries[e].cursor) { memmove(entries[e].buffer + entries[e].cursor - 1, entries[e].buffer + entries[e].cursor, (entries[e].size - entries[e].cursor) * 4); entries[e].size--; entries[e].cursor--; entries[e].changed = 1; } break; default: if(entries[e].size < BUFFER_SIZE) { memmove(entries[e].buffer + entries[e].cursor + 1, entries[e].buffer + entries[e].cursor, (entries[e].size - entries[e].cursor) * 4); entries[e].buffer[entries[e].cursor] = caca_get_event_key_utf32(&ev); entries[e].size++; entries[e].cursor++; entries[e].changed = 1; } break; } } caca_free_display(dp); caca_free_canvas(cv); 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; } }
JNIEXPORT void JNICALL Java_org_zoy_caca_Canvas_canvasFillBox(JNIEnv *env, jclass cls, jlong ptr, jint x, jint y, jint w, jint h, jint ch) { caca_fill_box((caca_canvas_t *)ptr, x, y, w, h, ch); }