Beispiel #1
0
def drawLineGrapic8(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2

    N = 10
    margin = 6
    pts = random_coordinates(margin, W - margin, margin, H - margin, N=N)
    pts = center_cordinates(pts, (cx, cy))

    length = len(pts)
    c1 = random_color_hsv()
    c2 = random_color_hsv()
    stroke = 0.5
    for i, pt in enumerate(pts):
        # print(pt)
        p1 = pt
        if i == length - 1:
            p2 = pts[0]
        else:
            p2 = pts[i + 1]

        stroke += 1.6
        color = color_fader(c1, c2, i / length)

        # style1: lines
        node = svg.draw(
            draw_line(p1[0],
                      p1[1],
                      p2[0],
                      p2[1],
                      stroke_width=stroke,
                      color=color))
Beispiel #2
0
def drawlinePoints(svg, pts, node=None, stroke_width=0.5, color=None, stroke_widths=None, dash=None):
    for i, pt in enumerate(pts):
        x1, y1, x2, y2 = pt
        x1 = clip_float(x1)
        y1 = clip_float(y1)
        x2 = clip_float(x2)
        y2 = clip_float(y2)
        if stroke_widths:
            stroke_width = stroke_widths[i]
        svg.draw_node(node, draw_line(x1, y1, x2, y2, stroke_width=stroke_width, color=color or random_color(), stroke_dasharray=dash))
Beispiel #3
0
def drawlinePointsContinus(svg, pts, stroke_width=0.5, color=None, stroke_widths=None):
    n = len(pts)
    for i in range(n - 1):
        (x1, y1), (x2, y2) = pts[i], pts[i + 1]

        x1 = clip_float(x1)
        y1 = clip_float(y1)
        x2 = clip_float(x2)
        y2 = clip_float(y2)
        if stroke_widths:
            stroke_width = stroke_widths[i]
        svg.draw(draw_line(x1, y1, x2, y2, stroke_width=stroke_width, color=color or random_color()))
Beispiel #4
0
def drawlinePointsContinusRainbow(svg, pts, stroke_width=0.5, color=None, colors=None, stroke_widths=None):
    # c = rainbow_colors(N=len(pts))
    for i in range(len(pts) - 1):
        (x1, y1), (x2, y2) = pts[i], pts[i + 1]

        x1 = clip_float(x1)
        y1 = clip_float(y1)
        x2 = clip_float(x2)
        y2 = clip_float(y2)
        if stroke_widths:
            stroke_width = stroke_widths[i]
        if colors:
            color = colors[i]
        # color = c[i]

        svg.draw(draw_line(x1, y1, x2, y2, stroke_width=stroke_width, color=color))
def draw_basic_shapes(svg):
    svg.draw(sb.draw_rect(x=3, y=3, width=20, height=20, stroke_width=1,
                          color='transparent', stroke_color='black'))
    rt = svg.draw(sb.draw_rect(x=28, y=3, width=20, height=20, stroke_width=1,
                               color='transparent', stroke_color='red'))

    svg.set_node(rt, 'rx', '2')
    svg.set_node(rt, 'ry', '2')
    svg.draw(sb.draw_circle(x=60, y=13, radius=10, color='green'))
    svg.draw(sb.draw_ring(x=85, y=13, radius=8, stroke_color='red', stroke_width=3))
    svg.draw(sb.draw_ellipse(cx=25, cy=35, rx=20, ry=8))
    svg.draw(sb.draw_line(x=50, y=30, x2=90, y2=45, stroke_width=1, color='#23ff67'))

    points = '8 50 18 70 28 50 38 70 48 50 58 70 68 50 78 70 88 50 98 70'
    svg.draw(sb.draw_polyline(points, stroke_width=0.5, stroke_color=random_color()))

    points = '8 75 25 75 30 95 5 95'
    svg.draw(sb.draw_polygon(points, stroke_width=0.5, stroke_color=random_color()))

    path = 'M 35 90 Q 55 60 98 90'
    svg.draw(sb.draw_path(path, stroke_width=0.2, color=random_color()))
Beispiel #6
0
 def DrawLineByPt(self, startPt, stopPt):
     if startPt[0] > stopPt[0]:  # switch
         startPt = startPt + stopPt
         stopPt = startPt - stopPt
         startPt = startPt - stopPt
     self.svg.draw(draw_line(startPt[0], startPt[1], stopPt[0], stopPt[1]))
def draw_first(svg):
    H, W = svg.get_size()
    svg.draw(draw_line(0, 0, W, H))
def anim9(svg):
    """moving ball bounce with a line"""
    H, W = svg.get_size()
    cx, cy = W // 2, H // 2

    g = svg.draw(draw_tag('g'))
    svg.set_node(g, 'opacity', '1.0')

    wall_line = [2, -1.8, 1]  # line parameters
    pt = random_point(4, W - 5)
    print(pt, type(pt))
    vx = -2
    vy = 1

    res = get_math_bounce_parameter(wall_line, pt, vx, vy)
    perpend_pt, reflect_pt, inter_pt, path_line, reflect_line = res

    # draw_line_param(svg, g, a, b, 0, W)
    pts = draw_line_param_abc(wall_line, 0, W, 0, H)
    drawlinePoints(svg, pts, g, color='black')

    svg.draw_node(g, draw_circle(pt[0], pt[1], 1, color='black'))
    svg.draw_node(g, draw_circle(perpend_pt[0], perpend_pt[1], 1, color='red'))
    svg.draw_node(g, draw_circle(reflect_pt[0], reflect_pt[1], 1, color='red'))
    svg.draw_node(g, draw_circle(inter_pt[0], inter_pt[1], 1, color='black'))

    svg.draw_node(
        g,
        draw_line(pt[0],
                  pt[1],
                  reflect_pt[0],
                  reflect_pt[1],
                  stroke_dasharray="2"))
    svg.draw_node(
        g,
        draw_line(inter_pt[0],
                  inter_pt[1],
                  reflect_pt[0],
                  reflect_pt[1],
                  stroke_dasharray="2"))

    if inter_pt is not None:
        min_x = min(pt[0], inter_pt[0])
        max_x = max(pt[0], inter_pt[0])
        min_y = min(pt[1], inter_pt[1])
        max_y = min(pt[1], inter_pt[1])
        pts = draw_line_param_abc(path_line, min_x, max_x, min_y, max_y)
        drawlinePoints(svg, pts, g, color='black')

    coords = [pt, inter_pt]
    if reflect_pt is not None:
        min_x, max_x = 0, W
        min_y, max_y = 0, H

        far_pt = [0, 0]
        if reflect_pt[0] < inter_pt[0]:
            min_x = inter_pt[0]

            far_pt[0] = max_x
            far_pt[1] = get_line_ABC_y(reflect_line, far_pt[0])
        else:
            max_x = inter_pt[0]
            far_pt[0] = min_x
            far_pt[1] = get_line_ABC_y(reflect_line, far_pt[0])

        pts = draw_line_param_abc(reflect_line, min_x, max_x, min_y, max_y)
        drawlinePoints(svg, pts, g, color='black')

        coords.append(far_pt)
        coords = np.asarray(coords)
        print('coords=', coords, coords.shape)
    path = get_points_path(coords, False)
    draw_circle_path_anim(svg,
                          g,
                          path,
                          radius=6,
                          duration=len(coords) * 1.0,
                          color='red')