Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

92 rader
2.4 KiB

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