当前位置: 首页>>代码示例>>Python>>正文


Python cairo.LINE_CAP_ROUND属性代码示例

本文整理汇总了Python中cairo.LINE_CAP_ROUND属性的典型用法代码示例。如果您正苦于以下问题:Python cairo.LINE_CAP_ROUND属性的具体用法?Python cairo.LINE_CAP_ROUND怎么用?Python cairo.LINE_CAP_ROUND使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cairo的用法示例。


在下文中一共展示了cairo.LINE_CAP_ROUND属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def render(self, scale=96/25.4, margin=10, line_width=0.5):
        import cairo
        x1, y1, x2, y2 = self.bounds
        width = int(scale * self.width + margin * 2)
        height = int(scale * self.height + margin * 2)
        surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
        dc = cairo.Context(surface)
        dc.set_line_cap(cairo.LINE_CAP_ROUND)
        dc.translate(margin, height - margin)
        dc.scale(scale, -scale)
        dc.translate(-x1, -y1)
        dc.set_line_width(line_width)
        dc.set_source_rgb(1, 1, 1)
        dc.paint()
        # dc.arc(0, 0, 3.0 / scale, 0, 2 * math.pi)
        # dc.set_source_rgb(1, 0, 0)
        # dc.fill()
        dc.set_source_rgb(0, 0, 0)
        for path in self.paths:
            dc.move_to(*path[0])
            for x, y in path:
                dc.line_to(x, y)
        dc.stroke()
        return surface 
开发者ID:fogleman,项目名称:xy,代码行数:26,代码来源:drawing.py

示例2: lines

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def lines(ctx, colors, x, y, width, height, num_steps, line_width):
    ctx.save()
    ctx.translate(x + width / 2, y + height / 2)
    ctx.rotate(random.uniform(- math.pi / 2, math.pi / 2))
    ctx.translate(-width/2, -height/2)

    step_size = max(width, height) // num_steps
    current_x = 0
    while current_x < width:
        ctx.move_to(current_x, 0)
        ctx.line_to(current_x, height)
        ctx.set_source_rgb(*palettes.hex_to_tuple(random.choice(colors)))
        ctx.set_line_width(line_width)
        ctx.set_line_cap(cairo.LINE_CAP_ROUND)
        ctx.stroke()
        current_x += step_size
    ctx.restore() 
开发者ID:anaulin,项目名称:generative-art,代码行数:19,代码来源:un_deux_trois.py

