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


Python Path.rect方法代码示例

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


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

示例1: parse_rect

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import rect [as 别名]
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,代码行数:29,代码来源:__init__.py

示例2: rect

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import rect [as 别名]
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,代码行数:10,代码来源:pyvector.py

示例3: parse_rect

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import rect [as 别名]
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,代码行数:11,代码来源:__init__.py

示例4: generator

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import rect [as 别名]
def generator():
    """Serve as a template for future functions that generate geometry"""
    p = Path()
    p.rect(0, 0, 100, 100)
    return p
开发者ID:alessandrostone,项目名称:nodebox,代码行数:7,代码来源:pyvector.py

示例5: l_system

# 需要导入模块: from nodebox.graphics import Path [as 别名]
# 或者: from nodebox.graphics.Path import rect [as 别名]
def l_system(shape, position, generations, length, length_scale, angle, angle_scale, thickness_scale, premise, *rules):
    if shape is None:
        p = Path()
        p.rect(0, -length/2, 2, length)
        shape = p.asGeometry()
    # Parse all rules
    rule_map = {}
    for rule_index, full_rule in enumerate(rules):
        if len(full_rule) > 0:
            if len(full_rule) < 3 or full_rule[1] != '=':
                raise ValueError("Rule %s should be in the format A=FFF" % (rule_index + 1))
            rule_key = full_rule[0]
            rule_value = full_rule[2:]
            rule_map[rule_key] = rule_value
    # Expand the rules up to the number of generations
    full_rule = premise
    for gen in xrange(int(round(generations))):
        tmp_rule = ""
        for letter in full_rule:
            if letter in rule_map:
                tmp_rule += rule_map[letter]
            else:
                tmp_rule += letter
        full_rule = tmp_rule
    # Now run the simulation
    g = Geometry()
    stack = []
    angleStack = []
    t = Transform()
    t.translate(position.x, position.y)
    angle = angle
    for letter in full_rule:
        if letter == 'F': # Move forward and draw
            transformed_shape = t.map(shape)
            if isinstance(transformed_shape, Geometry):
                g.extend(transformed_shape)
            elif isinstance(transformed_shape, Path):
                g.add(transformed_shape)
            t.translate(0, -length)
        elif letter == '+': # Rotate right
            t.rotate(angle)
        elif letter == '-': # Rotate left
            t.rotate(-angle)
        elif letter == '[': # Push state (start branch)
            stack.append(Transform(t))
            angleStack.append(angle)
        elif letter == ']': # Pop state (end branch)
            t = stack.pop()
            angle = angleStack.pop()
        elif letter == '"': # Multiply length
            t.scale(1.0, length_scale / 100.0)
        elif letter == '!': # Multiply thickness
            t.scale(thickness_scale / 100.0, 1.0)
        elif letter == ';': # Multiply angle
            angle *= angle_scale / 100.0
        elif letter == '_': # Divide length
            t.scale(1.0, 1.0/(length_scale / 100.0))
        elif letter == '?': # Divide thickness
            t.scale(1.0/(thickness_scale / 100.0), 1.0)
        elif letter == '@': # Divide angle
            angle /= angle_scale / 100.0
    return g
开发者ID:cleliodpaula,项目名称:nodebox,代码行数:64,代码来源:l_system.py


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