本文整理汇总了Python中caca.canvas.Canvas.get_height方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.get_height方法的具体用法?Python Canvas.get_height怎么用?Python Canvas.get_height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caca.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.get_height方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import get_height [as 别名]
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'))
示例2: test_set_boundaries
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import get_height [as 别名]
def test_set_boundaries(self):
""" module canvas: Canvas.set_boundaries()
"""
cv = Canvas()
self.assertEqual(0, cv.set_boundaries(0, 0, 10, 10))
self.assertEqual((10, 10), (cv.get_width(), cv.get_height()))
self.assertEqual(0, cv.set_boundaries(0, 0, 5, 5))
self.assertEqual((5, 5), (cv.get_width(), cv.get_height()))
self.assertRaises(CanvasError, cv.set_boundaries, "a", 0, 10, 10)
self.assertRaises(CanvasError, cv.set_boundaries, 0, 0, "abc", 10)
示例3: main
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import get_height [as 别名]
def main():
""" Main function. """
try:
cv = Canvas(8, 2)
except CanvasError as err:
sys.stderr.write("%s\n" % err)
sys.exit(127)
cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)
cv.put_str(0, 0, "ABcde")
cv.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK)
cv.put_str(5, 0, "\\o/")
cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
cv.put_str(0, 1, "&$âøÿØ?!")
fonts = caca.get_font_list()
if not fonts:
sys.stderr.write("libcaca was compiled without any fonts\n")
sys.exit(127)
try:
f = Font(fonts[0])
except FontError as err:
sys.stderr.write("%s\n" % err)
sys.exit(127)
w = cv.get_width() * f.get_width()
h = cv.get_height() * f.get_height()
buf = ctypes.c_buffer(4 * w * h)
cv.render(f, buf, w, h, 4 * w)
cv.set_size(80, 32)
try:
dp = Display(cv)
except DisplayError as err:
sys.stderr.write("%s\n" % err)
sys.exit(127)
try:
if sys.byteorder == 'big':
dit = Dither(32, w, h, 4 * w, 0xff0000, 0xff00, 0xff, 0xff000000)
else:
dit = Dither(32, w, h, 4 * w, 0xff00, 0xff0000, 0xff000000, 0xff)
dit.bitmap(cv, 0, 0, cv.get_width(), cv.get_height(), buf)
except DitherError as err:
sys.stderr.write("%s\n" % err)
sys.exit(127)
else:
dp.refresh()
dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
示例4: main
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import get_height [as 别名]
def main():
""" Main function. """
try:
cv = Canvas(0, 0)
except CanvasError as err:
sys.stderr.write("%s\n" % err)
sys.exit(2)
for idx in range(1, 200):
cv.create_frame(idx)
sys.stderr.write("canvas created, size is %dx%d\n" \
% (cv.get_width(), cv.get_height()))
cv.set_size(150, 80)
sys.stderr.write("canvas expanded, size is %dx%d\n" \
% (cv.get_width(), cv.get_height()))
for idx in range(0, 16):
cv.set_frame(idx)
cv.set_color_ansi(caca.COLOR_WHITE, idx)
cv.fill_box(0, 0, 40, 15, ':')
cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
cv.put_str((idx * 5) // 2, idx, "カカ")
cv.set_color_ansi(caca.COLOR_DEFAULT, caca.COLOR_TRANSPARENT)
cv.set_size(41, 16)
sys.stderr.write("canvas shrinked, size is %dx%d\n" \
% (cv.get_width(), cv.get_height()))
try:
dp = Display(cv)
except DisplayError as err:
sys.stderr.write("%s\n" % err)
sys.exit(2)
dp.set_time(50000)
sys.stderr.write("display attached, size is %dx%d\n" \
% (cv.get_width(), cv.get_height()))
n = 0
while not dp.get_event(caca.EVENT_KEY_PRESS, Event(), 0):
cv.set_frame(n % 16)
dp.refresh()
n += 1
示例5: test_set_size
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import get_height [as 别名]
def test_set_size(self):
""" module canvas: Canvas.set_size()
"""
cv = Canvas(0, 0)
cv.set_size(1234, 1001)
self.assertEqual((1234, 1001), (cv.get_width(), cv.get_height()))
self.assertRaises(CanvasError, cv.set_size, "a", 12)
self.assertRaises(CanvasError, cv.set_size, 12, "a")
示例6: main
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import get_height [as 别名]
def main():
""" Main function. """
try:
cv = Canvas(0, 0)
dp = Display(cv)
except (CanvasError, DisplayError) as err:
sys.stderr.write("%s\n" % err)
sys.exit(2)
sprite = Canvas(0, 0)
sprite.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK)
sprite.import_from_memory(THE_PIG, "text")
sprite.set_handle(sprite.get_width()//2, sprite.get_height()//2)
cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
cv.put_str(0, 0, "Centered sprite")
cv.blit(cv.get_width()//2, cv.get_height()//2, sprite, NullCanvas())
dp.refresh()
dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
sys.exit(0)
示例7: main
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import get_height [as 别名]
def main():
""" Main function. """
events = []
quit = 0
quit_string = ["", "q", "qu", "qui", "quit"]
try:
cv = Canvas(80, 24)
dp = Display(cv)
except (CanvasError, DisplayError) as err:
sys.stderr.write("%s\n" % err)
sys.exit(127)
h = cv.get_height() - 1
cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
cv.draw_line(0, 0, cv.get_width() - 1, 0, ' ')
cv.draw_line(0, h, cv.get_width() - 1, h, ' ')
cv.put_str(0, h, "Type \"quit\" to exit")
dp.refresh()
while quit < 4:
ev = Event()
if dp.get_event(caca.EVENT_ANY, ev, -1):
if ev.get_type() == caca.EVENT_KEY_PRESS:
key = ev.get_key_ch()
if key == ord('u') and quit == 1:
quit += 1
elif key == ord('i') and quit == 2:
quit += 1
elif key == ord('t') and quit == 3:
quit += 1
elif key == ord('q'):
quit = 1
else:
quit = 0
events.append(ev)
cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
cv.clear()
#print current event
cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE)
cv.draw_line(0, 0, cv.get_width() - 1, 0, ' ')
if events:
print_event(cv, 0, 0, events[-1])
cv.draw_line(0, h, cv.get_width() - 1, h, ' ')
cv.put_str(0, h, "Type \"quit\" to exit: %s" % quit_string[quit])
#print previous events
cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)
counts = list(range(0, len(events)-1))
counts.reverse()
if len(events) > 1:
j = 0
for i in counts:
if j < h - 1 and events[i].get_type():
print_event(cv, 0, ((len(events) - 1) - i), events[i])
j += 1
dp.refresh()
示例8: test_get_height
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import get_height [as 别名]
def test_get_height(self):
""" module canvas: Canvas.get_width()
"""
cv = Canvas(5, 10)
self.assertEqual(10, cv.get_height())
示例9: LibcacaServer
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import get_height [as 别名]
class LibcacaServer(KinematicServer):
def __init__(self, *args, **kwargs):
"""
"""
KinematicServer.__init__(self, *args, **kwargs)
self.robots = [r for (name, r) in self.elements.items()
if isinstance(r, Robot)]
self.cv = Canvas()
self.dp = Display(self.cv)
self.ev = Event()
self.quit = False
self.width = self.cv.get_width()
self.height = self.cv.get_height()
self.camera = Camera(self, 640 , 480)
self.camera.translation = [3.5, 0, 1]
self.camera.init()
self.fps = -1.0
self.frames = 0
self.last_t = 0
def compute_fps(self):
now = time.time()
if self.last_t == 0:
self.last_t = now
return
PER = 2.0
if now - self.last_t >= PER:
self.fps = self.frames / PER
self.frames = 0
self.last_t = now
return
else:
self.frames += 1
def key_cb(self):
UP, DOWN, LEFT, RIGHT = 273,274,275,276
if self.dp.get_event(caca.EVENT_KEY_PRESS, self.ev, 0):
ch = self.ev.get_key_ch()
if ch == ord('q'):
self.quit = True
elif ch == UP:
self.camera.rotate(0, 1)
elif ch == DOWN:
self.camera.rotate(0, -1)
elif ch == LEFT:
self.camera.rotate(1, 0)
elif ch == RIGHT:
self.camera.rotate(-1, 0)
def project(self, p):
u, v = self.camera.project(p)
up, vp = int(u*self.width/self.camera.width), int((v)*self.height/self.camera.height)
return up, self.height - vp
def draw_floor(self):
lines=[]
L = 5
w = 1
N = int(L/w)
self.cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)
for i in range(-N,N+1):
lines.append([i*w, L,0.005])
lines.append([i*w,-L,0.005])
lines.append([L , i*w,0.005])
lines.append([-L , i*w,0.005] )
for i in range(len(lines)/2):
p1 = lines[2*i]
p2 = lines[2*i+1]
u1, v1 = self.project(p1)
u2, v2 = self.project(p2)
self.cv.draw_thin_line(int(u1), int(v1), int(u2), int(v2))
def draw_robot(self, r):
self.cv.set_color_ansi(caca.COLOR_GREEN, caca.COLOR_BLACK)
for j in r.moving_joint_list:
u, v = self.project(j.T[:3,3])
radius = 0
if j.parent:
up, vp = self.project(j.parent.T[:3,3])
self.cv.draw_thin_line(int(u), int(v), int(up), int(vp))
self.cv.set_color_ansi(caca.COLOR_RED, caca.COLOR_BLACK)
for j in r.moving_joint_list:
u, v = self.project(j.T[:3,3])
self.cv.draw_circle(u, v, radius, '@')
def run(self):
try:
while not self.quit:
self.key_cb()
self.compute_fps()
self.cv.clear()
#.........这里部分代码省略.........