本文整理汇总了Python中vector.Vector.vectorize方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.vectorize方法的具体用法?Python Vector.vectorize怎么用?Python Vector.vectorize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.vectorize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_arrow
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import vectorize [as 别名]
def draw_arrow(canvas, point_from, point_to, color=Color(), width=1.0):
"""
@type canvas: drawing.canvas.Canvas
@type point_from: vector.Vector
@type point_to: vector.Vector
@type color: Color
@type width: float
"""
point_from = Vector.vectorize(point_from)
point_to = Vector.vectorize(point_to)
DrawingUtils.draw_line(canvas, point_from, point_to, color, width)
vec_arrow = point_to.sub(point_from)
wing = vec_arrow.inverse().normalized().scaled(10)
wing_right = wing.rotate(45)
wing_left = wing.rotate(-45)
DrawingUtils.draw_line(canvas, point_to,
wing_right.add(point_to), color,
width)
DrawingUtils.draw_line(canvas, point_to,
wing_left.add(point_to), color,
width)
示例2: draw_line
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import vectorize [as 别名]
def draw_line(canvas, point_from, point_to, color=Color(), width=1.0):
"""
@type canvas: drawing.canvas.Canvas
@type point_from: drawing.vector.Vector
@type point_to: drawing.vector.Vector
@type color: Color
@type width: float
"""
cr = canvas.cr
cr.save()
point_from = Vector.vectorize(point_from)
point_to = Vector.vectorize(point_to)
DrawingUtils.set_color(canvas, color)
cr.set_line_width(width)
cr.move_to(point_from.x, point_from.y)
cr.line_to(point_to.x, point_to.y)
cr.stroke()
cr.restore()
示例3: draw_text
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import vectorize [as 别名]
def draw_text(canvas, text, position, y_center=False, x_center=False,
font_style=None):
"""
Draws text on a given position. When no centering is set, it will be
drawn from top-left corner.
@type canvas: canvas.Canvas
@type text: str
@type position: Vector
@type y_center: bool
@type x_center: bool
@type font_style: FontStyle
"""
if not font_style:
font_style = FontStyle()
cr = canvas.cr
cr.save()
DrawingUtils.apply_font_style(canvas, font_style)
position = Vector.vectorize(position)
text = text.strip()
text_size = DrawingUtils.get_text_size(canvas, text)
if x_center:
position.x -= text_size.width / 2.0
if y_center:
w_size = DrawingUtils.get_text_size(canvas, "W")
position.y += w_size.height / 2.0
else:
position.y += text_size.height
DrawingUtils.set_color(canvas, font_style.color)
cr.move_to(position.x, position.y)
cr.show_text(text)
cr.restore()
示例4: draw_rectangle
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import vectorize [as 别名]
def draw_rectangle(canvas, position, size, color=Color(), width=1.0,
center=False, stroke=True):
cr = canvas.cr
cr.save()
position = Vector.vectorize(position)
size = Size.make_size(size)
if center:
position.x -= size.width / 2
position.y -= size.height / 2
DrawingUtils.set_color(canvas, color)
cr.rectangle(position.x, position.y, size.width, size.height)
if stroke:
cr.set_line_width(width)
cr.stroke()
else:
cr.fill()
cr.restore()
示例5: draw_image_from_surface
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import vectorize [as 别名]
def draw_image_from_surface(canvas, position, img, size=None,
center=False):
"""
Draws an image given by a cairo.ImageSurface object.
@type canvas: canvas.Canvas
@type position: vector.Vector
@type img: cairo.ImageSurface
@type size: size.Size
@type center: boolean
"""
if not size:
size = Size(img.get_width(), img.get_height())
else:
size = Size.make_size(size)
position = Vector.vectorize(position)
width = img.get_width()
height = img.get_height()
cr = canvas.cr
cr.save()
if center:
cr.translate(position.x - size.width / 2.0,
position.y - size.height / 2.0)
else:
cr.translate(position.x, position.y)
x_ratio = float(size.width) / width
y_ratio = float(size.height) / height
cr.scale(x_ratio, y_ratio)
cr.set_source_surface(img)
cr.get_source().set_filter(cairo.FILTER_FAST)
cr.paint()
cr.restore()