File: text.py

package info (click to toggle)
libcaca 0.99.beta20-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,540 kB
  • sloc: ansic: 25,091; php: 2,763; python: 2,637; cs: 1,213; cpp: 1,127; java: 916; objc: 836; makefile: 545; perl: 505; sh: 472; asm: 297; ruby: 215; xml: 33
file content (73 lines) | stat: -rwxr-xr-x 1,936 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# text          canvas text import/export
# Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
#
# This file is a Python port of "examples/text.c"
# which is:
# Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
#               All Rights Reserverd
#
# This library is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What the Fuck You Want
# to Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
#

import sys

import caca
from caca.canvas import Canvas, CanvasError, NullCanvas
from caca.display import Display, DisplayError, Event

STRING="""\
              |_| 
   _,----._   | | 
  (/ @  @ \\)   __ 
   |  OO  |   |_ 
   \\ `--' /   |__ 
    `----' 
              |_| 
 Hello world!  | 

"""

def main():
    """ Main function. """

    try:
        pig = Canvas(0, 0)
        pig.import_from_memory(STRING, "text")
        cv = Canvas(pig.get_width() * 2, pig.get_height() * 2)
    except CanvasError as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(2)

    cv.blit(0, 0, pig, NullCanvas())
    pig.flip()
    cv.blit(pig.get_width(), 0, pig, NullCanvas())
    pig.flip()
    pig.flop()
    cv.blit(0, pig.get_height(), pig, NullCanvas())
    pig.flop()
    pig.rotate_180()
    cv.blit(pig.get_width(), pig.get_height(), pig, NullCanvas())

    for j in range(0, cv.get_height()):
        for i in range(0, cv.get_width(), 2):
            cv.set_color_ansi(caca.COLOR_LIGHTBLUE + (i + j) % 6,
                              caca.COLOR_DEFAULT)

            a = cv.get_attr(-1, -1)
            cv.put_attr(i, j, a)
            cv.put_attr(i+1, j, a)

    print("%s" % cv.export_to_memory('utf8'))
    cv.rotate_left()
    print("%s" % cv.export_to_memory('utf8'))

if __name__ == "__main__":
    main()