当前位置: 首页>>代码示例>>Python>>正文


Python Path.curveto方法代码示例

本文整理汇总了Python中nodebox.graphics.Path.curveto方法的典型用法代码示例。如果您正苦于以下问题:Python Path.curveto方法的具体用法?Python Path.curveto怎么用?Python Path.curveto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nodebox.graphics.Path的用法示例。


在下文中一共展示了Path.curveto方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _update_path

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import curveto [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
开发者ID:cleliodpaula,项目名称:nodebox,代码行数:27,代码来源:bezierpatheditor.py

示例2: quad_curve

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import curveto [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
开发者ID:alessandrostone,项目名称:nodebox,代码行数:20,代码来源:pyvector.py

示例3: link

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import curveto [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
开发者ID:alessandrostone,项目名称:nodebox,代码行数:20,代码来源:pyvector.py

示例4: parse_path

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import curveto [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
开发者ID:RyanHun,项目名称:nodebox,代码行数:98,代码来源:__init__.py

示例5: parse_path

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import curveto [as 别名]

#.........这里部分代码省略.........

        # 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.
        # Only the horizontal coordinate is supplied.
        if command == "V":
            for i in range(len(points)):
                path.lineto(dx, points[i])
                dy = points[i]

        # Relative vertical LINETO.
        # Offset from the current point.
        elif command == "v":
            for i in range(len(points)):
                path.lineto(dx, dy+points[i])
                dy += points[i]

        # Absolute CURVETO.
        # Draw a bezier with given control handles and destination.
        elif command == "C":
            for i in range(len(points)/6):
                path.curveto(points[i*6],   points[i*6+1], 
                             points[i*6+2], points[i*6+3], 
                             points[i*6+4], points[i*6+5])
                dhx = points[i*6+2]
                dhy = points[i*6+3]
                dx = points[i*6+4]
                dy = points[i*6+5]
        
        # Relative CURVETO.
        # Offset from the current point.
        elif command == "c":
            for i in range(len(points)/6):
                path.curveto(dx+points[i*6],   dy+points[i*6+1], 
                             dx+points[i*6+2], dy+points[i*6+3], 
                             dx+points[i*6+4], dy+points[i*6+5])
                dhx = dx+points[i*6+2]
                dhy = dy+points[i*6+3]
                dx += points[i*6+4]
                dy += points[i*6+5]

        # Absolute reflexive CURVETO.
        # Only the second control handle is given,
        # the first is the reflexion of the previous handle.
        elif command == "S":
            for i in range(len(points)/4):
                if previous_command not in ["C", "c", "S", "s"]:
                    dhx = dx
                    dhy = dy
                else:
                    dhx = dx-dhx
                    dhy = dy-dhy
                path.curveto(dx+dhx, dy+dhy, 
                             points[i*4],   points[i*4+1], 
开发者ID:DimosN,项目名称:nodebox,代码行数:70,代码来源:__init__.py


注:本文中的nodebox.graphics.Path.curveto方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。