Example #1
0
def drawFuncSVG2(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2
    N = 100

    ptX, ptY = getCirclePoints(r=45, N=N, func=heartFuc)
    ptX, ptY = reflect_xy(ptX, ptY)
    ptX, ptY = translation_pts_xy(ptX, ptY, (cx, cy))
    drawOneFuncSVG(svg, ptX, ptY, N=N, color=random_color_hsv())

    ptX = np.linspace(-50, 50, num=200)
    ptY = funcQuadratic(ptX)
    ptX, ptY = reflect_xy(ptX, ptY)
    ptX, ptY = translation_pts_xy(ptX, ptY, (cx, cy+40))
    drawOneFuncSVG(svg, ptX, ptY, N=N, color=random_color_hsv())

    ptX = np.linspace(-50, 50, num=200)
    ptY = funcSin(ptX)*20
    ptX, ptY = reflect_xy(ptX, ptY)
    ptX, ptY = translation_pts_xy(ptX, ptY, (cx, cy))
    drawOneFuncSVG(svg, ptX, ptY, N=N, color=random_color_hsv())

    ptX = np.linspace(-50, 50, num=200)
    ptY = funcCos(ptX)*20
    ptX, ptY = reflect_xy(ptX, ptY)
    ptX, ptY = translation_pts_xy(ptX, ptY, (cx, cy))
    drawOneFuncSVG(svg, ptX, ptY, N=N, color=random_color_hsv())

    ptX = np.linspace(-50, 50, num=200)
    ptY = sigmoid(ptX)
    ptX, ptY = reflect_xy(ptX, ptY)
    ptX, ptY = translation_pts_xy(ptX, ptY, (cx, cy))
    drawOneFuncSVG(svg, ptX, ptY, N=N, color=random_color_hsv())
Example #2
0
def svg_transformation_cust(svg):
    """custom transform"""
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2
    pts = get_5star(R=25, r=15)
    # print('pts=', pts, pts.shape)

    px, py = translation_pts(pts, (cx - 15, cy - 15))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color='green',
                    fillColor='green',
                    close=True)

    matrix = np.array([[0.2, 0.3], [-1.2, 0.1]])

    px, py = transform_any_points(pts, matrix)
    px, py = translation_pts_xy(px, py, (cx + 15, cy + 15))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color='green',
                    fillColor='green',
                    close=True)
Example #3
0
def drawArrowCircleLine(svg):
    def getPointCircle(r, theta):
        # return np.array([[r*np.cos(theta), r*np.sin(theta)]])
        return (r * np.cos(theta), r * np.sin(theta))

    def getTwinPoints(r, theta, sTheta=2 * np.pi / 80):
        pt1 = getPointCircle(r, theta - sTheta / 2)
        pt2 = getPointCircle(r, theta + sTheta / 2)
        return pt1, pt2

    W, H = svg.get_size()
    cx, cy = W // 2, H // 2
    N = 40
    R0 = 80
    rMin = 8
    rMax = 30
    theta = 0
    for i in range(1, N):
        theta = theta + 2 * np.pi / (N - 1)
        R = R0 + random.normalvariate(mu=0, sigma=1) * 3
        r = random.choice(np.linspace(rMin, rMax, 10))

        ptInner = getPointCircle(r, theta)
        sTheta = 2 * np.pi / random.choice(range(80, 200, 2))
        ptOuter1, ptOuter2 = getTwinPoints(R, theta, sTheta=sTheta)

        x = [ptInner[0], ptOuter1[0], ptOuter2[0]]
        y = [ptInner[1], ptOuter1[1], ptOuter2[1]]

        x, y = translation_pts_xy(x, y, (cx, cy))
        # drawTrianglePoints(svg,(x[0],y[0]), (x[1],y[1]), (x[2],y[2]))
        drawPloygon(svg, [(x[0], y[0]), (x[1], y[1]), (x[2], y[2])],
                    color='black')
Example #4
0
def svg_path7(svg):
    W, H = svg.get_size()
    # dictStyle = {'stroke-width': "0.4", 'fill': "transparent"}
    # dictStyle = {'stroke-width': "0.4", 'fill': "transparent", 'stroke': "green"}
    dictStyle = {'stroke-width': "0.4", 'stroke': "green"}
    styleList = get_styles(dictStyle)
    svg.draw(add_style('path', styleList))

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

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

    times = 68
    pts = random_points((times, 2), 0, W)
    for i in range(times):
        z = i / times

        x, y = zoom_pts_xy_point(ptx, pty, (pts[i][0], pts[i][1]), z)

        color = None  # random_color_hsv()
        draw_points_svg(svg,
                        x,
                        y,
                        stroke=None,
                        color=color,
                        fillColor=random_color_hsv(),
                        close=True)
