本文整理汇总了Python中caca.canvas.Canvas.draw_line方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.draw_line方法的具体用法?Python Canvas.draw_line怎么用?Python Canvas.draw_line使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caca.canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.draw_line方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_draw_line
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import draw_line [as 别名]
def test_draw_line(self):
""" module canvas: Canvas.draw_line()
"""
cv = Canvas(10, 1)
cv.draw_line(0, 0, 10, 1, "#")
self.assertEqual("#" * 10, cv.export_to_memory("utf8").strip('\n'))
self.assertRaises(CanvasError, cv.draw_line, 0, 0, 10, 1, 7)
self.assertRaises(CanvasError, cv.draw_line, 0, "a", 10, 1, "#")
示例2: main
# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import draw_line [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()