示例3: diagonal

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def diagonal(ctx, color, line_width):
    if random.random() < 0.5:
        start_x = -line_width
        start_y = random.randint(IMG_HEIGHT // 3, IMG_HEIGHT - line_width)
        ctx.move_to(start_x, start_y)
    else:
        start_x = random.randint(-line_width, IMG_WIDTH // 3)
        start_y = IMG_HEIGHT + line_width
        ctx.move_to(start_x, start_y)

    end_x = random.randint(start_x + 2 * line_width, IMG_WIDTH)
    end_y = random.randint(0, start_y - 2*line_width)
    ctx.line_to(end_x, end_y)
    ctx.set_source(gradient(color, start_x, start_y, end_x, end_y))
    ctx.set_line_width(line_width)
    ctx.set_line_cap(cairo.LINE_CAP_ROUND)
    ctx.stroke() 
开发者ID:anaulin,项目名称:generative-art,代码行数:19,代码来源:thick_diagonals.py

示例4: draw_scribble

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def draw_scribble(self, widget, cairo_context):
        """ Perform the drawings by user.

        Args:
            widget (:class:`~Gtk.DrawingArea`): The widget where to draw the scribbles.
            cairo_context (:class:`~cairo.Context`): The canvas on which to render the drawings
        """
        ww, wh = widget.get_allocated_width(), widget.get_allocated_height()

        cairo_context.set_line_cap(cairo.LINE_CAP_ROUND)

        for color, width, points in self.scribble_list:
            points = [(p[0] * ww, p[1] * wh) for p in points]

            cairo_context.set_source_rgba(*color)
            cairo_context.set_line_width(width)
            cairo_context.move_to(*points[0])

            for p in points[1:]:
                cairo_context.line_to(*p)
            cairo_context.stroke() 
开发者ID:Cimbali,项目名称:pympress,代码行数:23,代码来源:scribble.py

示例5: do_draw

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def do_draw(self, cr, background_area, cell_area, start, end, state):
        in_statement, is_current = self._in_statement(start)
        if not in_statement:
            return
        style = self.buffer.get_style_scheme()
        ref_style = style.get_style('line-numbers')
        if ref_style is not None:
            ok, col_default = Gdk.Color.parse(
                ref_style.get_property('foreground'))
        else:
            ok, col_default = Gdk.Color.parse('#1565C0')
        ok, col_highlight = Gdk.Color.parse('#1565C0')
        cr.move_to(cell_area.x, cell_area.y)
        cr.line_to(cell_area.x, cell_area.y + cell_area.height)
        cr.set_line_width(10)
        cr.set_line_cap(cairo.LINE_CAP_ROUND)
        if is_current:
            cr.set_source_rgb(*col_highlight.to_floats())
        else:
            cr.set_source_rgb(*col_default.to_floats())
        cr.stroke() 
开发者ID:andialbrecht,项目名称:runsqlrun,代码行数:23,代码来源:editor.py

示例6: render

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def render(
            self, dual=False, background_color=BACKGROUND_COLOR, margin=MARGIN,
            show_labels=SHOW_LABELS, line_width=LINE_WIDTH):
        surface = cairo.ImageSurface(
            cairo.FORMAT_RGB24, self.width, self.height)
        dc = cairo.Context(surface)
        dc.set_line_cap(cairo.LINE_CAP_ROUND)
        dc.set_line_join(cairo.LINE_JOIN_ROUND)
        dc.set_line_width(line_width)
        dc.set_font_size(18.0 / self.scale)
        dc.translate(self.width / 2, self.height / 2)
        dc.scale(self.scale, self.scale)
        dc.set_source_rgb(*color(background_color))
        dc.paint()
        shapes = self.dual() if dual else self.lookup.values()
        if show_labels:
            for shape in shapes:
                shape.render_edge_labels(dc, margin - 0.25)
        for shape in shapes:
            shape.render(dc, margin)
        if show_labels:
            for index, shape in enumerate(self.shapes):
                if shape in shapes:
                    shape.render_label(dc, index)
        return surface 
开发者ID:fogleman,项目名称:Tiling,代码行数:27,代码来源:tile.py

示例7: cairo_line_cap

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def cairo_line_cap(line_cap):
  if line_cap == 'round':
    return cairo.LINE_CAP_ROUND
  elif line_cap == 'square':
    return cairo.LINE_CAP_SQUARE
  else:
    return cairo.LINE_CAP_BUTT 
开发者ID:kevinpt,项目名称:symbolator,代码行数:9,代码来源:cairo_backend.py

示例8: render_cairo

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def render_cairo(self, ctx, origx, origy):
        ctx.set_line_width(max(self.thickness, MIN_WIDTH))
        ctx.set_line_cap(cairo.LINE_CAP_ROUND)
        p = self.points[0]
        ctx.move_to (origx + p[0], origy - p[1])
        for p in self.points[1:]:
            ctx.line_to (origx + p[0], origy - p[1])

        if self.fill == "f":
            ctx.close_path()
            ctx.set_source_rgb(*COLOR_FG)
            ctx.stroke_preserve()
            ctx.set_source_rgb(*COLOR_BG)
            ctx.fill()
        elif self.fill == "F":
            ctx.close_path()
            ctx.set_source_rgb(*COLOR_FG)
            ctx.stroke_preserve()
            ctx.set_source_rgb(*COLOR_FG)
            ctx.fill()
        else:
            ctx.set_source_rgb(*COLOR_FG)
            ctx.stroke()

        minx = min(i[0] for i in self.points) + origx
        maxx = max(i[0] for i in self.points) + origx
        miny = min(-i[1] for i in self.points) + origy
        maxy = max(-i[1] for i in self.points) + origy
        return BoundingBox(minx, maxx, miny, maxy) 
开发者ID:alexisvl,项目名称:kicad-schlib,代码行数:31,代码来源:schlib-render.py

示例9: main

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def main(hexagon_size, imgsize):
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, imgsize, imgsize)
    ctx = cairo.Context(surface)

    # we will put the center of the hexagon at the origin
    a, b, c = hexagon_size
    ctx.translate(imgsize / 2.0, imgsize / 2.0)
    extent = max(c, a * HALFSQRT3, b * HALFSQRT3) + 1
    ctx.scale(imgsize / (extent * 2.0), -imgsize / (extent * 2.0))
    ctx.translate(-b * HALFSQRT3, -c / 2.0)

    # paint background
    ctx.set_source_rgb(1, 1, 1)
    ctx.paint()
    ctx.set_line_cap(cairo.LINE_CAP_ROUND)
    ctx.set_line_join(cairo.LINE_JOIN_ROUND)

    T = LozengeTiling(hexagon_size)
    sample = run_cftp(T)
    for key, val in T.get_tiles(sample).items():
        for verts in val:
            A, B, C, D = square_to_hex(verts)
            ctx.move_to(A[0], A[1])
            ctx.line_to(B[0], B[1])
            ctx.line_to(C[0], C[1])
            ctx.line_to(D[0], D[1])
            ctx.close_path()
            if key == "T":
                ctx.set_source_rgb(*TOP_COLOR)
            elif key == "L":
                ctx.set_source_rgb(*LEFT_COLOR)
            else:
                ctx.set_source_rgb(*RIGHT_COLOR)
            ctx.fill_preserve()
            ctx.set_line_width(LINE_WIDTH)
            ctx.set_source_rgb(*EDGE_COLOR)
            ctx.stroke()

    surface.write_to_png("random_lozenge_tiling.png") 
开发者ID:neozhaoliang,项目名称:pywonderland,代码行数:41,代码来源:main.py

示例10: main

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def main():
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
    ctx = cairo.Context(surface)
    ctx.set_line_cap(cairo.LINE_CAP_ROUND)
    ctx.set_line_join(cairo.LINE_JOIN_ROUND)
    ctx.set_source_rgb(1, 1, 1)
    ctx.paint()
    fractal_tree(ctx, ITERATIONS, ROOT, TRUNK_LEN,
                 RATIO, THETA, ANGLE, PERTURB)
    surface.write_to_png("random_fractal_tree.png") 
开发者ID:neozhaoliang,项目名称:pywonderland,代码行数:12,代码来源:fractaltree.py

示例11: line

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def line(ctx, color, line_width):
    x1 = random.randint(0, IMG_WIDTH)
    y1 = random.randint(0, IMG_HEIGHT)
    x2 = random.randint(0, IMG_WIDTH)
    y2 = random.randint(0, IMG_HEIGHT)
    ctx.move_to(x1, y1)
    ctx.line_to(x2, y2)
    # Make lines more transparent, they tend to overtake things because they're long.
    alpha = random.uniform(0.09, 0.4)
    ctx.set_source_rgba(*color, alpha)
    ctx.set_line_width(line_width)
    ctx.set_line_cap(cairo.LINE_CAP_ROUND)
    ctx.stroke() 
开发者ID:anaulin,项目名称:generative-art,代码行数:15,代码来源:just_shapes.py

示例12: make_curve

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def make_curve(ctx, points, color, line_width):
    ctx.move_to(*points[0])
    ctx.curve_to(*points[1], *points[2], *points[3])
    ctx.set_line_width(line_width)
    ctx.set_line_cap(cairo.LINE_CAP_ROUND)
    ctx.set_source_rgb(*color)
    ctx.stroke() 
开发者ID:anaulin,项目名称:generative-art,代码行数:9,代码来源:esses.py

示例13: draw

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def draw(self, context):
        if self.parent and self.parent.moving:
            return

        def draw_line_end(pos, angle, port, draw):
            cr.save()
            cr.translate(*pos)
            cr.rotate(angle)
            draw(context, port)
            cr.restore()
        self.line_width = self._calc_line_width()
        cr = context.cairo
        cr.set_line_cap(LINE_CAP_ROUND)
        cr.set_line_width(self.line_width)

        # Draw connection tail (line perpendicular to from_port)
        start_segment_index = 0
        if self.from_port:
            draw_line_end(self._handles[0].pos, self._head_angle, self.from_port, self.draw_tail)
            start_segment_index = 1

        # Draw connection head (line perpendicular to to_port)
        end_segment_index = len(self._handles)
        if self.to_port:
            draw_line_end(self._handles[-1].pos, self._tail_angle, self.to_port, self.draw_head)
            end_segment_index -= 1

        # Draw connection line from waypoint to waypoint
        cr.move_to(*self._handles[start_segment_index].pos)
        for h in self._handles[start_segment_index+1:end_segment_index]:
            cr.line_to(*h.pos)
        cr.set_source_rgba(*self._line_color)
        cr.stroke()

        if self.name and (isinstance(self.from_port, LogicPortView) or
                          global_gui_config.get_config_value("SHOW_NAMES_ON_DATA_FLOWS", default=True)):
            self._draw_name(context) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:39,代码来源:line.py

示例14: draw

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def draw(self, context):
        allocation = self.get_allocation()
        x_loc = allocation.x
        y_loc = allocation.y
        width = allocation.width - 1
        height = allocation.height

        context.set_source_rgb(.2, .2, .2)
        #        context.rectangle(0, 0, width, height)
        #        context.fill()

        context.move_to(
            self.__toAHalf(x_loc + width / 2.) - LONG_LINE,
            self.__toAHalf(y_loc + height / 2.))
        context.line_to(
            self.__toAHalf(x_loc + width / 2.), self.__toAHalf(y_loc + height / 2.))
        if self.position == CHAIN_TOP:
            context.line_to(
                self.__toAHalf(x_loc + width / 2.),
                self.__toAHalf(float(y_loc + height)))
        else:
            context.line_to(
                self.__toAHalf(x_loc + width / 2.), self.__toAHalf(y_loc + 0.))
        context.set_line_width(1.0)
        context.set_line_cap(cairo.LINE_CAP_ROUND)
        context.set_line_join(cairo.LINE_JOIN_ROUND)
        context.stroke() 
开发者ID:pychess,项目名称:pychess,代码行数:29,代码来源:ChainVBox.py

示例15: draw_line

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LINE_CAP_ROUND [as 别名]
def draw_line(ctxs, draw):
    layer = [n for n in draw if n[0] == "layer"][0][1]
    if layer in ctxs:
        ctx = ctxs[layer]
        rgba = colours[layer]
        width = [n for n in draw if n[0] == "width"][0][1]
        ctx.set_source_rgba(*rgba)
        ctx.set_line_width(float(width))
        ctx.set_line_cap(cairo.LINE_CAP_ROUND)
        if draw[0] == "fp_line":
            start = [n for n in draw if n[0] == "start"][0]
            end = [n for n in draw if n[0] == "end"][0]
            ctx.move_to(float(start[1]), float(start[2]))
            ctx.line_to(float(end[1]), float(end[2]))
        elif draw[0] == "fp_circle":
            center = [n for n in draw if n[0] == "center"][0]
            end = [n for n in draw if n[0] == "end"][0]
            dx = float(end[1]) - float(center[1])
            dy = float(end[2]) - float(center[2])
            r = math.sqrt(dx**2 + dy**2)
            ctx.new_sub_path()
            ctx.arc(float(center[1]), float(center[2]), r, 0, 2*math.pi)
        elif draw[0] == "fp_arc":
            start = [n for n in draw if n[0] == "start"][0]
            end = [n for n in draw if n[0] == "end"][0]
            angle = [n for n in draw if n[0] == "angle"][0]
            dx = float(end[1]) - float(start[1])
            dy = float(end[2]) - float(start[2])
            r = math.sqrt(dx**2 + dy**2)
            a_start = math.atan2(dy, dx)
            a_end = a_start + float(angle[1]) * (math.pi / 180.0)
            ctx.new_sub_path()
            ctx.arc(float(start[1]), float(start[2]), r, a_start, a_end)
        ctx.stroke() 
开发者ID:adamgreig,项目名称:agg-kicad,代码行数:36,代码来源:draw_mod.py


注:本文中的cairo.LINE_CAP_ROUND属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。