Example #5
0
def transform_points(de_points, zoom_x=0.5, zoom_y=0.5, to_point=(0, 0)):
    de_points = [[i.x, i.y] for i in de_points]
    de_points = np.asarray(de_points)
    # print('de_points=', de_points, de_points.shape)

    # start to translate
    x, y = split_points(de_points)
    # x, y = zoom_pts_xy(x, y, zoom)
    x, y = zoom_non_pts_xy(x, y, zoom_x, zoom_y)
    x, y = translation_pts_xy(x, y, to_point)
    return combine_xy(x, y)
Example #6
0
def draw_path_star2(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2
    pts = get_5star(R=70, r=30)
    # print('pts=', pts, pts.shape)

    x, y = split_points(pts)
    x, y = translation_pts_xy(x, y, (cx, cy))
    # print('x=', x)
    # print('y=', y)
    draw_points_svg(svg, x, y, color='green', close=True)
Example #7
0
def drawLineGrapic6(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2

    N = 18
    xs, ys = [], []
    r1 = 50
    r2 = 80
    for i in range(N + 1):
        theta = i * 2 * np.pi / N
        x = r1 * np.cos(theta)
        y = r1 * np.sin(theta)
        xs.append(x)
        ys.append(y)

    xs, ys = translation_pts_xy(xs, ys, (cx, cy))
    pts = np.vstack((xs, ys)).T
    linePts = []
    for i in pts:
        linePts.append((cx, cy, i[0], i[1]))
    drawlinePoints(svg, linePts, color='black')
    drawPointsCircle(svg, pts, r=5, color='#000000')

    xs, ys = [], []
    for i in range(N + 1):
        theta = i * 2 * np.pi / N + np.pi / N
        x = r2 * np.cos(theta)
        y = r2 * np.sin(theta)
        xs.append(x)
        ys.append(y)

    xs, ys = translation_pts_xy(xs, ys, (cx, cy))
    pts = np.vstack((xs, ys)).T
    linePts = []
    for i in pts:
        linePts.append((cx, cy, i[0], i[1]))
    drawlinePoints(svg, linePts, color='black')
    # drawPointsCircle(svg, pts, r=5, color='#808B96')
    drawPointsCircleFadeColor(svg, pts, r=5)
Example #8
0
def svg_path2(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2
    N = 400
    xoffset = 0.5
    x = np.linspace(xoffset, 10 - xoffset, N) * 20
    y = funcSin(x / 2) * 20

    for i in range(4):
        offsetY = i * H // 4 + 20 + 5
        ptx, pty = translation_pts_xy(x, y, (0, offsetY))

        stroke = clip_float(random.random() * 2)
        draw_points_svg(svg, ptx, pty, stroke=stroke)
Example #9
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)
Example #10
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)
Example #11
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')
Example #12
0
def svg_path6(svg):
    W, H = svg.get_size()

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

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

    times = 28
    for i in range(times):
        z = i**2 / 180  # i*0.5
        x, y = zoom_pts_xy_point(ptx, pty, (cx, cy), z)
        draw_points_svg(svg,
                        x,
                        y,
                        color=random_color_hsv(),
                        stroke=0.4,
                        close=True)
Example #13
0
def svg_path4(svg):
    W, H = svg.get_size()
    # svg.set_background('#eeeeee')

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

    # draw one 5-pointed star
    # ptx, pty = translation_pts_xy(x, y, (cx, cy))
    # draw_points_svg(svg, ptx, pty, color='green', close=True)

    # draw random 5-pointed stars
    N = 30  # total points
    margin = 10  # margin to border
    pts = random_points((N, 2), min=10, max=W - margin)

    for pt in pts:
        ptx, pty = translation_pts_xy(x, y, (pt[0], pt[1]))
        draw_points_svg(svg, ptx, pty, color=random_color_hsv(), close=True)
Example #14
0
def drawLineGrapic5(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2

    N = 40
    layer = 14
    r0 = 5
    for k in range(layer + 1):
        xs, ys = [], []

        r = r0 + 6 * k
        th0 = 2 * k * np.pi / layer
        for i in range(N + 1):
            theta = i * 2 * np.pi / N + th0
            x = r * np.cos(theta)
            y = r * np.sin(theta)
            xs.append(x)
            ys.append(y)

        xs, ys = translation_pts_xy(xs, ys, (cx, cy))
        pts = np.vstack((xs, ys)).T
        drawPointsCircle(svg, pts, r=0.2 + k / 5)
Example #15
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')
Example #16
0
def drawLineGrapic3(svg):
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2
    length = 160

    pt1 = (-1 * length / 2, -1 * length / 2 * np.tan(np.pi / 6))
    pt2 = (length / 2, -1 * length / 2 * np.tan(np.pi / 6))
    pt3 = (0, (length / 2) / np.cos(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
    pts = []

    s, b = get_line(pt2, pt3)
    for i in range(N + 1):
        xn = pt3[0] + np.abs(pt2[0] - pt3[0]) * i / N
        yn = s * xn + b
        pts.append((pt1[0], pt1[1], xn, yn))

    s, b = get_line(pt1, pt3)
    for i in range(N + 1):
        xn = pt1[0] + np.abs(pt1[0] - pt3[0]) * i / N
        yn = s * xn + b
        pts.append((pt2[0], pt2[1], xn, yn))

    s, b = get_line(pt1, pt2)
    for i in range(N + 1):
        xn = pt1[0] + np.abs(pt1[0] - pt2[0]) * i / N
        yn = s * xn + b
        pts.append((pt3[0], pt3[1], xn, yn))

    drawlinePoints(svg, pts, color='black')
Example #17
0
def svg_transformation(svg):
    """basic transforms demonstration"""
    W, H = svg.get_size()

    pts = get_5star(R=9, r=6)
    print('pts=', pts, pts.shape)
    fillColor = 'green'  # random_color_hsv()
    stroke_w = 0.3
    stroke_color = None
    line_color = 'green'
    N = 5  # lines
    hinter = H // N
    text_w = 22
    start_w = (W - text_w) // 2
    text_x = 1
    text_y = 10
    fontsize = '3px'
    offet_x, offet_y = 15, 11

    # start to draw
    path = f'M{text_w} 0 V{H}'
    svg.draw(draw_path(path, stroke_width=stroke_w, color=line_color))

    # draw grid lines
    for i in range(N):
        path = f'M0 {i * hinter} h{W}'
        svg.draw(draw_path(path, stroke_width=stroke_w, color=line_color))

    # start translation
    txt = 'Translation:'
    svg.draw(draw_text(x=text_x, y=text_y, text=txt, fontsize=fontsize))

    x, y = split_points(pts)
    cx = text_w + offet_x
    cy = offet_y
    px, py = translation_pts(pts, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)

    cx += start_w
    px, py = translation_pts(pts, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)

    # start rotation
    text_y += hinter
    txt = 'Rotation:'
    svg.draw(draw_text(x=text_x, y=text_y, text=txt, fontsize=fontsize))

    cx = text_w + offet_x
    cy += hinter
    px, py = translation_pts(pts, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)

    cx += start_w
    px, py = rotation_pts_xy(x, y, np.pi / 6)
    px, py = translation_pts_xy(px, py, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)

    # start zoom
    text_y += hinter
    txt = 'Zoom:'
    svg.draw(draw_text(x=text_x, y=text_y, text=txt, fontsize=fontsize))

    cx = text_w + offet_x
    cy += hinter
    px, py = translation_pts(pts, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)

    cx += start_w
    px, py = zoom_pts_xy(x, y, 0.7)
    px, py = translation_pts_xy(px, py, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)

    # start shear
    text_y += hinter
    txt = 'Shear:'
    svg.draw(draw_text(x=text_x, y=text_y, text=txt, fontsize=fontsize))

    cx = text_w + offet_x
    cy += hinter
    px, py = translation_pts(pts, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)

    cx += start_w
    px, py = shear_points(pts, r=0.7)
    px, py = translation_pts_xy(px, py, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)

    # start reflection
    text_y += hinter
    txt = 'Reflection:'
    svg.draw(draw_text(x=text_x, y=text_y, text=txt, fontsize=fontsize))

    cx = text_w + offet_x
    cy += hinter
    px, py = translation_pts(pts, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)

    cx += start_w
    px, py = reflection_points(pts, reflectx=False)
    px, py = translation_pts_xy(px, py, (cx, cy))
    draw_points_svg(svg,
                    px,
                    py,
                    stroke=None,
                    color=stroke_color,
                    fillColor=fillColor,
                    close=True)