You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

94 lines
2.4 KiB

  1. /*
  2. * text canvas text import/export
  3. * Copyright (c) 2006-2009 Sam Hocevar <sam@hocevar.net>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. #include "config.h"
  15. #if !defined(__KERNEL__)
  16. # include <stdio.h>
  17. # include <string.h>
  18. # include <stdlib.h>
  19. #endif
  20. #include "caca.h"
  21. #define STRING \
  22. " |_| \n" \
  23. " _,----._ | | \n" \
  24. " (/ @ @ \\) __ \n" \
  25. " | OO | |_ \n" \
  26. " \\ `--' / |__ \n" \
  27. " `----' \n" \
  28. " |_| \n" \
  29. " Hello world! | \n" \
  30. " \n"
  31. int main(int argc, char *argv[])
  32. {
  33. caca_canvas_t *cv, *pig;
  34. void *buffer;
  35. size_t len;
  36. int i, j;
  37. pig = caca_create_canvas(0, 0);
  38. caca_import_canvas_from_memory(pig, STRING, strlen(STRING), "text");
  39. cv = caca_create_canvas(caca_get_canvas_width(pig) * 2,
  40. caca_get_canvas_height(pig) * 2);
  41. if(cv == NULL || pig == NULL)
  42. {
  43. printf("Can't created canvas\n");
  44. return -1;
  45. }
  46. caca_blit(cv, 0, 0, pig, NULL);
  47. caca_flip(pig);
  48. caca_blit(cv, caca_get_canvas_width(pig), 0, pig, NULL);
  49. caca_flip(pig);
  50. caca_flop(pig);
  51. caca_blit(cv, 0, caca_get_canvas_height(pig), pig, NULL);
  52. caca_flop(pig);
  53. caca_rotate_180(pig);
  54. caca_blit(cv, caca_get_canvas_width(pig),
  55. caca_get_canvas_height(pig), pig, NULL);
  56. for(j = 0; j < caca_get_canvas_height(cv); j++)
  57. {
  58. for(i = 0; i < caca_get_canvas_width(cv); i += 2)
  59. {
  60. unsigned long int a;
  61. caca_set_color_ansi(cv, CACA_LIGHTBLUE + (i + j) % 6,
  62. CACA_DEFAULT);
  63. a = caca_get_attr(cv, -1, -1);
  64. caca_put_attr(cv, i, j, a);
  65. caca_put_attr(cv, i + 1, j, a);
  66. }
  67. }
  68. buffer = caca_export_canvas_to_memory(cv, "utf8", &len);
  69. fwrite(buffer, len, 1, stdout);
  70. free(buffer);
  71. caca_rotate_left(cv);
  72. buffer = caca_export_canvas_to_memory(cv, "utf8", &len);
  73. fwrite(buffer, len, 1, stdout);
  74. free(buffer);
  75. caca_free_canvas(pig);
  76. caca_free_canvas(cv);
  77. return 0;
  78. }