本文整理汇总了Python中cairo.Context.arc方法的典型用法代码示例。如果您正苦于以下问题:Python Context.arc方法的具体用法?Python Context.arc怎么用?Python Context.arc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.arc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import arc [as 别名]
class Canvas:
def __init__(self, width, height):
self.xform = lambda x, y: (x, y)
self.img = ImageSurface(FORMAT_RGB24, width, height)
self.ctx = Context(self.img)
self.ctx.move_to(0, 0)
self.ctx.line_to(width, 0)
self.ctx.line_to(width, height)
self.ctx.line_to(0, height)
self.ctx.line_to(0, 0)
self.ctx.set_source_rgb(1, 1, 1)
self.ctx.fill()
self.width = width
self.height = height
def fit(self, left, top, right, bottom):
xoff = left
yoff = top
xscale = self.width / float(right - left)
yscale = self.height / float(bottom - top)
if abs(xscale) > abs(yscale):
xscale *= abs(yscale) / abs(xscale)
elif abs(xscale) < abs(yscale):
yscale *= abs(xscale) / abs(yscale)
self.xform = lambda x, y: ((x - xoff) * xscale, (y - yoff) * yscale)
def dot(self, x, y, size=4, fill=(.5, .5, .5)):
x, y = self.xform(x, y)
self.ctx.arc(x, y, size/2., 0, 2*pi)
self.ctx.set_source_rgb(*fill)
self.ctx.fill()
def line(self, points, stroke=(.5, .5, .5), width=1):
self.ctx.move_to(*self.xform(*points[0]))
for (x, y) in points[1:]:
self.ctx.line_to(*self.xform(x, y))
self.ctx.set_source_rgb(*stroke)
self.ctx.set_line_cap(LINE_CAP_ROUND)
self.ctx.set_line_width(width)
self.ctx.stroke()
def save(self, filename):
self.img.write_to_png(filename)
示例2: range
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import arc [as 别名]
start = end+1
ctx.fill_preserve()
ctx.set_source_rgb(0,1,0)
ctx.stroke()
start, end = 0, 0
for i in range(len(outline.contours)):
end = outline.contours[i]
ctx.new_path()
ctx.set_source_rgb(0,0,1)
for j in range(start, end+1):
if ( Curve_Tag[j] == FT_Curve_Tag_On ):
point = outline.points[j]
ctx.move_to(point[0],point[1])
ctx.arc(point[0], point[1], 40, 0, 2 * math.pi)
ctx.fill()
ctx.new_path()
ctx.set_source_rgb(1,0,0)
for j in range(start, end+1):
if ( Curve_Tag[j] != FT_Curve_Tag_On ):
point = outline.points[j]
ctx.move_to(point[0],point[1])
ctx.arc(point[0], point[1], 10, 0, 2 * math.pi)
ctx.fill()
points = outline.points[start:end+1]
points.append(points[0])
tags = outline.tags[start:end+1]
tags.append(tags[0])