Last change
on this file since 3284 was
521,
checked in by Jean-Yves Lamoureux, 15 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 | |
---|
3 | import caca |
---|
4 | import math |
---|
5 | from random import Random |
---|
6 | from math import * |
---|
7 | import Numeric as N |
---|
8 | |
---|
9 | ret = caca.init() |
---|
10 | |
---|
11 | r = N.zeros(256) |
---|
12 | g = N.zeros(256) |
---|
13 | b = N.zeros(256) |
---|
14 | a = N.zeros(256) |
---|
15 | |
---|
16 | rand = Random() |
---|
17 | |
---|
18 | # Our pixel array |
---|
19 | pixels = N.zeros(32*32*4) |
---|
20 | #pixels = pixelst.tolist() |
---|
21 | |
---|
22 | for i in range(0,256): |
---|
23 | r[i] = i |
---|
24 | g[i] = i |
---|
25 | b[i] = i |
---|
26 | a[i] = 128 |
---|
27 | |
---|
28 | |
---|
29 | bitmap = caca.create_bitmap(32,32,32,32*4,0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000) |
---|
30 | #caca.set_bitmap_palette(bitmap, r, g, b, a) |
---|
31 | |
---|
32 | |
---|
33 | color = 0 |
---|
34 | |
---|
35 | while 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 | |
---|
56 | caca.end(); |
---|
Note: See
TracBrowser
for help on using the repository browser.