示例#1
0
def draw_edge(graph, edge):
    pos = edge.get_pos()

    if len(pos) >= 2 and pos[0] == '"' and pos[-1] == '"':
        pos = pos[1:-1]
    
    # split into vertices
    vertices = re.split(" ", pos)
    control_pts = []
    arrow_head = (None, None)

    for v in vertices:
        if v[0] == "e":
            arrow_head = ("end", map(float, v[2:].split(",")))
        elif v[0] == "s":
            arrow_head = ("start", map(float, v[2:].split(",")))
        else:
            control_pts.extend(map(float, v.split(",")))
    
    curve = shapes.bezier_curve(control_pts, ndivs=20)
    
    #target = graph.get_node('"' + edge.get_destination() + '"')
    target = graph.get_node(edge.get_destination())

    print vertices, target

    target_pos = map(float, target.get_pos().split(","))
    
    source = graph.get_node('"' + edge.get_source() + '"')
    source_pos = map(float, source.get_pos().split(","))

    edge_color = colors.black
    
    if arrow_head[0] == "start":
        return group(edge_color,
                     lines(source_pos[0], source_pos[1], 
                           control_pts[0], control_pts[1]),
                     line_strip(*curve),
                     lines(target_pos[0], target_pos[1], 
                           control_pts[-2], control_pts[-1]),
                     shapes.arrow(arrow_head[1][0], arrow_head[1][1],
                                  control_pts[0], control_pts[1],
                                  head_size=7))
    elif arrow_head[0] == "end":
        return group(edge_color, 
                     lines(source_pos[0], source_pos[1], 
                           control_pts[0], control_pts[1]),
                     line_strip(*curve),
                     lines(target_pos[0], target_pos[1], 
                           control_pts[-2], control_pts[-1]),
                     colors.red,
                     zoom_clamp(
                         shapes.arrow_head(arrow_head[1][0], arrow_head[1][1], 
                                           control_pts[-2], control_pts[-1],
                                           size=7),
                         origin=target_pos,
                         axis=arrow_head[1],
                         maxx=1, maxy=1, minx=.1, miny=.1, 
                         clip=True, link=True, link_type="smaller"))
    else:
        return group(edge_color, 
                     lines(source_pos[0], source_pos[1], 
                           control_pts[0], control_pts[1]),
                     line_strip(*curve),
                     lines(target_pos[0], target_pos[1], 
                           control_pts[-2], control_pts[-1]))
示例#2
0
文件: arrows.py 项目: mdrasmus/summon
#!/usr/bin/env python-i

import math

from summon.core import *
import summon
from summon import shapes, colors, util



win = summon.Window("arrows")

radius = 100
for angle in util.frange(0, 2*math.pi, math.pi / 10):
    x = radius * math.cos(angle)
    y = radius * math.sin(angle)
    win.add_group(shapes.arrow(x, y, 0, 0))
    #win.add_group(rotate(180/math.pi*angle, shapes.arrow(100, 0, 0, 0)))

win.home()