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://www.wtfpl.net/ 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
25STRING="""\
26              |_|
27   _,----._   | |
28  (/ @  @ \\)   __
29   |  OO  |   |_
30   \\ `--' /   |__
31    `----'
32              |_|
33 Hello world!  |
34
35"""
36
37def main():
38    """ Main function. """
39
40    try:
41        pig = Canvas(0, 0)
42        pig.import_from_memory(STRING, "text")
43        cv = Canvas(pig.get_width() * 2, pig.get_height() * 2)
44    except CanvasError as err:
45        sys.stderr.write("%s\n" % err)
46        sys.exit(2)
47
48    cv.blit(0, 0, pig, NullCanvas())
49    pig.flip()
50    cv.blit(pig.get_width(), 0, pig, NullCanvas())
51    pig.flip()
52    pig.flop()
53    cv.blit(0, pig.get_height(), pig, NullCanvas())
54    pig.flop()
55    pig.rotate_180()
56    cv.blit(pig.get_width(), pig.get_height(), pig, NullCanvas())
57
58    for j in range(0, cv.get_height()):
59        for i in range(0, cv.get_width(), 2):
60            cv.set_color_ansi(caca.COLOR_LIGHTBLUE + (i + j) % 6,
61                              caca.COLOR_DEFAULT)
62
63            a = cv.get_attr(-1, -1)
64            cv.put_attr(i, j, a)
65            cv.put_attr(i+1, j, a)
66
67    print("%s" % cv.export_to_memory('utf8'))
68    cv.rotate_left()
69    print("%s" % cv.export_to_memory('utf8'))
70
71if __name__ == "__main__":
72    main()
73
74