本文整理汇总了Python中nodebox.graphics.Path.moveto方法的典型用法代码示例。如果您正苦于以下问题:Python Path.moveto方法的具体用法?Python Path.moveto怎么用?Python Path.moveto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nodebox.graphics.Path
的用法示例。
在下文中一共展示了Path.moveto方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_path
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def _update_path(self):
x, y = self.mouse()
path = Path()
if len(self._points) > 0:
first = True
for i in range(len(self._points)):
# Construct the path.
pt = self._points[i]
if first:
path.moveto(pt.x, pt.y)
first = False
else:
if pt.cmd == CLOSE:
path.close()
elif pt.cmd == MOVETO:
path.moveto(pt.x, pt.y)
elif pt.cmd == LINETO:
path.lineto(pt.x, pt.y)
elif pt.cmd == CURVETO:
path.curveto(pt.ctrl1.x, pt.ctrl1.y,
pt.ctrl2.x, pt.ctrl2.y,
pt.x, pt.y)
# Set the current path,
self.path = path
示例2: star
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def star(position, points, outer, inner):
p = Path()
p.moveto(position.x, position.y + outer / 2)
# Calculate the points of the star.
for i in xrange(1, points * 2):
angle = i * pi / points
radius = i % 2 and inner / 2 or outer / 2
x = position.x + radius * sin(angle)
y = position.y + radius * cos(angle)
p.lineto(x, y)
p.close()
return p
示例3: transform
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
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
示例4: connect
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def connect(points, closed=True):
"""Connects all points in a path."""
if points is None: return None
if len(points) < 2: return None
points = list(points)
start = points[0]
p = Path()
p.moveto(start.x, start.y)
for point in points[1:]:
p.lineto(point.x, point.y)
if closed:
p.close()
p.stroke = Color.BLACK
p.strokeWidth = 1.0
return p
示例5: link
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def link(shape1, shape2, orientation):
if shape1 is None or shape2 is None: return None
p = Path()
ax, ay, aw, ah = shape1.bounds
bx, by, bw, bh = shape2.bounds
if orientation == "horizontal":
hw = (bx - (ax + aw)) / 2
p.moveto(ax + aw, ay)
p.curveto(ax + aw + hw, ay, bx - hw, by, bx, by)
p.lineto(bx, by + bh)
p.curveto(bx - hw, by + bh, ax + aw + hw, ay + ah, ax + aw, ay + ah)
else:
hh = (by - (ay + ah)) / 2
p.moveto(ax, ay + ah)
p.curveto(ax, ay + ah + hh, bx, by - hh, bx, by)
p.lineto(bx + bw, by)
p.curveto(bx + bw, by - hh, ax + aw, ay + ah + hh, ax + aw, ay + ah)
return p
示例6: quad_curve
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def quad_curve(pt1, pt2, t, distance):
t /= 100.0
cx = pt1.x + t * (pt2.x - pt1.x)
cy = pt1.y + t * (pt2.y - pt1.y)
a = angle(pt1.x, pt1.y, pt2.x, pt2.y) + 90
qx, qy = coordinates(cx, cy, distance, a)
p = Path()
p.moveto(pt1.x, pt1.y)
c1x = pt1.x + 2/3.0 * (qx - pt1.x)
c1y = pt1.y + 2/3.0 * (qy - pt1.y)
c2x = pt2.x + 2/3.0 * (qx - pt2.x)
c2y = pt2.y + 2/3.0 * (qy - pt2.y)
p.curveto(c1x, c1y, c2x, c2y, pt2.x, pt2.y)
p.fill = None
p.stroke = Color.BLACK
p.strokeWidth = 1.0
return p
示例7: polygon
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def polygon(position, radius, sides, align):
"""Draw a polygon."""
p = Path()
x, y, r = position.x, position.y, radius
sides = max(sides, 3)
a = 360.0 / sides
da = 0
if align:
x0, y0 = coordinates(x, y, r, 0)
x1, y1 = coordinates(x, y, r, a)
da = -angle(x1, y1, x0, y0)
for i in xrange(sides):
x1, y1 = coordinates(x, y, r, (a*i) + da)
if i == 0:
p.moveto(x1, y1)
else:
p.lineto(x1, y1)
p.close()
return p
示例8: parse_polygon
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def parse_polygon(e):
d = get_attribute(e, "points", default="")
d = d.replace(" ", ",")
d = d.replace("-", ",")
d = d.split(",")
points = []
for x in d:
if x != "": points.append(float(x))
autoclosepath = True
if (e.tagName == "polyline") :
autoclosepath = False
p = Path()
p.moveto(points[0], points[1])
for i in range(len(points)/2):
p.lineto(points[i*2], points[i*2+1])
if autoclosepath:
p.close()
return p
示例9: _str_to_path
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def _str_to_path(s):
# Utility function to convert a string containing a list of points to a Path
# The letter M marks the start of a new curve.
p = Path()
for curve_str in s.strip().split("M"):
curve_str = curve_str.strip()
if curve_str:
coords = []
for coord in curve_str.split(" "):
try:
coords.append(float(coord))
except:
pass
coords = len(coords) % 2 and coords[:-1] or coords
for i in range(0, len(coords), 2):
x = coords[i]
y = coords[i+1]
if i == 0:
p.moveto(x, y)
else:
p.lineto(x, y)
return p
示例10: parse_path
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def parse_path(e):
d = get_attribute(e, "d", default="")
d = re.sub(r",", r" ", d) # get rid of all commas
d = re.sub(r"([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])", r"\1 \2", d) # separate commands from commands
d = re.sub(r"([MmZzLlHhVvCcSsQqTtAa])([MmZzLlHhVvCcSsQqTtAa])", r"\1 \2", d) # separate commands from commands
d = re.sub(r"([MmZzLlHhVvCcSsQqTtAa])([^\s])", r"\1 \2", d) # separate commands from points
d = re.sub(r"([^\s])([MmZzLlHhVvCcSsQqTtAa])", r"\1 \2", d) # separate commands from points
d = re.sub(r"([0-9])([+\-])", r"\1 \2", d) # separate digits when no comma
d = re.sub(r"(\.[0-9]*)(\.)", r"\1 \2", d) # separate digits when no comma
d = re.sub(r"([Aa](\s+[0-9]+){3})\s+([01])\s*([01])", r"\1 \3 \4 ", d) # shorthand elliptical arc path syntax
d = re.sub(r"[\s\r\t\n]+", r" ", d)
d = d.strip()
path = Path()
pp = PathParser(d)
pp.reset()
while not pp.isEnd():
pp.nextCommand()
command = pp.command.lower()
if command == 'm':
p = pp.getAsCurrentPoint()
path.moveto(p.x, p.y)
pp.start = pp.current
while not pp.isCommandOrEnd():
p = pp.getAsCurrentPoint()
path.lineto(p.x, p.y)
elif command == 'l':
while not pp.isCommandOrEnd():
p = pp.getAsCurrentPoint()
path.lineto(p.x, p.y)
elif command == 'h':
while not pp.isCommandOrEnd():
newP = Point((pp.isRelativeCommand() and pp.current.x or 0) + pp.getScalar(), pp.current.y)
pp.current = newP
path.lineto(pp.current.x, pp.current.y)
elif command == 'v':
while not pp.isCommandOrEnd():
newP = Point(pp.current.x, (pp.isRelativeCommand() and pp.current.y or 0) + pp.getScalar())
pp.current = newP
path.lineto(pp.current.x, pp.current.y)
elif command == 'c':
while not pp.isCommandOrEnd():
curr = pp.current
p1 = pp.getPoint()
cntrl = pp.getAsControlPoint()
cp = pp.getAsCurrentPoint()
path.curveto(p1.x, p1.y, cntrl.x, cntrl.y, cp.x, cp.y)
elif command == 's':
while not pp.isCommandOrEnd():
curr = pp.current
p1 = pp.getReflectedControlPoint()
cntrl = pp.getAsControlPoint()
cp = pp.getAsCurrentPoint()
path.curveto(p1.x, p1.y, cntrl.x, cntrl.y, cp.x, cp.y)
elif command == 'q':
while not pp.isCommandOrEnd():
curr = pp.current
cntrl = pp.getAsControlPoint()
cp = pp.getAsCurrentPoint()
cp1x = curr.x + 2 / 3.0 * (cntrl.x - curr.x) # CP1 = QP0 + 2 / 3 *(QP1-QP0)
cp1y = curr.y + 2 / 3.0 * (cntrl.y - curr.y) # CP1 = QP0 + 2 / 3 *(QP1-QP0)
cp2x = cp1x + 1 / 3.0 * (cp.x - curr.x) # CP2 = CP1 + 1 / 3 *(QP2-QP0)
cp2y = cp1y + 1 / 3.0 * (cp.y - curr.y) # CP2 = CP1 + 1 / 3 *(QP2-QP0)
g.curveto(cp1x, cp1y, cp2x, cp2y, cp.x, cp.y)
elif command == 't':
while not pp.isCommandOrEnd():
curr = pp.current
cntrl = pp.getReflectedControlPoint()
pp.control = cntrl
cp = pp.getAsCurrentPoint()
cp1x = curr.x + 2 / 3.0 * (cntrl.x - curr.x) # CP1 = QP0 + 2 / 3 *(QP1-QP0)
cp1y = curr.y + 2 / 3.0 * (cntrl.y - curr.y) # CP1 = QP0 + 2 / 3 *(QP1-QP0)
cp2x = cp1x + 1 / 3.0 * (cp.x - curr.x) # CP2 = CP1 + 1 / 3 *(QP2-QP0)
cp2y = cp1y + 1 / 3.0 * (cp.y - curr.y) # CP2 = CP1 + 1 / 3 *(QP2-QP0)
path.curveto(cp1x, cp1y, cp2x, cp2y, cp.x, cp.y)
elif command == 'a':
while not pp.isCommandOrEnd():
curr = pp.current
rx = pp.getScalar()
ry = pp.getScalar()
rot = pp.getScalar() # * (math.pi / 180.0)
large = pp.getScalar()
sweep = pp.getScalar()
cp = pp.getAsCurrentPoint()
ex = cp.x
ey = cp.y
segs = arcToSegments(ex, ey, rx, ry, large, sweep, rot, curr.x, curr.y)
for seg in segs:
bez = segmentToBezier(*seg)
path.curveto(*bez)
elif command == 'z':
path.close()
pp.current = pp.start
return path
示例11: parse_path
# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import moveto [as 别名]
def parse_path(e):
d = get_attribute(e, "d", default="")
# Divide the path data string into segments.
# Each segment starts with a path command,
# usually followed by coordinates.
segments = []
i = 0
for j in range(len(d)):
commands = ["M", "m", "Z", "z", "L", "l", "H", "h", "V", "v", "C","c", "S", "s", "A"]
if d[j] in commands:
segments.append(d[i:j].strip())
i = j
segments.append(d[i:].strip())
segments.remove("")
previous_command = ""
# Path origin (moved by MOVETO).
x0 = 0
y0 = 0
# The current point in the path.
dx = 0
dy = 0
# The previous second control handle.
dhx = 0
dhy = 0
path = Path()
for segment in segments:
command = segment[0]
if command in ["Z", "z"]:
path.close()
else:
# The command is a pen move, line or curve.
# Get the coordinates.
points = segment[1:].strip()
points = points.replace("-", ",-")
points = points.replace(" ", ",")
points = re.sub(",+", ",", points)
points = points.strip(",")
points = [float(i) for i in points.split(",")]
# Absolute MOVETO.
# Move the current point to the new coordinates.
if command == "M":
for i in range(len(points)/2):
path.moveto(points[i*2], points[i*2+1])
dx = points[i*2]
dy = points[i*2+1]
x0 = dx
y0 = dy
# Relative MOVETO.
# Offset from the current point.
elif command == "m":
for i in range(len(points)/2):
path.moveto(dx+points[i*2], dy+points[i*2+1])
dx += points[i*2]
dy += points[i*2+1]
x0 = dx
y0 = dy
# Absolute LINETO.
# Draw a line from the current point to the new coordinate.
elif command == "L":
for i in range(len(points)/2):
path.lineto(points[i*2], points[i*2+1])
dx = points[i*2]
dy = points[i*2+1]
# Relative LINETO.
# Offset from the current point.
elif command == "l":
for i in range(len(points)/2):
path.lineto(dx+points[i*2], dy+points[i*2+1])
dx += points[i*2]
dy += points[i*2+1]
# Absolute horizontal LINETO.
# Only the vertical coordinate is supplied.
elif command == "H":
for i in range(len(points)):
path.lineto(points[i], dy)
dx = points[i]
# Relative horizontal LINETO.
# Offset from the current point.
elif command == "h":
for i in range(len(points)):
path.lineto(dx+points[i], dy)
dx += points[i]
# Absolute vertical LINETO.
#.........这里部分代码省略.........