本文整理汇总了Python中cairo.Context.set_line_cap方法的典型用法代码示例。如果您正苦于以下问题:Python Context.set_line_cap方法的具体用法?Python Context.set_line_cap怎么用?Python Context.set_line_cap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cairo.Context
的用法示例。
在下文中一共展示了Context.set_line_cap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _draw_cell
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_cap [as 别名]
def _draw_cell(self, context: cairo.Context,
cell_value: CrucipixelCellValue, area: Rectangle):
r, g, b = self.crucipixel_cell_value_to_color[cell_value]
context.set_source_rgb(r, g, b)
context.rectangle(area.start.x,
area.start.y,
area.width,
area.height)
context.fill()
if not self.victory_screen and cell_value == CrucipixelCellValue.EMPTY:
# draw the X
r, g, b = self.crucipixel_cell_value_to_color[
CrucipixelCellValue.SELECTED
]
context.set_source_rgb(r, g, b)
context.set_line_cap(cairo.LINE_CAP_ROUND)
delta_x = self.cell_width // 2.8
delta_y = self.cell_height // 2.8
context.move_to(area.start.x + area.width - delta_x,
area.start.y + delta_y)
context.line_to(area.start.x + delta_x,
area.start.y + area.height - delta_y)
context.move_to(area.start.x + area.width - delta_x,
area.start.y + area.width - delta_y)
context.line_to(area.start.x + delta_x,
area.start.y + delta_y)
context.stroke()
示例2: __init__
# 需要导入模块: from cairo import Context [as 别名]
# 或者: from cairo.Context import set_line_cap [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)