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


Python Canvas.draw_circle方法代碼示例

本文整理匯總了Python中caca.canvas.Canvas.draw_circle方法的典型用法代碼示例。如果您正苦於以下問題:Python Canvas.draw_circle方法的具體用法?Python Canvas.draw_circle怎麽用?Python Canvas.draw_circle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在caca.canvas.Canvas的用法示例。


在下文中一共展示了Canvas.draw_circle方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_draw_circle

# 需要導入模塊: from caca.canvas import Canvas [as 別名]
# 或者: from caca.canvas.Canvas import draw_circle [as 別名]
 def test_draw_circle(self):
     """ module canvas: Canvas.draw_circle()
     """
     cv = Canvas(10, 10)
     self.assertEqual(0, cv.draw_circle(5, 5, 3, '#'))
     self.assertRaises(CanvasError, cv.draw_circle, 0, 0, '#', '#')
     self.assertRaises(CanvasError, cv.draw_circle, 0, 0, 3, 0)
開發者ID:Kirkman,項目名稱:libcaca,代碼行數:9,代碼來源:canvas.py

示例2: LibcacaServer

# 需要導入模塊: from caca.canvas import Canvas [as 別名]
# 或者: from caca.canvas.Canvas import draw_circle [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.draw_circle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。