25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

74 lines
1.9 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # text canvas text import/export
  5. # Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
  6. #
  7. # This file is a Python port of "examples/text.c"
  8. # which is:
  9. # Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
  10. # All Rights Reserverd
  11. #
  12. # This library is free software. It comes without any warranty, to
  13. # the extent permitted by applicable law. You can redistribute it
  14. # and/or modify it under the terms of the Do What The Fuck You Want
  15. # To Public License, Version 2, as published by Sam Hocevar. See
  16. # http://sam.zoy.org/wtfpl/COPYING for more details.
  17. #
  18. import sys
  19. import caca
  20. from caca.canvas import Canvas, CanvasError, NullCanvas
  21. from caca.display import Display, DisplayError, Event
  22. STRING="""\
  23. |_|
  24. _,----._ | |
  25. (/ @ @ \\) __
  26. | OO | |_
  27. \\ `--' / |__
  28. `----'
  29. |_|
  30. Hello world! |
  31. """
  32. def main():
  33. """ Main function. """
  34. try:
  35. pig = Canvas(0, 0)
  36. pig.import_from_memory(STRING, "text")
  37. cv = Canvas(pig.get_width() * 2, pig.get_height() * 2)
  38. except CanvasError as err:
  39. sys.stderr.write("%s\n" % err)
  40. sys.exit(2)
  41. cv.blit(0, 0, pig, NullCanvas())
  42. pig.flip()
  43. cv.blit(pig.get_width(), 0, pig, NullCanvas())
  44. pig.flip()
  45. pig.flop()
  46. cv.blit(0, pig.get_height(), pig, NullCanvas())
  47. pig.flop()
  48. pig.rotate_180()
  49. cv.blit(pig.get_width(), pig.get_height(), pig, NullCanvas())
  50. for j in range(0, cv.get_height()):
  51. for i in range(0, cv.get_width(), 2):
  52. cv.set_color_ansi(caca.COLOR_LIGHTBLUE + (i + j) % 6,
  53. caca.COLOR_DEFAULT)
  54. a = cv.get_attr(-1, -1)
  55. cv.put_attr(i, j, a)
  56. cv.put_attr(i+1, j, a)
  57. print("%s" % cv.export_to_memory('utf8'))
  58. cv.rotate_left()
  59. print("%s" % cv.export_to_memory('utf8'))
  60. if __name__ == "__main__":
  61. main()