示例#1
0
def drawRandomTrianglePoints(svg):
    """draw a random triangle and zoom this to seris"""
    W, H = svg.get_size()
    cx, cy = W // 2, H // 2

    r = 10
    if 1:
        pts = getRandomProper3Points(min=r, max=W - r)
    else:
        pts = random_points((3, 2), min=cx - r, max=cx + r)
        print(pts)

    # drawTrianglePoints(svg,pts[0],pts[1],pts[2])

    cx, cy, _ = getCenterPoint(pts[0], pts[1], pts[2])
    x = pts.T[0]
    y = pts.T[1]
    print('cx,cy=', cx, cy)

    # zoomPoint = (0,0)
    zoomPoint = (cx, cy)
    times = 30
    for z in np.linspace(0.1, 1.0, times):
        zx, zy = zoom_pts_xy_point(x, y, zoomPoint, z)
        drawTrianglePointsXY(svg, zx, zy)
示例#2
0
def drawAbstractLine(svg):
    W, H = svg.get_size()
    # cx, cy = W // 2, H // 2
    N = 10

    # svg.draw(draw_rect(0,0,W,H,color='#808B96'))  # background

    slope = 1.7
    # ptYaxis = getLinePointFromSlope(slope,(20,0))
    # print('ptYaxis=',ptYaxis)
    pts1 = random_points((N, ), min=0, max=W).reshape((N, 1))
    pts1 = np.append(pts1, np.zeros_like(pts1), axis=1)

    pts2 = None
    for i in pts1:
        pt = getLinePointFromSlope(slope, (i[0], i[1]))
        pt = np.array(pt).reshape(1, 2)
        # print('pt=',pt)
        # pts2 = np.append(pts2, pt, axis=1)
        pts2 = np.concatenate((pts2, pt), axis=0) if pts2 is not None else pt

    # print('pts1=',pts1)
    # print('pts2=',pts2)

    linePoints = []
    widths = []
    for pt1, pt2 in zip(pts1, pts2):
        linePoints.append((pt1[0], pt1[1], pt2[0], pt2[1]))
        widths.append(random.choice([2, 2, 4, 6, 8, 10]))
    # print(widths)
    drawlinePoints(svg, linePoints, color=None, stroke_widths=widths)
示例#3
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)
示例#4
0
def drawPointsLineGraphic5(svg):
    W, H = svg.get_size()
    # cx,cy = W//2,H//2
    N = 10

    color = 'black'
    pts = random_points((N, 2), min=2, max=W - 2)
    drawPointsCircle(svg, pts, r=1)

    graph = GraphPoints(pts)
    # graph.show()

    conMatrix = graph.getConnectionMatrix2(KNearst=3)
    print('conMatrix=', conMatrix)
    # for i,pt in enumerate(pts):
    #     #print(i,pt, conMatrix[i])
    #     ptsTriangle=[]
    #     ptsTriangle.append(pts[i])
    #     ptsTriangle.append(pts[conMatrix[i][0]])
    #     ptsTriangle.append(pts[conMatrix[i][1]])

    #     color = None
    #     drawPloygon(svg,ptsTriangle,color=color)

    linePoints = []
    for i in conMatrix:
        s, t = i[0], i[1]  # start stop point index
        if t == -1:
            continue
        linePoints.append((pts[s][0], pts[s][1], pts[t][0], pts[t][1]))

    drawlinePoints(svg, linePoints, color=color)
示例#5
0
def drawPointsLineGraphic6(svg):
    W, H = svg.get_size()
    # cx,cy = W//2,H//2
    N = 50

    color = 'black'
    pts = random_points((N, 2), min=2, max=W - 2)
    drawPointsCircle(svg, pts, r=1)

    graph = GraphPoints(pts)
    # graph.show()

    # conMatrix = graph.getAllConnectionMatrix()
    conMatrix = graph.getConnectionMatrix2(KNearst=4)
    print('conMatrix=', conMatrix)
    linePoints = []
    for i in conMatrix:
        s, t = i[0], i[1]  # start stop point index
        if t == -1:
            continue

        conect = (pts[s][0], pts[s][1], pts[t][0], pts[t][1])
        if not IsIntersectionWithAlreayLines(conect, linePoints):
            linePoints.append(conect)

    drawlinePoints(svg, linePoints, color=color)
示例#6
0
def drawPointsLineGraphic(svg):
    W, H = svg.get_size()
    # cx,cy = W//2,H//2
    N = 50

    color = 'black'
    pts = random_points((N, 2), min=2, max=W - 2)
    drawPointsCircle(svg, pts, r=1, color='red')

    graph = GraphPoints(pts)
    # graph.show()

    # conMatrix = graph.getConnectionMatrix(K=3,KNearst=4)  # style1
    conMatrix = graph.getConnectionMatrix2(KNearst=6)  # style2
    # print('conMatrix=',conMatrix)
    linePoints = []
    for i in conMatrix:
        s, t = i[0], i[1]  # start stop point index
        if t == -1:
            continue

        conect = (pts[s][0], pts[s][1], pts[t][0], pts[t][1])
        linePoints.append(conect)

    drawlinePoints(svg, linePoints, color=color)
