本文整理汇总了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)
示例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()
#.........这里部分代码省略.........