source: libcaca/trunk/python/examples/blit.py @ 4711

Last change on this file since 4711 was 4711, checked in by Alex Foulon, 9 years ago
  • Add examples: blit, frames and text.
  • Property svn:executable set to *
File size: 1.7 KB
Line 
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
19import sys
20
21import caca
22from caca.canvas import Canvas, CanvasError, NullCanvas
23from caca.display import Display, DisplayError, Event
24
25THE_PIG="""\
26  ,__         __,
27  \\)`\\_..._/`(/
28   .'  _   _  '.
29  /    o\\ /o   \\
30  |    .-.-.    |  _
31  |   /() ()\\   | (,`)
32 / \\  '-----'  / \\ .'
33|   '-..___..-'   |
34|                 |
35|                 |
36;                 ;
37 \\      / \\      /
38  \\-..-/'-'\\-..-/
39jgs\\/\\/     \\/\\/"""
40
41def main():
42    """ Main function. """
43    try:
44        cv = Canvas(0, 0)
45        dp = Display(cv)
46    except (CanvasError, DisplayError), 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
64if __name__ == "__main__":
65    main()
66
Note: See TracBrowser for help on using the repository browser.