def animCircleInflation5(svg):
    H, W = svg.get_size()
    cx, cy = W // 2, H // 2
    N = 20  # total points
    r0 = 5
    r1 = 60

    offset = 10  # margin to border
    pts = random_points((N, 2), min=offset, max=W - offset)

    color = None  # "black"#
    rList = np.linspace(1, r1 / 2, 20)
    for i in range(N):
        begin = str(random.randint(1, 4)) + 's'  # str(i)+'s' #'0s'
        dur = random.randint(3, 6)
        r = random.choice(rList)
        id, circle = circleInflation(svg,
                                     pts[i][0],
                                     pts[i][1],
                                     r=r,
                                     color=color,
                                     fromR=r0,
                                     toR=r1,
                                     durS=dur,
                                     begin=begin)

        animateDict = {}
        animateDict["{{{}}}".format(svg.xlink) + 'href'] = f'#{id}'
        animateDict['id'] = 'ani_' + id + '_' + rand_str(2)
        animateDict['attributeName'] = 'stroke-width'
        animateDict['values'] = '0;2;4;2;1;0'
        animateDict['dur'] = '5s'  # str(random.randint(0,durS)) #'5'
        animateDict['begin'] = begin  # '0s'
        animateDict["repeatCount"] = "indefinite"  # "5"
        addNodeAnitmation(svg, circle, animateDict)
示例#8
0
def drawPointsLineGraphic3(svg):
    W, H = svg.get_size()
    # cx,cy = W//2,H//2
    N = 100
    color1 = 'green'
    # color2 = 'yellow'

    pts = random_points((N, 2), min=2, max=W - 2)

    pts1 = pts[: N // 2]
    pts2 = pts[N // 2:]
    drawPointsCircle(svg, pts1, r=1, color=color1)
    drawPointsCircle(svg, pts2, r=1, color=color1)

    linePoints = [(pt1[0], pt1[1], pt2[0], pt2[1]) for pt1, pt2 in zip(pts1, pts2)]

    drawlinePoints(svg, linePoints, color=color1, stroke_width=0.2)
    drawInterPointLines(svg, linePoints, r=1, color=color1)
def animCircleInflation2(svg):
    H, W = svg.get_size()

    N = 30  # total points
    offset = 10  # margin to border
    pts = random_points((N, 2), min=offset, max=W - offset)
    # print(pts)

    color = None  # "black" #None
    for pt in pts:
        r = random.randint(1, 6)
        circleInflation(svg,
                        pt[0],
                        pt[1],
                        r=r,
                        color=color,
                        fromR=r,
                        toR=r * 5,
                        durS=3)
示例#10
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)
示例#11
0
def drawPointsLineGraphic9(svg):
    W, H = svg.get_size()
    # cx, cy = W // 2, H // 2
    N = 50

    pts = random_points((N, 2), min=2, max=W - 2)
    drawPointsCircle(svg, pts, r=2, color='black')
    drawPointsCircle(svg, pts, r=1.5, color='red')

    # print(pts, len(pts), type(pts))
    ptsNum = list(itertools.combinations(range(len(pts)), 2))
    # print(ptsNum)
    linePts = np.array([]).reshape(0, 2)
    for i, j in ptsNum:
        # print(i,j, pts[i], pts[j])
        # linePts.append([pts[i], pts[j]])
        linePts = np.vstack((linePts, pts[i]))
        linePts = np.vstack((linePts, pts[j]))

    # print('linePts=', linePts)
    drawlinePointsContinus(svg, linePts, stroke_width=0.2, color='black')
示例#12
0
def drawPointsLineGraphic2(svg):
    W, H = svg.get_size()
    # cx,cy = W//2,H//2
    N = 200

    color1 = 'green'
    color2 = '#C70039'

    # svg.draw(draw_rect(0,0,W,H,color='#808B96')) #background
    pts = random_points((N, 2), min=2, max=W - 2)

    pts1 = pts[:N // 2]
    pts2 = pts[N // 2:]
    drawPointsCircle(svg, pts1, color=color1)
    drawPointsCircle(svg, pts2, color=color2)

    linePoints = [(0, 0, i[0], i[1]) for i in pts1]
    drawlinePoints(svg, linePoints, color=color1, stroke_width=0.2)

    linePoints = [(i[0], i[1], W, H) for i in pts2]
    drawlinePoints(svg, linePoints, color=color2, stroke_width=0.2)
示例#13
0
def test_geo_transformation():
    x = np.array([1, 2, 5])
    y = np.array([3, 4, 6])
    print(x.shape)
    # new_x, new_y = translation_pts_xy(x, y, (1, 2))
    # translation_pts_xy(x,y,(-1.5,-3.5))

    N = 10
    pts = random_points((N, 2), min=1, max=10)
    print(pts, pts.shape)

    x, y = split_points(pts)

    # print('x, x.shape=', x, x.shape)
    # new_x, new_y = identity_trans(x, y)
    # new_x, new_y = translation_pts_xy(x, y, (1, -2))
    # new_x, new_y = translation_pts(pts, (1, -2))
    # new_x, new_y = rotation_pts_xy(x, y, 0)
    # new_x, new_y = zoom_pts_xy(x, y, 1.1)
    # new_x, new_y = shear_points(pts, 1)
    new_x, new_y = reflection_points(pts, 1)
    print('new_x =', new_x)
    print('new_y =', new_y)