Example #1
0
def drawSmileSVGNode(svg, node, radius, offsetX=0, offsetY=0, color=None):
    x = radius + offsetX
    y = radius + offsetY
    color = color or '#FFC10E'
    svg.draw_node(node, draw_circle(x, y, radius, color=color))

    x = radius * 0.67 + offsetX
    y = radius * 0.66 + offsetY
    r = radius * 0.16
    svg.draw_node(node, draw_circle(x, y, r, color='#333333'))  # left eye

    x = 2 * radius - x + 2 * offsetX
    svg.draw_node(node, draw_circle(x, y, r, color='#333333'))  # right eye

    startPt = [0.40 * radius + offsetX, 1.05 * radius + offsetY]
    stopPt = [2 * radius - startPt[0] + 2 * offsetX, startPt[1]]
    cp1 = [0.6 * radius + offsetX,
           1.78 * radius + offsetY]  # Bézier Curves control points
    cp2 = [2 * radius - cp1[0] + 2 * offsetX,
           cp1[1]]  # Bézier Curves control points
    path = 'M {} {} C {} {}, {} {}, {} {}'.format(startPt[0], startPt[1],
                                                  cp1[0], cp1[1], cp2[0],
                                                  cp2[1], stopPt[0], stopPt[1])

    color = 'black'
    lineWidth = 0.11 * radius
    svg.draw_node(node, draw_path(path, stroke_width=lineWidth,
                                  color=color))  # mouth

    svg.draw_node(
        node, draw_circle(startPt[0], startPt[1], lineWidth / 2, color=color))
    svg.draw_node(
        node, draw_circle(stopPt[0], stopPt[1], lineWidth / 2, color=color))
Example #2
0
def drawPointsCircleFadeColor(svg, pts, r=2):
    c = rainbow_colors(N=len(pts))
    # print(c,type(c))

    for i, pt in enumerate(pts):
        x = clip_float(pt[0])
        y = clip_float(pt[1])

        color = c[i]
        svg.draw(draw_circle(x, y, radius=r, color=color))
def drawRandomCirclePath(svg):
    W, H = svg.get_size()

    styles = ['circles', 'circle points', 'circle points random']

    onlyPath = False
    times = 100
    r = 2
    offsetX = W // 2
    offsetY = H // 2
    style = styles[1]

    if style == styles[0]:
        for _ in range(times):
            r = r + random.random() * 8
            ptX, ptY = getCirclePtsSVG(svg,
                                       r=r,
                                       N=200,
                                       offsetX=offsetX,
                                       offsetY=offsetY,
                                       noise=False,
                                       onlyPath=onlyPath)
            drawOnePathcSVG(svg, ptX, ptY, onlyPath=onlyPath)

    elif style == styles[1]:
        times = 10
        for _ in range(times):
            r = r + random.random() * 18
            ptX, ptY = getCirclePtsSVG(svg,
                                       r=r,
                                       N=20,
                                       offsetX=offsetX,
                                       offsetY=offsetY,
                                       noise=False,
                                       onlyPath=onlyPath)
            ptNumber = int(5 * r)
            # ptX = np.random.choice(ptX, ptNumber)

            ptX = ptX.reshape((len(ptX), 1))
            ptY = ptY.reshape((len(ptY), 1))
            pts = np.concatenate((ptX, ptY), axis=1)
            # print(ptX.shape, pts.shape)

            ptsIndex = np.random.randint(len(pts), size=ptNumber)
            # print('ptsIndex=', ptsIndex, len(pts))
            pts = pts[ptsIndex, :]

            for i in pts:
                # print('i=', i)
                # ra = 0.5
                ra = np.random.random() * (3 - 0.2) + 0.2
                ra = clip_float(ra)
                x = clip_float(i[0])
                y = clip_float(i[1])
                svg.draw(draw_circle(x, y, radius=ra, color=random_color()))
Example #4
0
    def DrawCircleByPt(self, pt1, pt2, pt3, pt4, circle=True):
        ptCenter = np.array([(pt1[0] + pt3[0]) / 2, (pt1[1] + pt3[1]) / 2])
        r = abs(ptCenter[0] - pt1[0])

        if circle:
            rings = 4
            r = random.choice(range(1, rings)) * r / rings
            self.svg.draw(draw_circle(ptCenter[0], ptCenter[1], r))
        else:
            for i in draw_circleRings(ptCenter[0], ptCenter[1], r):
                self.svg.draw(i)
def createCircle(svg, x, y, r, color=None):
    id = 'circle_' + rand_str(4)
    color = color or random_color()
    circle = svg.draw(draw_circle(x, y, r, color=color))
    svg.set_node(circle, 'id', id)

    if 1:  # rings
        svg.set_node(circle, 'fill', 'none')
        svg.set_node(circle, 'stroke-width', "2")
        svg.set_node(circle, 'stroke', color)
    return id, circle
def draw_circle_path_anim(svg, node, path, radius, color='red', duration=None):
    circle = svg.draw_node(node, draw_circle(0, 0, radius=radius, color=color))

    animate_dict = {}

    if duration is None:
        animate_dict['dur'] = '5s'
    else:
        animate_dict['dur'] = f'{duration}s'
    animate_dict["repeatCount"] = "indefinite"
    animate_dict["path"] = path

    addNodeAnitmation(svg, circle, animate_dict, elementName='animateMotion')
Example #7
0
    def drawStep(self):
        r = self.step / 2
        for i in range(0, self.svgH, self.step):
            for j in range(0, self.svgW, self.step):
                x = i + 1 / 2 * self.step
                y = j + 1 / 2 * self.step

                roi = self.image[i:i + self.step, j:j + self.step]
                # print(i,j,self.svgH,self.svgW,i+self.step,j+self.step)
                color = color_fader(mix=np.mean(roi) / 255)
                if 0:
                    self.svg.draw(draw_circle(y, x, r, color=color))
                else:
                    self.svg.draw(
                        draw_rect(y, x, self.step, self.step, 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()))
Example #9
0
def drawPointsCircle(svg, pts=[], node=None, r=2, color='black'):
    for pt in pts:
        x = clip_float(pt[0])
        y = clip_float(pt[1])
        svg.draw_node(node, draw_circle(x, y, radius=r, color=color))
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')
Example #11
0
 def drawPointsCircle_colors(svg, pts, r, colors):
     for i, pt in enumerate(pts):
         x = clip_float(pt[0])
         y = clip_float(pt[1])
         svg.draw(draw_circle(x, y, radius=r, color=colors[i]))