Exemplo n.º 1
0
def svg_path(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2
    N = 400
    xoffset = 0.5
    x = np.linspace(xoffset, 10 - xoffset, N) * 10

    y = funcSin(x / 3) * 30
    x, y = translation_pts_xy(x, y, (0, cy))
    draw_points_svg(svg, x, y)

    x1, y1 = rotation_pts_xy_point(x, y, (0, cy), -1 * np.pi / 6)
    draw_points_svg(svg, x1, y1)
    x2, y2 = rotation_pts_xy_point(x, y, (0, cy), np.pi / 6)
    draw_points_svg(svg, x2, y2)
Exemplo n.º 2
0
def drawLsoscelesTrianglePoints(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2

    times = 40
    width = 0
    rotation = True
    for _ in range(times):
        # width = width + 4
        width = 160

        x = []
        y = []

        # pt1 = (cx - width/2, cy + (width/2)*np.tan(np.pi/6))
        # pt2 = (cx + width/2, cy + (width/2)*np.tan(np.pi/6))
        # pt3 = (cx, cy - (width/2)*(np.tan(np.pi/3) - np.tan(np.pi/6)))
        x.append(cx - width / 2)
        x.append(cx + width / 2)
        x.append(cx)
        x = np.array(x)

        y.append(cy + (width / 2) * np.tan(np.pi / 6))
        y.append(cy + (width / 2) * np.tan(np.pi / 6))
        y.append(cy - (width / 2) * (np.tan(np.pi / 3) - np.tan(np.pi / 6)))
        y = np.array(y)

        if rotation:
            # theta = i*2*np.pi/(times+1)
            theta = random.random() * 2 * np.pi
            x, y = rotation_pts_xy_point(x, y, (cx, cy), theta)

        drawTrianglePointsXY(svg, x, y)
def drawRandomRectanglePath(svg):
    W, H = svg.get_size()
    styles = ['rectangle', 'rectangle roation', 'rotataion Center']

    onlyPath = False
    times = 80
    w = 2
    h = w
    offsetX = 5
    offsetY = 5
    style = styles[2]

    if style == styles[0]:
        for _ in range(times):
            w = w + random.random() * 4
            h = w
            ptX, ptY, _ = getRectanglePtsSVG(w, h, N=20, noise=True)
            ptX = ptX + offsetX
            ptY = ptY + offsetY
            drawOnePathcSVG(svg, ptX, ptY, onlyPath=onlyPath)

    elif style == styles[1]:
        times = 150
        offsetX = W // 2
        offsetY = H // 2
        theta = 0
        for _ in range(times):
            w = w + random.random() * 1
            h = w
            ptX, ptY, center = getRectanglePtsSVG(w, h, N=20, noise=False)

            ptX, ptY = rotation_pts_xy(ptX, ptY, theta)
            theta = theta + 2 * np.pi / (times - 1)

            ptX = ptX + offsetX
            ptY = ptY + offsetY
            drawOnePathcSVG(svg, ptX, ptY, width=0.5, onlyPath=onlyPath)
    elif style == styles[2]:
        times = 120
        offsetX = 20  # W//2
        offsetY = 20  # H//2
        theta = 0
        for _ in range(times):
            offsetX = offsetX + random.random() * 1  # 8
            w = w + random.random() * 1
            h = w
            ptX, ptY, center = getRectanglePtsSVG(w, h, N=30, noise=True)

            ptX, ptY = rotation_pts_xy_point(ptX, ptY, center, theta)
            theta = theta + 2 * np.pi / (times - 1)

            ptX = ptX + offsetX
            ptY = ptY + offsetY
            drawOnePathcSVG(svg, ptX, ptY, width=0.5, onlyPath=onlyPath)

    print(w, H)
Exemplo n.º 4
0
def drawPointsLineGraphic7(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2

    r = 50
    x0 = [cx, cx + 2 * r, cx + r]
    y0 = [cy, cy, cy - r * np.tan(np.pi / 6)]

    times = 8
    theta = 0
    for i in range(times):
        theta = i * (2 * np.pi / times)
        x, y = rotation_pts_xy_point(x0, y0, (cx, cy), theta)
        drawPloygon(svg, [(x[0], y[0]), (x[1], y[1]), (x[2], y[2])], color='black')
Exemplo n.º 5
0
def svg_path5(svg):
    W, H = svg.get_size()

    cx, cy = W // 2, H // 2
    pts = get_5star(R=40, r=10)
    pts = np.hsplit(pts, 2)
    x, y = pts[0].ravel(), pts[1].ravel()

    ptx, pty = translation_pts_xy(x, y, (cx, cy))

    times = 18
    for i in range(times):
        theta = i * (2 * np.pi / times)
        x, y = rotation_pts_xy_point(ptx, pty, (cx, cy), theta)
        draw_points_svg(svg, x, y, color='green', close=True)
Exemplo n.º 6
0
def svg_path3(svg, anim=True):
    def drawStyleText(svg):
        styleDict = {}
        # styleDict['fill'] = 'black'
        styleDict['font-family'] = 'Consolas'
        styleDict['font-size'] = '10px'
        styleList = get_styles(styleDict)

        svg.draw(add_style('text', styleList))

    W, H = svg.get_size()
    cx, cy = W // 2, H // 2
    N = 400
    xoffset = 0.2
    x = np.linspace(xoffset, 5 - xoffset, N) * 20
    y = funcSin(x / 0.6) * x / 3

    x, y = translation_pts_xy(x, y, (cx, cy))
    # draw_points_svg(svg, x, y)

    # drawStyleText(svg)
    # svg.draw(draw_text(5, 10, 'y=sin(x)'))

    N = 10
    for i in range(N):
        ptx, pty = rotation_pts_xy_point(x, y, (cx, cy), i * 2 * np.pi / N)
        node = draw_points_svg(svg, ptx, pty)

        if anim:
            animateTransDict = {}
            animateTransDict['attributeName'] = 'transform'
            animateTransDict['attributeType'] = 'xml'
            animateTransDict['type'] = 'rotate'
            animateTransDict['from'] = f'0 {cx} {cy}'
            animateTransDict['to'] = f'360 {cx} {cy}'
            animateTransDict['dur'] = '8s'
            animateTransDict["repeatCount"] = "indefinite"  # "5"

            addNodeAnitmation(svg,
                              node,
                              animateTransDict,
                              elementName='animateTransform')
def drawNodeShape(svg, node):
    H, W = svg.get_size()
    cx, cy = W // 2, H // 2
    r = 45

    angle = np.pi / 5
    x0 = [cx, cx + 2 * r, cx + r]
    y0 = [cy, cy, cy - r * np.tan(angle)]
    # print('x0 ,y0=', x0 ,y0)

    times = 8
    theta = 0
    rainbowC = rainbow_colors(times)
    for i in range(times):
        theta = i * (2 * np.pi / times)
        x, y = rotation_pts_xy_point(x0, y0, (cx, cy), theta)
        color = random_color_hsv()
        # color = random_color()
        drawPloygonNode(svg,
                        node=node,
                        pts=[(x[0], y[0]), (x[1], y[1]), (x[2], y[2])],
                        color=color)
        # drawPloygonNode(svg, node=node, pts=[(x[0],y[0]), (x[1],y[1]), (x[2],y[2])], color=rainbowC[i])

        # --------- draw text-------------- #
        dis = get_distance([x0[0], y0[0]], [x0[1], y0[1]])
        x_t = x0[0] + dis * 1.5 / 3
        y_t = y0[0] - (dis * 1.5 / 3) * np.tan(angle) * 0.6 / 2

        x_t = clip_float(x_t, 2)
        y_t = clip_float(y_t, 2)

        # print('x_t, y_t=', x_t, y_t)
        txt_child = svg.draw_node(
            node, draw_text(x_t, y_t, 'Love', color=reverse_hex(color)))

        strTmp = 'rotate({},{},{})'.format(i * 360 / times, x0[0], y0[0])
        svg.set_node(txt_child, 'transform', strTmp)
        svg.set_node(txt_child, 'text-anchor', 'middle')
        svg.set_node(txt_child, 'dominant-baseline', 'central')
Exemplo n.º 8
0
def drawLineGrapic4(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2
    length = 160

    pt1 = (0, -1 * (length / 2) / np.cos(np.pi / 6))
    pt2 = (-1 * length / 2, length / 2 * np.tan(np.pi / 6))
    pt3 = (length / 2, length / 2 * np.tan(np.pi / 6))
    x = [pt1[0], pt2[0], pt3[0]]
    y = [pt1[1], pt2[1], pt3[1]]
    x, y = translation_pts_xy(x, y, (cx, cy))
    pt1 = (x[0], y[0])
    pt2 = (x[1], y[1])
    pt3 = (x[2], y[2])

    N = 20
    for i in range(N + 1):
        newX, newY = rotation_pts_xy_point(x,
                                           y, (cx, cy),
                                           theta=i * np.pi / 6 / N)
        newX, newY = zoom_pts_xy_point(newX, newY, (cx, cy), z=1 - 0.8 * i / N)
        drawTrianglePointsXY(svg, newX, newY, stroke_width=0.5, color='black')