Python svgwrite.Drawing() Examples
The following are 30
code examples of svgwrite.Drawing().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
svgwrite
, or try the search function
.
Example #1
Source File: heatmap_drawer.py From GpxTrackPoster with MIT License | 7 votes |
def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY): """Draw the heatmap based on tracks.""" bbox = self._determine_bbox() for tr in self.poster.tracks: color = self.color(self.poster.length_range, tr.length, tr.special) for line in utils.project(bbox, size, offset, tr.polylines): for opacity, width in [(0.1, 5.0), (0.2, 2.0), (1.0, 0.3)]: dr.add( dr.polyline( points=line, stroke=color, stroke_opacity=opacity, fill="none", stroke_width=width, stroke_linejoin="round", stroke_linecap="round", ) )
Example #2
Source File: wad.py From doom-net-pytorch with MIT License | 6 votes |
def save_svg(self): """ Scale the drawing to fit inside a 1024x1024 canvas (iPhones don't like really large SVGs even if they have the same detail) """ import svgwrite view_box_size = self.normalize(self.upper_right, 10) if view_box_size[0] > view_box_size[1]: canvas_size = (1024, int(1024 * (float(view_box_size[1]) / view_box_size[0]))) else: canvas_size = (int(1024 * (float(view_box_size[0]) / view_box_size[1])), 1024) dwg = svgwrite.Drawing(self.name + '.svg', profile='tiny', size=canvas_size, viewBox=('0 0 %d %d' % view_box_size)) for line in self.lines: a = self.normalize(self.vertices[line.a]) b = self.normalize(self.vertices[line.b]) if line.is_one_sided(): dwg.add(dwg.line(a, b, stroke='#333', stroke_width=10)) else: dwg.add(dwg.line(a, b, stroke='#999', stroke_width=3)) dwg.save()
Example #3
Source File: basic.py From brand with Creative Commons Zero v1.0 Universal | 6 votes |
def generate_works(): dwg = svgwrite.Drawing('generate/basic.svg', size=(u'1200', u'600')) shapes = dwg.add(dwg.g(id='shapes', fill='none')) for x in range(1, 150): shapes.add(dwg.line((250, 60 + x), (380, 0 + x), stroke='#59B840', stroke_width=1)) for x in range(1, 150): shapes.add(dwg.line((380, 0 + x), (420, 60 + x), stroke='#1A7906', stroke_width=1)) # color bg: #1A7906 shapes.add(dwg.rect((420, 60), (950, 250), fill='#59B840')) shapes.add(dwg.text('标题', insert=(450, 240), fill='#fff', font_size=160, font_family='Helvetica')) shapes.add(dwg.line((440, 280), (1180, 280), stroke='#fff', stroke_width=4)) dwg.save()
Example #4
Source File: fretboard.py From python-fretboard with MIT License | 6 votes |
def draw(self): self.drawing = svgwrite.Drawing(size=( self.style.drawing.width, self.style.drawing.height )) if self.style.drawing.background_color is not None: self.drawing.add( self.drawing.rect( insert=(0, 0), size=( self.style.drawing.width, self.style.drawing.height ), fill=self.style.drawing.background_color ) ) self.calculate_layout() self.draw_frets() self.draw_inlays() self.draw_fret_label() self.draw_strings() self.draw_nut() self.draw_markers()
Example #5
Source File: calendar_drawer.py From GpxTrackPoster with MIT License | 6 votes |
def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY): """Iterate through the Poster's years, creating a calendar for each.""" if self.poster.tracks is None: raise PosterError("No tracks to draw.") years = self.poster.years.count() _, counts = utils.compute_grid(years, size) if counts is None: raise PosterError("Unable to compute grid.") count_x, count_y = counts[0], counts[1] x, y = 0, 0 cell_size = size * XY(1 / count_x, 1 / count_y) margin = XY(4, 8) if count_x <= 1: margin.x = 0 if count_y <= 1: margin.y = 0 sub_size = cell_size - 2 * margin for year in range(self.poster.years.from_year, self.poster.years.to_year + 1): self._draw(dr, sub_size, offset + margin + cell_size * XY(x, y), year) x += 1 if x >= count_x: x = 0 y += 1
Example #6
Source File: detect.py From examples-camera with Apache License 2.0 | 6 votes |
def generate_svg(src_size, inference_size, inference_box, objs, labels, text_lines): dwg = svgwrite.Drawing('', size=src_size) src_w, src_h = src_size inf_w, inf_h = inference_size box_x, box_y, box_w, box_h = inference_box scale_x, scale_y = src_w / box_w, src_h / box_h for y, line in enumerate(text_lines, start=1): shadow_text(dwg, 10, y*20, line) for obj in objs: x0, y0, x1, y1 = list(obj.bbox) # Relative coordinates. x, y, w, h = x0, y0, x1 - x0, y1 - y0 # Absolute coordinates, input tensor space. x, y, w, h = int(x * inf_w), int(y * inf_h), int(w * inf_w), int(h * inf_h) # Subtract boxing offset. x, y = x - box_x, y - box_y # Scale to source coordinate space. x, y, w, h = x * scale_x, y * scale_y, w * scale_x, h * scale_y percent = int(100 * obj.score) label = '{}% {}'.format(percent, labels.get(obj.id, obj.id)) shadow_text(dwg, x, y - 5, label) dwg.add(dwg.rect(insert=(x,y), size=(w, h), fill='none', stroke='red', stroke_width='2')) return dwg.tostring()
Example #7
Source File: svg.py From giftolottie with MIT License | 6 votes |
def save(shapes, name): svg = svgwrite.Drawing(filename = name, size = ("512px", "512px")) for shape in shapes: if shape['type'] == 'rect': svg.add(svg.rect( insert = (str(shape['coords'][0][0]) + "px", str(shape['coords'][0][1]) + "px"), size = ( str(shape['coords'][1][0] - shape['coords'][0][0]) + "px", str(shape['coords'][1][1] - shape['coords'][0][1]) + "px", ), #stroke_width = "0", fill = "rgb(" + ",".join(map(str, shape['color'])) + ")" )) svg.save()
Example #8
Source File: create.py From databench with MIT License | 6 votes |
def main(): svg_favicon = svgwrite.Drawing(filename="favicon.svg", size=("128px", "128px")) svg_document = svgwrite.Drawing(filename="logo.svg", size=("128px", "128px")) for y, r in enumerate(DATA): for x, v in enumerate(r): simple(svg_favicon, x, y, v) smaller(svg_document, x, y, v) print(svg_document.tostring()) svg_favicon.save() svg_document.save() # create pngs os.system('svg2png logo.svg --width=100 --height=100') os.system('svg2png logo.svg --width=600 --height=600') favicon_sizes = [16, 32, 48, 128, 256] for s in favicon_sizes: os.system('svg2png favicon.svg --width='+str(s)+' --height='+str(s)) png_favicon_names = ['favicon-w'+str(s)+'.png' for s in favicon_sizes] os.system('convert ' + (' '.join(png_favicon_names)) + ' -colors 256 favicon.ico')
Example #9
Source File: circular_drawer.py From GpxTrackPoster with MIT License | 6 votes |
def _draw_rings(self, dr: svgwrite.Drawing, center: XY, radius_range: ValueRange): length_range = self.poster.length_range_by_date ring_distance = self._determine_ring_distance() if ring_distance is None: return distance = ring_distance while distance < length_range.upper(): radius = ( radius_range.lower() + radius_range.diameter() * distance / length_range.upper() ) dr.add( dr.circle( center=center.tuple(), r=radius, stroke=self._ring_color, stroke_opacity="0.2", fill="none", stroke_width=0.3, ) ) distance += ring_distance
Example #10
Source File: output.py From Pixel-Art with GNU General Public License v3.0 | 5 votes |
def make_drawing(self, filename): return Drawing(filename)
Example #11
Source File: drawing.py From tskit with MIT License | 5 votes |
def setup_drawing(self): "Return an svgwrite.Drawing object for further use" dwg = svgwrite.Drawing( size=self.image_size, debug=True, **self.root_svg_attributes ) dwg.defs.add(dwg.style(self.standard_style)) tree_class = f"tree t{self.tree.index}" self.root_group = dwg.add(dwg.g(class_=tree_class)) return dwg
Example #12
Source File: __init__.py From psd2svg with MIT License | 5 votes |
def convert(self, layer, output=None): """Convert the given PSD to SVG.""" self.reset() self._set_input(layer) self._set_output(output) layer = self._layer bbox = layer.viewbox if hasattr(layer, 'viewbox') else layer.bbox if bbox == (0, 0, 0, 0): bbox = self._psd.viewbox self._dwg = svgwrite.Drawing( size=(bbox[2] - bbox[0], bbox[3] - bbox[1]), viewBox='%d %d %d %d' % ( bbox[0], bbox[1], bbox[2] - bbox[0], bbox[3] - bbox[1] ), ) if layer.is_group(): self.create_group(layer, self._dwg) else: self._dwg.add(self.convert_layer(layer)) # Layerless PSDImage. if ( isinstance(layer, PSDImage) and len(layer) == 0 and layer.has_preview() ): self._dwg.add(self._dwg.image( self._get_image_href(layer.topil()), insert=(0, 0), size=(layer.width, layer.height), debug=False )) return self._save_svg()
Example #13
Source File: gstreamer.py From project-teachable with Apache License 2.0 | 5 votes |
def on_new_sample(sink, overlay, screen_size, appsink_size, user_function): sample = sink.emit('pull-sample') buf = sample.get_buffer() result, mapinfo = buf.map(Gst.MapFlags.READ) if result: img = Image.frombytes('RGB', (appsink_size[0], appsink_size[1]), mapinfo.data, 'raw') svg_canvas = svgwrite.Drawing('', size=(screen_size[0], screen_size[1])) user_function(img, svg_canvas) overlay.set_property('data', svg_canvas.tostring()) buf.unmap(mapinfo) return Gst.FlowReturn.OK
Example #14
Source File: svgEXT.py From touchdesigner-sop-to-svg with MIT License | 5 votes |
def SavePolyline(self, path, pline): ''' This is a sample method. This sample method is intended to help illustrate what method docstrings should look like. Notes --------------- 'self' does not need to be included in the Args section. Args --------------- name (str): A string name, with spaces as underscores age (int): Age as full year measurements height (float): Height in meters to 2 significant digits, ex: 1.45 Examples --------------- Returns --------------- formatted_profile (str) : A formatted string populated with the with the supplied information ''' Canvassize = self.Canvas_size() prims = pline.prims dwg = svgwrite.Drawing(path, profile='tiny', size=Canvassize) for item in prims: if self.UseCamera: newPoints = [self.WorldToCam(vert.point.P) for vert in item ] else: newPoints = [(vert.point.x,vert.point.y) for vert in item ] newPoly = dwg.polyline(points=newPoints, stroke='black', stroke_width=1, fill='none') dwg.add(newPoly) dwg.save() return
Example #15
Source File: svgEXT.py From touchdesigner-sop-to-svg with MIT License | 5 votes |
def SavePolygon(self, path, pgon): ''' This is a sample method. This sample method is intended to help illustrate what method docstrings should look like. Notes --------------- 'self' does not need to be included in the Args section. Args --------------- name (str): A string name, with spaces as underscores age (int): Age as full year measurements height (float): Height in meters to 2 significant digits, ex: 1.45 Examples --------------- Returns --------------- formatted_profile (str) : A formatted string populated with the with the supplied information ''' Canvassize = self.Canvas_size() prims = pgon.prims dwg = svgwrite.Drawing(path, profile='tiny', size=Canvassize) for item in prims: if self.UseCamera: newPoints = [self.WorldToCam(vert.point.P) for vert in item ] else: newPoints = [(vert.point.x,vert.point.y) for vert in item ] newPoly = dwg.polygon(points=newPoints, stroke='black', stroke_width=1, fill='none') dwg.add(newPoly) dwg.save()
Example #16
Source File: registration.py From silhouette with MIT License | 5 votes |
def generate(self, svgfn="registration.svg"): svg = svgwrite.Drawing(svgfn) svg.add(self.cube_mark()) svg.add(self.top_angle_mark()) svg.add(self.bottom_angle_mark()) svg.save()
Example #17
Source File: visualisation.py From tsinfer with GNU General Public License v3.0 | 5 votes |
def draw(self, ancestor_id, filename_pattern): start = self.ancestor_data.ancestors_start[ancestor_id] end = self.ancestor_data.ancestors_end[ancestor_id] focal_sites = self.ancestor_data.ancestors_focal_sites[ancestor_id] a = np.zeros(self.sample_data.num_sites, dtype=int) a[:] = -1 a[start:end] = self.ancestor_data.ancestors_haplotype[ancestor_id] print(start, end, focal_sites, a) dwg = svgwrite.Drawing(size=(self.width, self.height), debug=True) self.draw_matrix(dwg, focal_sites, a) with open(filename_pattern.format(0), "w") as f: f.write(dwg.tostring())
Example #18
Source File: classify.py From examples-camera with Apache License 2.0 | 5 votes |
def generate_svg(size, text_lines): dwg = svgwrite.Drawing('', size=size) for y, line in enumerate(text_lines, start=1): dwg.add(dwg.text(line, insert=(11, y*20+1), fill='black', font_size='20')) dwg.add(dwg.text(line, insert=(10, y*20), fill='white', font_size='20')) return dwg.tostring()
Example #19
Source File: svg3d.py From svg3d with MIT License | 5 votes |
def render(self, filename, size=(512, 512), viewBox="-0.5 -0.5 1.0 1.0", **extra): drawing = svgwrite.Drawing(filename, size, viewBox=viewBox, **extra) self.render_to_drawing(drawing) drawing.save()
Example #20
Source File: slogan.py From brand with Creative Commons Zero v1.0 Universal | 5 votes |
def generate_slogan(): width = 600 height = 50 dwg = svgwrite.Drawing('slogan.svg', profile='full', size=(u'540', u'50')) mask = dwg.mask((0, 0), (540, height), id='a') mask.add(dwg.rect((0, 0), (540, height), fill='#eee', rx=5)) dwg.add(mask) g = dwg.add(dwg.g(id='g', fill='none', mask='url(#a)')) g.add(dwg.rect((0, 0), (width / 3, height), fill='#03a9f4')) g.add(dwg.rect((width / 3, 0), (width / 3, height), fill='#e91e63')) g.add(dwg.rect((width * 2 / 3, 0), (width * 2 / 3, height), fill='#ecf0f1')) slogan_link = Hyperlink('http://www.xuntayizhan.com/person/ji-ke-ai-qing-zhi-er-shi-dai-wo-dai-ma-bian-cheng-qu-ni-wei-qi-ke-hao-wan/', target='_blank') slogan_link.add(dwg.text('待我代码编成', insert=(10, 35), fill='#fff', font_size=30, font_family='STFangSong')) slogan_link.add(dwg.text('娶你为妻可好', insert=(210, 35), fill='#fff', font_size=30, font_family='STFangSong')) dwg.add(slogan_link) link = Hyperlink('http://www.hug8217.com/', target='_blank') link.add(dwg.text('@花仲马', insert=(410, 35), fill='#34495e', font_size=30, font_family='STFangSong')) dwg.add(link) dwg.save()
Example #21
Source File: generate.py From brand with Creative Commons Zero v1.0 Universal | 5 votes |
def generate_works(): dwg = svgwrite.Drawing('shields/works.svg', size=(u'950', u'150')) width = 950 height = 150 a_mask = dwg.mask((0, 0), (width, height), id='a') a_mask.add(dwg.rect((0, 0), (width, height), fill='#eee', rx=15)) dwg.add(a_mask) g = dwg.add(dwg.g(id='g', fill='none', mask='url(#a)')) g.add(dwg.rect((phodal_width, 0), (width - phodal_width, height), fill='#2c3e50')) shapes = dwg.add(dwg.g(id='shapes', fill='none')) g.add(dwg.rect((phodal_width, 0), (426, 150), fill='#2c3e50')) for x in range(0, 300, 10): text = get_some_random10(100) g.add( dwg.text(text, insert=(phodal_width + 1, x), fill='#27ae60', font_size=12, font_family='Inconsolata for Powerline', opacity=0.3, transform="rotate(15 1000, 0)")) g.add(dwg.rect((0, 0), (phodal_width, height), fill='#5E6772')) slogan_link = Hyperlink('https://www.phodal.com/', target='_blank') shapes.add(dwg.text('phodal', insert=(84, basic_text_y + 1), fill='#000', fill_opacity=0.3, font_size=120, font_family='Helvetica')) slogan_link.add( dwg.text('phodal', insert=(83, basic_text_y), fill='#FFFFFF', font_size=120, font_family='Helvetica')) dwg.add(slogan_link) shapes.add(dwg.text('works', insert=(secondary_text_x + 1, basic_text_y + 1), fill='#FFFFFF', font_size=120, font_family='Helvetica')) shapes.add(dwg.text('works', insert=(secondary_text_x, basic_text_y), fill='#FFFFFF', font_size=120, font_family='Helvetica')) dwg.save()
Example #22
Source File: generate_small.py From brand with Creative Commons Zero v1.0 Universal | 5 votes |
def generate_works(): width = 316 height = 50 dwg = svgwrite.Drawing('shields/works-small.svg', size=(u'316', u'50')) rect_with_radius_mask = dwg.mask((0, 0), (width, height), id='a') rect_with_radius_mask.add(dwg.rect((0, 0), (width, height), fill='#eee', rx=3)) dwg.add(rect_with_radius_mask) g = dwg.add(dwg.g(id='g', fill='none', mask='url(#a)')) g.add(dwg.rect((phodal_width, 0), (width - phodal_width, height), fill='#2c3e50')) shapes = dwg.add(dwg.g(id='shapes', fill='none')) for x in range(0, 100, 5): text = get_some_random10(100) g.add( dwg.text(text, insert=(phodal_width + 1, x), fill='#27ae60', font_size=4, font_family='Inconsolata for Powerline', opacity=0.3, transform="rotate(15 300, 0)")) g.add(dwg.rect((0, 0), (phodal_width, height), fill='#5E6772')) slogan_link = Hyperlink('https://www.phodal.com/', target='_blank') shapes.add(dwg.text('phodal', insert=(28, basic_text_y + 1), fill='#000', fill_opacity=0.3, font_size=40, font_family='Helvetica')) slogan_link.add( dwg.text('phodal', insert=(27, basic_text_y), fill='#FFFFFF', font_size=40, font_family='Helvetica')) dwg.add(slogan_link) shapes.add( dwg.text('works', insert=(secondary_text_x + 1, basic_text_y + 1), fill='#000', fill_opacity=0.3, font_size=40, font_family='Helvetica')) shapes.add(dwg.text('works', insert=(secondary_text_x, basic_text_y), fill='#FFFFFF', font_size=40, font_family='Helvetica')) dwg.save()
Example #23
Source File: generate_small.py From brand with Creative Commons Zero v1.0 Universal | 5 votes |
def generate_design(): # for D Rect red_point = 272 design_width = 162 width = 338 height = 50 dwg = svgwrite.Drawing('shields/design-small.svg', size=(u'338', u'50')) rect_with_radius_mask = dwg.mask((0, 0), (width, height), id='a') rect_with_radius_mask.add(dwg.rect((0, 0), (width, height), fill='#eee', rx=3)) dwg.add(rect_with_radius_mask) g = dwg.add(dwg.g(id='g', fill='none', mask='url(#a)')) shapes = dwg.add(dwg.g(id='shapes', fill='none')) g.add(dwg.rect((0, 0), (phodal_width, 50), fill='#5E6772')) shapes.add(dwg.rect((phodal_width, 25.6), (design_width, 30), fill='#2196f3')) shapes.add(dwg.text('design', insert=(secondary_text_x + 5, 36), fill='#000', stroke_width=4, font_size=40, font_family='Helvetica')) shapes.add(dwg.rect((phodal_width, 0), (design_width, 26), fill='#03a9f4')) shapes.add(dwg.rect((phodal_width, 25.6), (design_width, 0.6), fill='#000')) shapes.add(dwg.text('design', insert=(secondary_text_x + 4, basic_text_y), fill='#FFFFFF', font_size=40, font_family='Helvetica')) def draw_red_point(): shapes.add(dwg.ellipse((red_point, 8), (3, 3), fill='#000')) shapes.add(dwg.ellipse((red_point + 1, 8), (3, 3), fill='#f44336')) draw_red_point() slogan_link = Hyperlink('https://www.phodal.com/', target='_blank') shapes.add(dwg.text('phodal', insert=(28, basic_text_y + 1), fill='#000', fill_opacity=0.3, font_size=40, font_family='Helvetica')) slogan_link.add( dwg.text('phodal', insert=(27, basic_text_y), fill='#FFFFFF', font_size=40, font_family='Helvetica')) dwg.add(slogan_link) dwg.save()
Example #24
Source File: generate_small.py From brand with Creative Commons Zero v1.0 Universal | 5 votes |
def generate_book(): dwg = svgwrite.Drawing('shields/book-small.svg', size=(u'323', u'50')) height = 50 width = 308 rect_with_radius_mask = dwg.mask((0, 0), (width, height), id='a') rect_with_radius_mask.add(dwg.rect((0, 0), (width, height), fill='#eee', rx=3)) dwg.add(rect_with_radius_mask) g = dwg.add(dwg.g(id='g', fill='none', mask='url(#a)')) g.add(dwg.rect((0, 0), (phodal_width, height), fill='#5E6772')) g.add(dwg.rect((phodal_width, 0), (width - phodal_width, height), fill='#2ECC71')) shapes = dwg.add(dwg.g(id='shapes', fill='none')) slogan_link = Hyperlink('https://www.phodal.com/', target='_blank') shapes.add(dwg.text('phodal', insert=(28, basic_text_y + 1), fill='#000', fill_opacity=0.3, font_size=40, font_family='Helvetica')) slogan_link.add( dwg.text('phodal', insert=(27, basic_text_y), fill='#FFFFFF', font_size=40, font_family='Helvetica')) dwg.add(slogan_link) def draw_for_bg_plus(): for y in range(0, 50, 5): shapes.add(dwg.line((180, y), (304, y), stroke='#EEEEEE', stroke_width='0.2', stroke_opacity=0.5)) draw_for_bg_plus() shapes.add(dwg.text('book', insert=(secondary_text_x, basic_text_y), fill='#FFFFFF', font_size=40, font_family='Helvetica')) dwg.save()
Example #25
Source File: title.py From brand with Creative Commons Zero v1.0 Universal | 5 votes |
def generate_article_title(color_name, bg_color, font_color): bg_color = '#' + bg_color font_color = '#' + font_color dwg = svgwrite.Drawing('generate/titles/' + color_name + '.svg', size=(u'950', u'300')) shapes = dwg.add(dwg.g(id='shapes', fill='none')) shapes.add(dwg.rect((0, 0), (950, 300), fill=bg_color)) shapes.add(dwg.text('PHODAL', insert=(475, 50), fill=font_color, font_size=22, style="text-anchor: middle; dominant-baseline: hanging;", font_family='Helvetica')) shapes.add(dwg.rect((220, 54), (200, 10), fill=font_color)) shapes.add(dwg.rect((530, 54), (200, 10), fill=font_color)) shapes.add(dwg.text('这是一个标题', insert=(475, 100), fill=font_color, font_size=120, style="text-anchor: middle; dominant-baseline: hanging;", font_family='Helvetica')) shapes.add(dwg.text('CREATE & SHARE', insert=(475, 220), fill=font_color, font_size=22, style="text-anchor: middle; dominant-baseline: hanging;", font_family='Helvetica')) shapes.add(dwg.rect((50, 225), (320, 5), fill=font_color)) shapes.add(dwg.rect((580, 225), (320, 5), fill=font_color)) dwg.save()
Example #26
Source File: utils.py From incremental-sequence-learning with MIT License | 5 votes |
def draw_strokes_custom_color( data, factor = 10, svg_filename = 'test.svg', color_data = None, stroke_width = 1 ): min_x, max_x, min_y, max_y = get_bounds( data, factor ) dims = ( 50 + max_x - min_x, 50 + max_y - min_y ) dwg = svgwrite.Drawing( svg_filename, size = dims ) dwg.add( dwg.rect( insert = ( 0, 0 ), size = dims, fill = 'white' ) ) lift_pen = 1 abs_x = 25 - min_x abs_y = 25 - min_y for i in range( len( data ) ): x = float( data[ i, 0 ] )/factor y = float( data[ i, 1 ] )/factor prev_x = abs_x prev_y = abs_y abs_x += x abs_y += y if ( lift_pen == 1 ): p = "M "+str( abs_x )+", "+str( abs_y )+" " else: p = "M +"+str( prev_x )+", "+str( prev_y )+" L "+str( abs_x )+", "+str( abs_y )+" " lift_pen = data[ i, 2 ] the_color = "black" if ( color_data is not None ): the_color = "rgb( "+str( int( color_data[ i, 0 ] ) )+", "+str( int( color_data[ i, 1 ] ) )+", "+str( int( color_data[ i, 2 ] ) )+" )" dwg.add( dwg.path( p ).stroke( the_color, stroke_width ).fill( the_color ) ) dwg.save( ) display( SVG( dwg.tostring( ) ) )
Example #27
Source File: utils.py From incremental-sequence-learning with MIT License | 5 votes |
def draw_strokes( data, factor = 10, svg_filename = 'sample.svg' ): min_x, max_x, min_y, max_y = get_bounds( data, factor ) dims = ( 50 + max_x - min_x, 50 + max_y - min_y ) dwg = svgwrite.Drawing( svg_filename, size = dims ) dwg.add( dwg.rect( insert = ( 0, 0 ), size = dims, fill = 'white' ) ) lift_pen = 1 abs_x = 25 - min_x abs_y = 25 - min_y p = "M%s, %s " % ( abs_x, abs_y ) command = "m" for i in range( len( data ) ): if ( lift_pen == 1 ): command = "m" elif ( command != "l" ): command = "l" else: command = "" x = float( data[ i, 0 ] )/factor y = float( data[ i, 1 ] )/factor lift_pen = data[ i, 2 ] p += command+str( x )+", "+str( y )+" " the_color = "black" stroke_width = 1 dwg.add( dwg.path( p ).stroke( the_color, stroke_width ).fill( "none" ) ) dwg.save( ) display( SVG( dwg.tostring( ) ) )
Example #28
Source File: generate_hanzi_grids.py From anki-maobi with MIT License | 5 votes |
def rice(): o = GRID_STROKE_WIDTH / 2 dwg = svgwrite.Drawing('maobi/rice.svg', profile='tiny', size=(SIZE, SIZE)) dwg.add(dwg.line((o, o), (SIZE - o, SIZE - o), stroke=GRID_COLOR, stroke_width=GRID_STROKE_WIDTH)) dwg.add(dwg.line((o, SIZE - o), (SIZE - o, o), stroke=GRID_COLOR, stroke_width=GRID_STROKE_WIDTH)) dwg.add(dwg.line((SIZE / 2, 0), (SIZE / 2, SIZE), stroke=GRID_COLOR, stroke_width=GRID_STROKE_WIDTH)) dwg.add(dwg.line((0, SIZE / 2), (SIZE, SIZE / 2), stroke=GRID_COLOR, stroke_width=GRID_STROKE_WIDTH)) dwg.save()
Example #29
Source File: generate_hanzi_grids.py From anki-maobi with MIT License | 5 votes |
def field(): dwg = svgwrite.Drawing('maobi/field.svg', profile='tiny', size=(SIZE, SIZE)) dwg.add(dwg.line((SIZE / 2, 0), (SIZE / 2, SIZE), stroke=GRID_COLOR, stroke_width=GRID_STROKE_WIDTH)) dwg.add(dwg.line((0, SIZE / 2), (SIZE, SIZE / 2), stroke=GRID_COLOR, stroke_width=GRID_STROKE_WIDTH)) dwg.save()
Example #30
Source File: tracks_drawer.py From GpxTrackPoster with MIT License | 5 votes |
def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY): pass