| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# figfont libcaca blit test program |
| 5 |
# Copyright (c) 2010 Alex Foulon <[email protected]> |
| 6 |
# |
| 7 |
# This file is a Python port of "examples/blit.c" |
| 8 |
# which is: |
| 9 |
# Copyright (c) 2006-2010 Sam Hocevar <[email protected]> |
| 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://www.wtfpl.net/ for more details. |
| 17 |
# |
| 18 |
|
| 19 |
import sys |
| 20 |
|
| 21 |
import caca |
| 22 |
from caca.canvas import Canvas, CanvasError, NullCanvas |
| 23 |
from caca.display import Display, DisplayError, Event |
| 24 |
|
| 25 |
THE_PIG="""\ |
| 26 |
,__ __, |
| 27 |
\\)`\\_..._/`(/ |
| 28 |
.' _ _ '. |
| 29 |
/ o\\ /o \\ |
| 30 |
| .-.-. | _ |
| 31 |
| /() ()\\ | (,`) |
| 32 |
/ \\ '-----' / \\ .' |
| 33 |
| '-..___..-' | |
| 34 |
| | |
| 35 |
| | |
| 36 |
; ; |
| 37 |
\\ / \\ / |
| 38 |
\\-..-/'-'\\-..-/ |
| 39 |
jgs\\/\\/ \\/\\/""" |
| 40 |
|
| 41 |
def main(): |
| 42 |
""" Main function. """ |
| 43 |
try: |
| 44 |
cv = Canvas(0, 0) |
| 45 |
dp = Display(cv) |
| 46 |
except (CanvasError, DisplayError) as err: |
| 47 |
sys.stderr.write("%s\n" % err) |
| 48 |
sys.exit(2) |
| 49 |
|
| 50 |
sprite = Canvas(0, 0) |
| 51 |
sprite.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK) |
| 52 |
sprite.import_from_memory(THE_PIG, "text") |
| 53 |
sprite.set_handle(sprite.get_width()//2, sprite.get_height()//2) |
| 54 |
|
| 55 |
cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE) |
| 56 |
cv.put_str(0, 0, "Centered sprite") |
| 57 |
cv.blit(cv.get_width()//2, cv.get_height()//2, sprite, NullCanvas()) |
| 58 |
|
| 59 |
dp.refresh() |
| 60 |
dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1) |
| 61 |
|
| 62 |
sys.exit(0) |
| 63 |
|
| 64 |
if __name__ == "__main__": |
| 65 |
main() |
| 66 |
|