本文整理汇总了Python中nodebox.graphics.Path类的典型用法代码示例。如果您正苦于以下问题:Python Path类的具体用法?Python Path怎么用?Python Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_rect
def parse_rect(e):
x = float(get_attribute(e, "x"))
y = float(get_attribute(e, "y"))
w = float(get_attribute(e, "width"))
h = float(get_attribute(e, "height"))
if w < 0:
print >> sys.stderr, "Error: invalid negative value for <rect> attribute width=\"%s\"" % w
w = 0
if h < 0:
print >> sys.stderr, "Error: invalid negative value for <rect> attribute height=\"%s\"" % h
h = 0
rx = float(get_attribute(e, "rx"))
ry = float(get_attribute(e, "ry"))
if rx < 0:
print >> sys.stderr, "Error: invalid negative value for <rect> attribute rx=\"%s\"" % rx
rx = 0
if ry < 0:
print >> sys.stderr, "Error: invalid negative value for <rect> attribute ry=\"%s\"" % ry
ry = 0
if not rx or not ry:
rx = ry = max(rx, ry)
if rx > w / 2.0: rx = w / 2.0
if ry > h / 2.0: ry = h / 2.0
p = Path()
p.rect(x + w / 2.0, y + h / 2.0, w, h, rx, ry)
return p
示例2: line_angle
def line_angle(position, angle, distance):
p = Path()
x1, y1 = coordinates(position.x, position.y, distance, angle)
p.line(position.x, position.y, x1, y1)
p.strokeColor = Color.BLACK
p.strokeWidth = 1
return p
示例3: rect
def rect(position, width, height, roundness):
"""Create a rectangle or rounded rectangle."""
p = Path()
if roundness == Point.ZERO:
p.rect(position.x, position.y, width, height)
else:
p.roundedRect(position.x, position.y, width, height, roundness.x, roundness.y)
return p
示例4: transform
def transform(path, m, n1, n2, n3, scale=1.0, points=100, range=TWOPI):
new_path = Path()
for i in _range(points):
pt = path.pointAt(float(i) / points)
phi = i * range / points
dx, dy = supercalc(m, n1, n2, n3, phi)
new_path.addPoint(pt.x + dx * scale, pt.y + dy * scale)
return new_path
示例5: text_on_path
def text_on_path(text, shape, font_name, font_size, alignment, margin, baseline_offset):
if shape is None or shape.length <= 0: return None
if text is None: return None
text = unicode(text)
if isinstance(shape, Path):
shape = shape.asGeometry()
p = Path()
fm = get_font_metrics(font_name, font_size)
string_width = textwidth(text, fm)
dw = string_width / shape.length
if alignment == "trailing":
first = True
for char in text:
char_width = textwidth(char, fm)
if first:
t = (99.9 - margin) / 100.0
first = False
else:
t -= char_width / string_width * dw
t = t % 1.0
margin = t * 100
first = True
for char in text:
char_width = textwidth(char, fm)
if first:
t = margin / 100.0
first = False
else:
t += char_width / string_width * dw
# Always loop (the other behavior is weird)
t = t % 1.0
pt1 = shape.pointAt(t)
pt2 = shape.pointAt(t + 0.0000001)
a = angle(pt2.x, pt2.y, pt1.x, pt1.y)
tp = Text(char, -char_width, -baseline_offset)
tp.align = Text.Align.LEFT
tp.fontName = font_name
tp.fontSize = font_size
tp.translate(pt1.x, pt1.y)
tp.rotate(a - 180)
for contour in tp.path.contours:
p.add(contour)
return p
示例6: parse_line
def parse_line(e):
x1 = float(get_attribute(e, "x1"))
y1 = float(get_attribute(e, "y1"))
x2 = float(get_attribute(e, "x2"))
y2 = float(get_attribute(e, "y2"))
p = Path()
p.line(x1, y1, x2, y2)
return p
示例7: parse_circle
def parse_circle(e):
x = float(get_attribute(e, "cx"))
y = float(get_attribute(e, "cy"))
r = float(get_attribute(e, "r"))
p = Path()
p.ellipse(x, y, r*2, r*2)
p.close()
return p
示例8: parse_rect
def parse_rect(e):
x = float(get_attribute(e, "x"))
y = float(get_attribute(e, "y"))
w = float(get_attribute(e, "width"))
h = float(get_attribute(e, "height"))
p = Path()
p.rect(x+w/2, y+h/2, w, h)
return p
示例9: _flatten
def _flatten(geo):
compound = Path()
first = True
for path in geo.paths:
if first:
compound = path
first = False
else:
compound = compound.united(path)
return compound
示例10: parse_oval
def parse_oval(e):
x = float(get_attribute(e, "cx"))
y = float(get_attribute(e, "cy"))
w = float(get_attribute(e, "rx"))*2
h = float(get_attribute(e, "ry"))*2
p = Path()
p.ellipse(x, y, w, h)
p.close()
return p
示例11: delete_points
def delete_points(path, bounding, delete_selected=True):
if path is None or bounding is None: return None
new_path = Path(path, False) # cloneContours = False
for old_contour in path.contours:
new_contour = Contour()
for point in old_contour.points:
if bounding.contains(point) == delete_selected:
new_contour.addPoint(Point(point.x, point.y, point.type))
new_contour.closed = old_contour.closed
new_path.add(new_contour)
return new_path
示例12: path
def path(position, width, height, m, n1, n2, n3, points=1000, percentage=1.0, range=TWOPI):
path = Path()
for i in _range(points):
if i > points*percentage:
continue
phi = i * range / points
dx, dy = supercalc(m, n1, n2, n3, phi)
dx = (dx * width / 2) + position.x
dy = (dy * height / 2) + position.y
path.addPoint(dx, dy)
return path
示例13: parse_circle
def parse_circle(e):
cx = float(get_attribute(e, "cx"))
cy = float(get_attribute(e, "cy"))
r = float(get_attribute(e, "r"))
if r < 0:
print >> sys.stderr, "Error: invalid negative value for <circle> attribute r=\"%s\"" % r
r = 0
p = Path()
p.ellipse(cx, cy, r*2, r*2)
p.close()
return p
示例14: shape_intersects
def shape_intersects(distance):
tx, ty = coordinates(0, 0, distance, angle)
t = Transform()
t.translate(tx, ty)
translated_shape = t.map(shape)
if use_bounding_box:
b = Path()
b.cornerRect(translated_shape.bounds)
else:
b = translated_shape
# If the shape intersects it is too close (the distance is too low).
if bounding_path.intersects(b):
return -1
return 1
示例15: transform
def transform(path, m, n1, n2, n3, points=100, range=TWOPI):
first = True
for i in _range(points):
pt = path.getPoints#(float(i)/points)
phi = i * range / points
dx, dy = supercalc(m, n1, n2, n3, phi)
if first:
p = Path()
p.moveto(pt.x+dx, pt.y+dy)
first = False
else:
_ctx.lineto(pt.x+dx, pt.y+dy)
p.lineto(pt.x+dx, pt.y+dy)
return p