Преглед на файлове

* Added two examples for python bindings (a subset of cacademo, and bitmap example)

tags/v0.99.beta14
Jean-Yves Lamoureux jylam преди 19 години
родител
ревизия
1a9c9e36f8
променени са 3 файла, в които са добавени 196 реда и са изтрити 0 реда
  1. +26
    -0
      python/caca.txt
  2. +114
    -0
      python/test1.py
  3. +56
    -0
      python/test2.py

+ 26
- 0
python/caca.txt Целия файл

@@ -0,0 +1,26 @@
12 6 6 3
,
` ,_ ,
` _( )_
_( ` )_
( `-. ' )
`-.____,-'
h
h gg h
h gggggg
gggggggggg
gggggggggggg
gggggggggg
12 6 6 3
. ,
` ,_
_( )_ '
_( ` )_
( `-. ' )
`-.____,-'
h h
h gg
gggggg h
gggggggggg
gggggggggggg
gggggggggg

+ 114
- 0
python/test1.py Целия файл

@@ -0,0 +1,114 @@
#!/usr/bin/python2.4

import caca
import math
from random import Random
from math import *


ret = caca.init()
print "caca.init() returned ", ret
print "Window size is ",caca.get_window_width(),"x",caca.get_window_height()
print "Buffer size is ",caca.get_width(),"x",caca.get_height()

caca.set_size(80,25)
print "Buffer size is now",caca.get_width(),"x",caca.get_height()


print "Feature name for CACA_DITHERING_FSTEIN is "+caca.get_feature_name(caca.CACA_DITHERING_FSTEIN)


sprite = int(caca.load_sprite("./caca.txt"))


rand = Random()

i = 0
while caca.get_event(caca.CACA_EVENT_KEY_PRESS) != caca.CACA_EVENT_KEY_PRESS|caca.CACA_KEY_ESCAPE:


i=i+1;
caca.clear();
caca.set_color(caca.CACA_COLOR_YELLOW, caca.CACA_COLOR_BLACK);
xo = caca.get_width() / 4;
yo = caca.get_height() / 4 + 5 * sin(0.03*i);
for j in range(0,16):
xa = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + 3.1415*j/8);
ya = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + 3.1415*j/8);
caca.draw_thin_line(int(xo), int(yo), int(xa), int(ya));

j = 15 + sin(0.03*i) * 8;
caca.set_color(caca.CACA_COLOR_WHITE, caca.CACA_COLOR_BLACK);
caca.fill_ellipse(int(xo), int(yo), int(j), int(j / 2), '#');
caca.set_color(caca.CACA_COLOR_YELLOW, caca.CACA_COLOR_BLACK);
caca.draw_ellipse(xo, yo, j, j / 2, '0');

xo = caca.get_width() * 5 / 8;
yo = 2;

xa = caca.get_width() / 8 + sin(0.03*i) * 5;
ya = caca.get_height() / 2 + cos(0.03*i) * 5;

xb = caca.get_width() - 10 - cos(0.02*i) * 10;
yb = caca.get_height() * 3 / 4 - 5 + sin(0.02*i) * 5;

xc = caca.get_width() / 4 - sin(0.02*i) * 5;
yc = caca.get_height() * 3 / 4 + cos(0.02*i) * 5;

caca.set_color(caca.CACA_COLOR_GREEN, caca.CACA_COLOR_BLACK);
caca.fill_triangle(xo, yo, xb, yb, xa, ya, '%');
caca.set_color(caca.CACA_COLOR_YELLOW, caca.CACA_COLOR_BLACK);
caca.draw_thin_triangle(xo, yo, xb, yb, xa, ya);

caca.set_color(caca.CACA_COLOR_RED, caca.CACA_COLOR_BLACK);
caca.fill_triangle(xa, ya, xb, yb, xc, yc, ' ');
caca.set_color(caca.CACA_COLOR_YELLOW, caca.CACA_COLOR_BLACK);
caca.draw_thin_triangle(xa, ya, xb, yb, xc, yc);

caca.set_color(caca.CACA_COLOR_BLUE, caca.CACA_COLOR_BLACK);
caca.fill_triangle(xo, yo, xb, yb, xc, yc, '%');
caca.set_color(caca.CACA_COLOR_YELLOW, caca.CACA_COLOR_BLACK);
caca.draw_thin_triangle(xo, yo, xb, yb, xc, yc);

xa = 2;
ya = 2;

xb = caca.get_width() - 3;
yb = caca.get_height() / 2;

xc = caca.get_width() / 3;
yc = caca.get_height() - 3;

caca.set_color(caca.CACA_COLOR_CYAN, caca.CACA_COLOR_BLACK);
caca.draw_thin_triangle(xa, ya, xb, yb, xc, yc);

xo = caca.get_width() / 2 + cos(0.027*i) * caca.get_width() / 3;
yo = caca.get_height() / 2 - sin(0.027*i) * caca.get_height() / 2;

caca.draw_thin_line(xa, ya, xo, yo);
caca.draw_thin_line(xb, yb, xo, yo);
caca.draw_thin_line(xc, yc, xo, yo);

caca.draw_sprite(xo, yo, sprite, 0);

for j in range(i - 60, i):
delta = (rand.random()*10)-5;
caca.set_color(rand.random()*15, rand.random()*15);
caca.putchar(caca.get_width() / 2
+ cos(0.02*j) * (delta + caca.get_width() / 4),
caca.get_height() / 2
+ sin(0.02*j) * (delta + caca.get_height() / 3),
' ');
caca.draw_sprite(caca.get_width() / 2 + cos(0.02*i) * caca.get_width() / 4,
caca.get_height() / 2 + sin(0.02*i) * caca.get_height() / 3,
int(sprite), int(0));


caca.refresh();


caca.end()

+ 56
- 0
python/test2.py Целия файл

@@ -0,0 +1,56 @@
#!/usr/bin/python2.3

import caca
import math
from random import Random
from math import *
import Numeric as N

ret = caca.init()

r = N.zeros(256)
g = N.zeros(256)
b = N.zeros(256)
a = N.zeros(256)

rand = Random()

# Our pixel array
pixels = N.zeros(32*32*4)
#pixels = pixelst.tolist()

for i in range(0,256):
r[i] = i
g[i] = i
b[i] = i
a[i] = 128

bitmap = caca.create_bitmap(32,32,32,32*4,0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000)
#caca.set_bitmap_palette(bitmap, r, g, b, a)


color = 0

while caca.get_event(caca.CACA_EVENT_KEY_PRESS) != caca.CACA_EVENT_KEY_PRESS|caca.CACA_KEY_ESCAPE:

for y in range(0,32):
for x in range(0,(32*4), 4):
offset = x + y * (32*4)
pixels[offset] = rand.random()*256
pixels[offset+1] = rand.random()*256
pixels[offset+2] = rand.random()*256
pixels[offset+3] = 128

color = color + 1

caca.draw_bitmap(0,0,caca.get_width() - 1, caca.get_height() - 1,
bitmap, pixels)
caca.refresh();



caca.end();

Зареждане…
Отказ
Запис