• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python graphics.Path类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Path类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:RyanHun,项目名称:nodebox,代码行数:27,代码来源:__init__.py


示例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
开发者ID:alessandrostone,项目名称:nodebox,代码行数:7,代码来源:pyvector.py


示例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
开发者ID:alessandrostone,项目名称:nodebox,代码行数:8,代码来源:pyvector.py


示例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
开发者ID:gleb-svechnikov,项目名称:cbm,代码行数:8,代码来源:supershape.py


示例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
开发者ID:alessandrostone,项目名称:nodebox,代码行数:58,代码来源:pyvector.py


示例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
开发者ID:RyanHun,项目名称:nodebox,代码行数:9,代码来源:__init__.py


示例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
开发者ID:DimosN,项目名称:nodebox,代码行数:9,代码来源:__init__.py


示例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
开发者ID:DimosN,项目名称:nodebox,代码行数:9,代码来源:__init__.py


示例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
开发者ID:alessandrostone,项目名称:nodebox,代码行数:10,代码来源:pyvector.py


示例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
开发者ID:DimosN,项目名称:nodebox,代码行数:10,代码来源:__init__.py


示例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
开发者ID:cleliodpaula,项目名称:nodebox,代码行数:11,代码来源:corevector.py


示例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
开发者ID:gleb-svechnikov,项目名称:cbm,代码行数:11,代码来源:supershape.py


示例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
开发者ID:RyanHun,项目名称:nodebox,代码行数:12,代码来源:__init__.py


示例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
开发者ID:cleliodpaula,项目名称:nodebox,代码行数:14,代码来源:packing.py


示例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
开发者ID:nodebox,项目名称:nodebox-workshop,代码行数:14,代码来源:__init__.py


示例16: _function

 def _function(shape, *args, **kwargs):
     from java.util import List
     if isinstance(shape, (list, tuple, List)):
         return fn(shape, *args, **kwargs)
     elif isinstance(shape, Path):
         new_path = Path(shape, False)
         for c in shape.contours:
             new_path.add(Contour(fn(c.points, *args, **kwargs), c.closed))
         return new_path
     elif isinstance(shape, Geometry):
         new_geo = Geometry()
         for path in shape.paths:
             new_geo.add(_map_geo_to_points(fn)(path, *args, **kwargs))
         return new_geo
     return None
开发者ID:alessandrostone,项目名称:nodebox,代码行数:15,代码来源:pyvector.py


示例17: parse_ellipse

def parse_ellipse(e):
    
    cx = float(get_attribute(e, "cx"))
    cy = float(get_attribute(e, "cy"))
    rx = float(get_attribute(e, "rx"))
    ry = float(get_attribute(e, "ry"))
    if rx < 0:
        print >> sys.stderr, "Error: invalid negative value for <ellipse> attribute rx=\"%s\"" % rx
        rx = 0
    if ry < 0:
        print >> sys.stderr, "Error: invalid negative value for <ellipse> attribute ry=\"%s\"" % ry
        ry = 0
    p = Path()
    p.ellipse(cx, cy, rx * 2, ry * 2)
    p.close()
    return p
开发者ID:RyanHun,项目名称:nodebox,代码行数:16,代码来源:__init__.py


示例18: connect

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
开发者ID:alessandrostone,项目名称:nodebox,代码行数:16,代码来源:pyvector.py


示例19: angle_pack

def angle_pack(shapes, seed, limit, maximum_radius, angle_tries=1, use_bounding_box=False):
    if shapes is None: return None
    _seed(seed)

    def center_and_translate(shape, tx=0, ty=0):
        bx, by, bw, bh = list(shape.bounds)
        t = Transform()
        t.translate(-bw / 2 - bx, -bh / 2 - by)
        return t.map(shape)

    geo = Geometry()
    bounding_path = Path()

    # Center first shape
    first_shape = center_and_translate(shapes[0])
    geo.add(first_shape)
    bounding_path.cornerRect(first_shape.bounds)

    for shape in shapes[1:]:
        centered_shape = center_and_translate(shape)

        angles = []
        for i in range(angle_tries):
            a = uniform(0, 360)
            if use_bounding_box:
                d = try_angle(bounding_path, centered_shape, a, limit, maximum_radius, use_bounding_box)
            else:
                d = try_angle(geo, centered_shape, a, limit, maximum_radius, use_bounding_box)
            angles.append([d, a])
        chosen_distance, chosen_angle = sorted(angles)[0]

        tx, ty = coordinates(0, 0, chosen_distance, chosen_angle)
        t = Transform()
        t.translate(tx, ty)
        translated_shape = t.map(centered_shape)
        bounding_path.cornerRect(translated_shape.bounds)
        geo.add(translated_shape)

    return geo
开发者ID:cleliodpaula,项目名称:nodebox,代码行数:39,代码来源:packing.py


示例20: star

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
开发者ID:alessandrostone,项目名称:nodebox,代码行数:12,代码来源:pyvector.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python graphics.Transform类代码示例发布时间:2022-05-27
下一篇:
Python graphics.Geometry类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap