當前位置: 首頁>>代碼示例>>Python>>正文


Python svgwrite.Drawing方法代碼示例

本文整理匯總了Python中svgwrite.Drawing方法的典型用法代碼示例。如果您正苦於以下問題:Python svgwrite.Drawing方法的具體用法?Python svgwrite.Drawing怎麽用?Python svgwrite.Drawing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在svgwrite的用法示例。


在下文中一共展示了svgwrite.Drawing方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: save

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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() 
開發者ID:bodqhrohro,項目名稱:giftolottie,代碼行數:18,代碼來源:svg.py

示例2: main

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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') 
開發者ID:svenkreiss,項目名稱:databench,代碼行數:24,代碼來源:create.py

示例3: _draw_rings

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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 
開發者ID:flopp,項目名稱:GpxTrackPoster,代碼行數:24,代碼來源:circular_drawer.py

示例4: draw

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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",
                        )
                    ) 
開發者ID:flopp,項目名稱:GpxTrackPoster,代碼行數:20,代碼來源:heatmap_drawer.py

示例5: draw

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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 
開發者ID:flopp,項目名稱:GpxTrackPoster,代碼行數:26,代碼來源:calendar_drawer.py

示例6: save_svg

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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() 
開發者ID:akolishchak,項目名稱:doom-net-pytorch,代碼行數:22,代碼來源:wad.py

示例7: draw

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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() 
開發者ID:dmpayton,項目名稱:python-fretboard,代碼行數:27,代碼來源:fretboard.py

示例8: generate_svg

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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() 
開發者ID:google-coral,項目名稱:examples-camera,代碼行數:27,代碼來源:detect.py

示例9: generate_works

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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() 
開發者ID:phodal,項目名稱:brand,代碼行數:22,代碼來源:basic.py

示例10: draw

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
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()) 
開發者ID:tskit-dev,項目名稱:tsinfer,代碼行數:15,代碼來源:visualisation.py

示例11: main

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
def main():
    background_locked = False
    timer_time = time.monotonic()

    def run_inference(engine, input_tensor):
        return engine.run_inference(input_tensor)

    def render_overlay(engine, output, src_size, inference_box):
        nonlocal timer_time, background_locked
        svg_canvas = svgwrite.Drawing('', size=src_size)
        outputs, inference_time = engine.ParseOutput(output)
        now_time = time.monotonic()

        if not background_locked:
            print('Waiting for everyone to leave the frame...')
            pose_camera.shadow_text(svg_canvas, 10, 20,
                                    'Waiting for everyone to leave the frame...')
            if outputs:  # frame still has people in it, restart timer
                timer_time = now_time
            elif now_time > timer_time + BACKGROUND_DELAY:  # frame has been empty long enough
                background_locked = True
                print('Background set.')

        for pose in outputs:
            pose_camera.draw_pose(svg_canvas, pose, src_size, inference_box)

        return (svg_canvas.tostring(), background_locked)

    pose_camera.run(run_inference, render_overlay) 
開發者ID:google-coral,項目名稱:project-posenet,代碼行數:31,代碼來源:anonymizer.py

示例12: main

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
def main():
    n = 0
    sum_process_time = 0
    sum_inference_time = 0
    ctr = 0
    fps_counter  = avg_fps_counter(30)

    def run_inference(engine, input_tensor):
        return engine.run_inference(input_tensor)

    def render_overlay(engine, output, src_size, inference_box):
        nonlocal n, sum_process_time, sum_inference_time, fps_counter

        svg_canvas = svgwrite.Drawing('', size=src_size)
        start_time = time.monotonic()
        outputs, inference_time = engine.ParseOutput(output)
        end_time = time.monotonic()
        n += 1
        sum_process_time += 1000 * (end_time - start_time)
        sum_inference_time += inference_time

        avg_inference_time = sum_inference_time / n
        text_line = 'PoseNet: %.1fms (%.2f fps) TrueFPS: %.2f Nposes %d' % (
            avg_inference_time, 1000 / avg_inference_time, next(fps_counter), len(outputs)
        )

        shadow_text(svg_canvas, 10, 20, text_line)
        for pose in outputs:
            draw_pose(svg_canvas, pose, src_size, inference_box)
        return (svg_canvas.tostring(), False)

    run(run_inference, render_overlay) 
開發者ID:google-coral,項目名稱:project-posenet,代碼行數:34,代碼來源:pose_camera.py

示例13: __init__

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
def __init__(self, filename):
		# load timeline data
		s = ''
		with open(filename) as f:
			s = f.read()
		self.data = json.loads(s)
		assert 'width' in self.data, 'width property must be set'
		assert 'start' in self.data, 'start property must be set'
		assert 'end' in self.data, 'end property must be set'
		# create drawing
		self.width = self.data['width']
		self.drawing = svgwrite.Drawing()
		self.drawing['width'] = self.width
		self.g_axis = self.drawing.g()		
		# figure out timeline boundaries
		self.cal = parsedatetime.Calendar()
		self.start_date = self.datetime_from_string(self.data['start'])
		self.end_date = self.datetime_from_string(self.data['end'])
		delta = self.end_date[0] - self.start_date[0]
		padding = datetime.timedelta(seconds=0.1*delta.total_seconds())
		self.date0 = self.start_date[0] - padding
		self.date1 = self.end_date[0] + padding
		self.total_secs = (self.date1 - self.date0).total_seconds()	
		# set up some params
		self.callout_size = (10, 15, 10) # width, height, increment
		self.text_fudge = (3, 1.5)
		self.tick_format = self.data.get('tick_format', None)
		self.markers = {}
		# initialize Tk so that font metrics will work
		self.tk_root = Tkinter.Tk()
		self.fonts = {}
		# max_label_height stores the max height of all axis labels
		# and is used in the final height computation in build(self)
		self.max_label_height = 0 
開發者ID:jasonreisman,項目名稱:Timeline,代碼行數:36,代碼來源:make_timeline.py

示例14: draw

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
def draw(self, drawer, output):
        """Set the Poster's drawer and draw the tracks."""
        self.tracks_drawer = drawer
        d = svgwrite.Drawing(output, (f"{self.width}mm", f"{self.height}mm"))
        d.viewbox(0, 0, self.width, self.height)
        d.add(d.rect((0, 0), (self.width, self.height), fill=self.colors["background"]))
        self.__draw_header(d)
        self.__draw_footer(d)
        self.__draw_tracks(d, XY(self.width - 20, self.height - 30 - 30), XY(10, 30))
        d.save() 
開發者ID:flopp,項目名稱:GpxTrackPoster,代碼行數:12,代碼來源:poster.py

示例15: draw

# 需要導入模塊: import svgwrite [as 別名]
# 或者: from svgwrite import Drawing [as 別名]
def draw(self, dr: svgwrite.Drawing, size: XY, offset: XY):
        """Draw the circular Poster using distances broken down by time"""
        if self.poster.tracks is None:
            raise PosterError("No tracks to draw.")
        if self.poster.length_range_by_date is None:
            return

        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, 4)
        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_year(dr, sub_size, offset + margin + cell_size * XY(x, y), year)
            x += 1
            if x >= count_x:
                x = 0
                y += 1 
開發者ID:flopp,項目名稱:GpxTrackPoster,代碼行數:28,代碼來源:circular_drawer.py


注:本文中的svgwrite.Drawing方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。