def drawColor(self): r = 1 for i in range(0, self.svgH, self.step): for j in range(0, self.svgW, self.step): color = convert_rgb(self.image[i, j, :]) self.svg.draw( draw_rect(j, i, r, r, stroke_width=0, color=color))
def DrawRectangleByPt(self, startPt, stopPt): if startPt[0] > stopPt[0]: # switch startPt = startPt + stopPt stopPt = startPt - stopPt startPt = startPt - stopPt self.svg.draw( draw_rect(startPt[0], startPt[1], stopPt[0] - startPt[0], stopPt[1] - startPt[1]))
def drawLineGrapic9(svg, anim=True): W, H = svg.get_size() cx, cy = W // 2, H // 2 N = 5000 # svg.set_background(random_color()) svg.set_background('black') rt_w = 10 rt_h = 10 pts = random_coordinates(0, W - rt_w, 0, H - rt_h, N=N) # remove some points may be lead intersected rect pts = remove_covered(pts, rt_w, rt_h) for i, pt in enumerate(pts): rect = svg.draw( draw_rect(pt[0], pt[1], width=rt_w, height=rt_h, color=random_color_hsv())) if anim: if 0: # style1 : move rect animateDict = {} animateDict['attributeName'] = 'x' # animateDict['from'] = f'{pt[0] - 1}' # animateDict['to'] = f'{pt[0] + 1}' animateDict["values"] = get_anim_values(pt[0] - 1, pt[0] + 1) animateDict['dur'] = str(random.randint(1, 3)) + 's' # animateDict['fill'] = 'freeze' animateDict["repeatCount"] = "indefinite" animateDict["begin"] = str(random.randint(0, 10)) + 's' # animateDict["additive"] = "replace" addNodeAnitmation(svg, rect, animateDict) animateDict['attributeName'] = 'y' # animateDict['from'] = f'{pt[1] - 1}' # animateDict['to'] = f'{pt[1] + 1}' animateDict["values"] = get_anim_values(pt[1] - 1, pt[1] + 1) addNodeAnitmation(svg, rect, animateDict) else: # style2: rotation rect_cx = int(pt[0] + rt_w / 2) rect_cy = int(pt[1] + rt_h / 2) animateDict = {} animateDict['attributeName'] = 'transform' animateDict['attributeType'] = 'xml' animateDict['type'] = 'rotate' animateDict['from'] = f'0 {rect_cx} {rect_cy}' animateDict['to'] = f'360 {rect_cx} {rect_cy}' # animateDict["begin"] = str(random.randint(0, 10)) + 's' animateDict['dur'] = str(random.randint(4, 6)) + 's' # '8s' animateDict["repeatCount"] = "indefinite" # "5" addNodeAnitmation(svg, rect, animateDict, elementName='animateTransform')
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()))
def setborder_2(): """ Method 2: add a background rect """ self._bk_rect = self.draw( draw_rect(0, 0, self._width, self._height, stroke_width=1, color='None', stroke_color='black')) self._bk_rect.set("id", "border") self._bk_rect.set("opacity", "0.8")
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 drawPointsRect_colors(svg, pts, r, colors): for i, pt in enumerate(pts): x = clip_float(pt[0]) y = clip_float(pt[1]) svg.draw(draw_rect(x, y, r, r, color=colors[i]))
def _draw_(self): self._prepare_svg() W, H = self.svg.get_size() # ----------------header------------------- # dictLink = {} dictLink["{{{}}}".format(self.svg._xlink) + 'href'] = self.dataDict['wiki'] aLink = self.svg.draw(draw_any(tag='a')) self.svg.set_node_dict(aLink, dictLink) itemW = 110 itemH = 150 styleImg = {} styleImg['width'] = str(itemW) styleImg['height'] = str(itemH) styleImg['x'] = str(0) styleImg['y'] = str(0) styleImg['href'] = self.dataDict['photo'] if 0: # self.svg.draw(draw_any('image', **styleImg)) self.svg.add_child(aLink, self.svg.new_node(draw_any('image', **styleImg))) else: self.draw_portrait(aLink, styleImg['href'], itemW, itemH, (0, 0)) y0 = 30 x0 = itemW + 5 node = self.svg.draw(draw_any(tag='text', x=x0, y=y0, text=self.dataDict['name'])) self.svg.set_node(node, 'class', 'big') node = self.svg.draw(draw_any(tag='text', x=x0, y=y0 + 30, text=self.dataDict['name_cn'])) self.svg.set_node(node, 'class', 'big') date = '(' + self.dataDict['date_birth'] + ' - ' + self.dataDict['date_death'] + ')' node = self.svg.draw(draw_any(tag='text', x=x0, y=y0 + 60, text=date)) self.svg.set_node(node, 'class', 'small') node = self.svg.draw(draw_any(tag='text', x=x0, y=y0 + 90, text=self.dataDict['profile'])) self.svg.set_node(node, 'class', 'small') # ----------------split line--------------- # self.svg.draw(draw_rect(x=0, y=itemH, width=W, height=0.01 * H, stroke_width=0.2, color='#FCC64A')) # ----------------body--------------------- # y0 = itemH + 10 nodeTextBody = self.svg.draw(draw_any(tag='text')) self.svg.set_node(nodeTextBody, 'class', 'bodyText') dictStyle = {'dy': "0.2em", 'x': "10"} for i, txts in enumerate(self.dataDict['quotes'], start=1): # dictStyle['y'] = str(y0) for k, lineText in enumerate(txts, start=1): if k == 1: s = str(i) + '. ' + lineText else: s = lineText y0 += 30 dictStyle['y'] = str(y0) line = self.svg.new_node(draw_any(tag='tspan', text=s, **dictStyle)) self.svg.add_child(nodeTextBody, line) y0 += 20