source: libcaca/trunk/python/test2.py @ 521

Last change on this file since 521 was 521, checked in by jylam, 9 years ago
  • Added two examples for python bindings (a subset of cacademo, and bitmap example)
  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/usr/bin/python2.3
2
3import caca
4import math
5from random import Random
6from math import *
7import Numeric as N
8
9ret = caca.init()
10
11r = N.zeros(256)
12g = N.zeros(256)
13b = N.zeros(256)
14a = N.zeros(256)
15
16rand = Random()
17
18# Our pixel array
19pixels = N.zeros(32*32*4)
20#pixels = pixelst.tolist()
21
22for i in range(0,256):
23    r[i] = i
24    g[i] = i
25    b[i] = i
26    a[i] = 128
27
28       
29bitmap = caca.create_bitmap(32,32,32,32*4,0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000)
30#caca.set_bitmap_palette(bitmap, r, g, b, a)
31
32
33color = 0
34
35while caca.get_event(caca.CACA_EVENT_KEY_PRESS) != caca.CACA_EVENT_KEY_PRESS|caca.CACA_KEY_ESCAPE:
36
37    for y in range(0,32):
38         for x in range(0,(32*4), 4):
39            offset = x + y * (32*4)
40            pixels[offset]   = rand.random()*256
41            pixels[offset+1] = rand.random()*256
42            pixels[offset+2] = rand.random()*256
43            pixels[offset+3] = 128
44           
45
46       
47    color = color + 1
48
49    caca.draw_bitmap(0,0,caca.get_width() - 1, caca.get_height() - 1,
50                     bitmap, pixels)
51       
52    caca.refresh();
53
54
55
56caca.end();
Note: See TracBrowser for help on using the repository browser.