当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.clear方法代码示例

本文整理汇总了Python中caca.canvas.Canvas.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.clear方法的具体用法?Python Canvas.clear怎么用?Python Canvas.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在caca.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_clear

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import clear [as 别名]
 def test_clear(self):
     """ module canvas: Canvas.clear()
     """
     cv = Canvas(5, 1)
     cv.put_str(0, 0, "test!")
     cv.clear()
     data = cv.export_to_memory("utf8").strip('\n')
     self.assertEqual("     ", data)
开发者ID:Kirkman,项目名称:libcaca,代码行数:10,代码来源:canvas.py

示例2: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import clear [as 别名]
def main():
    """ Main function. """

    try:
        cv = Canvas(80, 24)
        dp = Display(cv)
    except (CanvasError, DisplayError) as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(127)

    cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
    cv.clear()

    for i in range(0, 16):
        if i >= 8:
            y = i + 3
        else:
            y = i + 2

        cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
        cv.printf(3, y, "ANSI %i", i)

        for j in range(0, 16):
            if j >= 8:
                x = 13 + (j * 4)
            else:
                x = 12 + (j * 4)
            if i >= 8:
                y = i + 3
            else:
                y = i + 2

            cv.set_color_ansi(i, j)
            cv.put_str(x, y, "Aaホ")

    cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
    cv.put_str(3, 20, "This is bold    This is blink    This is italics    This is underline")
    cv.set_attr(caca.STYLE_BOLD)
    cv.put_str(3 + 8, 20, "bold")
    cv.set_attr(caca.STYLE_BLINK)
    cv.put_str(3 + 24, 20, "blink")
    cv.set_attr(caca.STYLE_ITALICS)
    cv.put_str(3 + 41, 20, "italics")
    cv.set_attr(caca.STYLE_UNDERLINE)
    cv.put_str(3 + 60, 20, "underline")

    dp.refresh()
    dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
开发者ID:Kirkman,项目名称:libcaca,代码行数:50,代码来源:colors.py

示例3: main

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import clear [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

示例4: do_box

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import clear [as 别名]
            self.cv.draw_ellipse(x, y, a, b, '@')

    def do_box(self, thin=False):
        if thin:
            self.cv.draw_thin_box(0, 0, self.cv.get_width(), self.cv.get_height())
        else:
            self.cv.draw_box(0, 0, self.cv.get_width(), self.cv.get_height(), '#')

if __name__ == "__main__":
    cv = Canvas()
    dp = Display(cv)
    ev = Event()
    draw = Drawing(cv)

    while True:
        cv.clear()
        draw.do_menu()
        dp.refresh()
        if dp.get_event(caca.EVENT_KEY_PRESS, ev, 0):
            ch = ev.get_key_ch()
            cv.clear()
            if ch == ord('q'):
                sys.exit()
            elif ch == ord('1'):
                draw.do_line()
            elif ch == ord('2'):
                draw.do_line(thin=True)
            elif ch == ord('3'):
                draw.do_polyline()
            elif ch == ord('4'):
                draw.do_polyline(thin=True)
开发者ID:chazu,项目名称:libcaca,代码行数:33,代码来源:drawing.py

示例5: LibcacaServer

# 需要导入模块: from caca.canvas import Canvas [as 别名]
# 或者: from caca.canvas.Canvas import clear [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()
#.........这里部分代码省略.........
开发者ID:duongdang,项目名称:robot-viewer,代码行数:103,代码来源:libcaca_server.py


注:本文中的caca.canvas.Canvas.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。