예제 #1
0
def draw_path_origin(ctx, path, last_picked_vtx_idx):
    if last_picked_vtx_idx == None:
        return

    ctx.FillColor(nvg.RGB(255, 255, 255))
    ctx.StrokeColor(nvg.RGB(255, 255, 255))
    ctx.StrokeWidth(0.01)

    i0 = -1 if last_picked_vtx_idx == 0 else 0
    i1 = -2 if last_picked_vtx_idx == 0 else 1
    p0 = copy.copy(path[i0].p)
    p1 = copy.copy(path[i1].p)
    wi = p1 - p0
    theta = np.arctan2(wi[1], wi[0])
    wi = np.array([np.cos(theta), np.sin(theta)])
    p1 = p0 + wi * 0.08

    ctx.BeginPath()
    ctx.MoveTo(p0[0], p0[1])
    ctx.LineTo(p1[0], p1[1])
    ctx.Stroke()

    wi2 = np.array([np.cos(theta+0.3), np.sin(theta+0.3)])
    wi3 = np.array([np.cos(theta-0.3), np.sin(theta-0.3)])
    p2 = p0 + wi2 * 0.08
    p3 = p0 + wi3 * 0.08
    p4 = p1 + wi  * 0.03

    ctx.BeginPath()
    ctx.MoveTo(p4[0], p4[1])
    ctx.LineTo(p2[0], p2[1])
    ctx.LineTo(p3[0], p3[1])
    ctx.LineTo(p4[0], p4[1])
    ctx.Fill()
예제 #2
0
def draw_path_tangents(ctx, path, scale=1.0):
    ctx.Save()
    ctx.FillColor(nvg.RGB(0, 0, 255))
    ctx.StrokeColor(nvg.RGB(0, 0, 255))
    ctx.StrokeWidth(0.01*scale)
    for i in range(1, len(path)-1):
        vtx = path[i]
        draw_arrow_helper(ctx, vtx.p, vtx.s, scale)
    ctx.Restore()
예제 #3
0
def draw_coord_system(ctx):
    ctx.StrokeColor(nvg.RGB(0, 0, 0))
    ctx.StrokeWidth(0.005)

    for i in range(-100, 101):
        ctx.BeginPath()
        ctx.MoveTo(-1000.0, float(i))
        ctx.LineTo(+1000.0, float(i))
        ctx.Stroke()

    for i in range(-100, 101):
        ctx.BeginPath()
        ctx.MoveTo(float(i), -1000.0)
        ctx.LineTo(float(i), +1000.0)
        ctx.Stroke()

    ctx.StrokeWidth(0.01)

    ctx.BeginPath()
    ctx.MoveTo(-1000.0, 0.0)
    ctx.LineTo(+1000.0, 0.0)
    ctx.Stroke()

    ctx.BeginPath()
    ctx.MoveTo(0.0, -1000.0)
    ctx.LineTo(0.0, +1000.0)
    ctx.Stroke()
예제 #4
0
def draw_path_vertices(ctx, path, modifier='', scale=1):
    if modifier == 'seed':
        ctx.FillColor(nvg.RGB(255, 0, 0))
    elif modifier == 'manifold':
        ctx.FillColor(nvg.RGB(114, 104, 130))
    else:
        ctx.FillColor(nvg.RGB(80, 80, 80))

    ctx.StrokeColor(nvg.RGB(255, 255, 255))
    ctx.StrokeWidth(0.005*scale)
    for i in range(0, len(path)):
        vtx = path[i]
        ctx.BeginPath()
        ctx.Circle(vtx.p[0], vtx.p[1], 0.015*scale)
        ctx.Fill()
        if modifier != 'seed':
            ctx.Stroke()
예제 #5
0
def draw_path_lines(ctx, path, modifier='', scale=1):
    if modifier == 'tangent' or modifier == 'seed':
        ctx.StrokeColor(nvg.RGB(255, 0, 0))
        ctx.StrokeWidth(0.004*scale)
    elif modifier == 'manifold':
        ctx.StrokeColor(nvg.RGB(114, 104, 130))
        ctx.StrokeWidth(0.008*scale)
    elif modifier == '':
        ctx.StrokeColor(nvg.RGB(80, 80, 80))
        ctx.StrokeWidth(0.008*scale)
    for i in range(len(path) - 1):
        v0 = path[i].p
        v1 = path[i+1].p

        ctx.BeginPath()
        ctx.MoveTo(v0[0], v0[1])
        ctx.LineTo(v1[0], v1[1])
        ctx.Stroke()
예제 #6
0
def draw_vertices(ctx, positions, color, scale=1):
    ctx.Save()
    ctx.FillColor(color)

    ctx.StrokeColor(nvg.RGB(255, 255, 255))
    ctx.StrokeWidth(0.005*scale)
    for p in positions:
        ctx.BeginPath()
        ctx.Circle(p[0], p[1], 0.015*scale)
        ctx.Fill()
        ctx.Stroke()
    ctx.Restore()
예제 #7
0
    def draw(self, ctx, scale=1.0):
        if not self.active:
            return

        if self.directional:
            if self.hover:
                ctx.StrokeColor(nvg.RGB(255, 0, 0))
                ctx.FillColor(nvg.RGB(255, 0, 0))
            else:
                ctx.StrokeColor(nvg.RGB(255, 255, 255))
                ctx.FillColor(nvg.RGB(255, 255, 255))
            p0 = self.p
            theta = np.radians(self.angle)
            wo = np.array([np.cos(theta), np.sin(theta)])
            p1 = p0 + wo * 0.1 * scale

            ctx.StrokeWidth(0.012 * scale)
            ctx.BeginPath()
            ctx.MoveTo(p0[0], p0[1])
            ctx.LineTo(p1[0], p1[1])
            ctx.Stroke()

            wo2 = np.array([np.cos(theta + 0.3), np.sin(theta + 0.3)])
            wo3 = np.array([np.cos(theta - 0.3), np.sin(theta - 0.3)])

            p2 = p0 + wo2 * 0.1 * scale
            p3 = p0 + wo3 * 0.1 * scale
            p4 = p1 + wo * 0.05 * scale

            ctx.BeginPath()
            ctx.MoveTo(p4[0], p4[1])
            ctx.LineTo(p2[0], p2[1])
            ctx.LineTo(p3[0], p3[1])
            ctx.LineTo(p4[0], p4[1])
            ctx.Fill()

        if self.hover:
            ctx.FillColor(nvg.RGB(255, 0, 0))
        else:
            ctx.FillColor(nvg.RGB(255, 255, 255))

        ctx.StrokeColor(nvg.RGB(0, 0, 0))

        ctx.StrokeWidth(0.01 * scale)

        ctx.BeginPath()
        ctx.Circle(self.p[0], self.p[1], 0.022 * scale)
        ctx.Fill()
        ctx.Stroke()
예제 #8
0
def draw_dotted_path_lines(ctx, path, scale=1.0, spacing=0.05):
    color = nvg.RGB(80, 80, 80)
    for i in range(len(path) - 1):
        v0 = path[i].p
        v1 = path[i+1].p
        draw_dotted_line(ctx, v0, v1, color, scale=scale, spacing=spacing)