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.
 
 
 
 
 
 

67 regels
1.7 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # figfont libcaca blit test program
  5. # Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
  6. #
  7. # This file is a Python port of "examples/blit.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. THE_PIG="""\
  23. ,__ __,
  24. \\)`\\_..._/`(/
  25. .' _ _ '.
  26. / o\\ /o \\
  27. | .-.-. | _
  28. | /() ()\\ | (,`)
  29. / \\ '-----' / \\ .'
  30. | '-..___..-' |
  31. | |
  32. | |
  33. ; ;
  34. \\ / \\ /
  35. \\-..-/'-'\\-..-/
  36. jgs\\/\\/ \\/\\/"""
  37. def main():
  38. """ Main function. """
  39. try:
  40. cv = Canvas(0, 0)
  41. dp = Display(cv)
  42. except (CanvasError, DisplayError) as err:
  43. sys.stderr.write("%s\n" % err)
  44. sys.exit(2)
  45. sprite = Canvas(0, 0)
  46. sprite.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK)
  47. sprite.import_from_memory(THE_PIG, "text")
  48. sprite.set_handle(sprite.get_width()//2, sprite.get_height()//2)
  49. cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
  50. cv.put_str(0, 0, "Centered sprite")
  51. cv.blit(cv.get_width()//2, cv.get_height()//2, sprite, NullCanvas())
  52. dp.refresh()
  53. dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
  54. sys.exit(0)
  55. if __name__ == "__main__":
  56. main()