當前位置: 首頁>>代碼示例>>Python>>正文


Python Canvas.draw_line方法代碼示例

本文整理匯總了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, "#")
開發者ID:Kirkman,項目名稱:libcaca,代碼行數:10,代碼來源:canvas.py

示例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()
開發者ID:Kirkman,項目名稱:libcaca,代碼行數:67,代碼來源:event.py


注:本文中的caca.canvas.Canvas.draw_line方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。