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


Python cairo.LinearGradient方法代码示例

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


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

示例1: draw_gradient

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def draw_gradient(self):
        w, h = self.get_size()
        gradient = self.fill[2]
        surface = cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
        ctx = cairo.Context(surface)
        self.draw_cairo_background(ctx)
        if gradient[0] == sk2const.GRADIENT_LINEAR:
            grd = cairo.LinearGradient(0.0, h / 2.0, w, h / 2.0)
        else:
            grd = cairo.RadialGradient(w / 2.0, h / 2.0, 0,
                                       w / 2.0, h / 2.0, w / 2.0)
        for stop in gradient[2]:
            grd.add_color_stop_rgba(stop[0], *self.get_cairo_color(stop[1]))
        ctx.set_source(grd)
        ctx.rectangle(0, 0, w, h)
        ctx.fill()
        self.gc_draw_bitmap(wal.copy_surface_to_bitmap(surface), 0, 0) 
开发者ID:sk1project,项目名称:sk1-wx,代码行数:19,代码来源:colorctrls.py

示例2: draw_line

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def draw_line(ctx, x, y, width, height, line_width, palette):
    leftToRight = random.random() >= 0.5

    if leftToRight:
        start = (x, y)
        end = (x + width, y + height)
    else:
        start = (x + width, y)
        end = (x, y + height)

    ctx.move_to(start[0], start[1])
    ctx.line_to(end[0], end[1])

    ctx.set_line_width(line_width)
    ctx.set_line_cap(cairo.LineCap.ROUND)

    g = cairo.LinearGradient(start[0], start[1], end[0], end[1])
    colors = [hex_to_tuple(c) for c in random.choices(palette['colors'], k=2)]
    g.add_color_stop_rgb(0, *colors[0])
    g.add_color_stop_rgb(1, *colors[1])
    ctx.set_source(g)
    ctx.stroke() 
开发者ID:anaulin,项目名称:generative-art,代码行数:24,代码来源:tiled_lines.py

示例3: main

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def main(filename="output.png", img_width=2000, img_height=2000):
    ims = cairo.ImageSurface(cairo.FORMAT_ARGB32, img_width, img_height)
    ims.set_fallback_resolution(300.0, 300.0)
    ctx = cairo.Context(ims)

    ctx.rectangle(0, 0, img_width, img_height)
    gradient_start_y = random.randint(0, img_height)
    gradient_end_y = random.randint(gradient_start_y, img_height)
    gradient = cairo.LinearGradient(0, gradient_start_y, img_width, gradient_end_y)
    stop = 0
    while stop < 0.98:
        color = (random.random(), random.random(), random.random())
        gradient.add_color_stop_rgb(stop, *color)
        stop = random.uniform(stop, 1)

    ctx.set_source(gradient)
    ctx.fill()

    ims.write_to_png(filename) 
开发者ID:anaulin,项目名称:generative-art,代码行数:21,代码来源:color_field.py

示例4: draw_directed_edge

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def draw_directed_edge(self, edge, src_vertex, dest_vertex):
        if src_vertex == dest_vertex:  # TODO
            return self.draw_loop_edge(edge, src_vertex)

        src_pos, dest_pos = src_vertex.position, dest_vertex.position
        ctx = self.context

        # Set up the gradient
        lg = LinearGradient(src_pos[0], src_pos[1], dest_pos[0], dest_pos[1])
        edge_color = edge.color[:3] + self.alpha_at_src
        edge_color_end = edge_color[:3] + self.alpha_at_dest
        lg.add_color_stop_rgba(0, *edge_color)
        lg.add_color_stop_rgba(1, *edge_color_end)

        # Draw the edge
        ctx.set_source(lg)
        ctx.set_line_width(edge.width)
        ctx.move_to(*src_pos)
        ctx.line_to(*dest_pos)
        ctx.stroke() 
开发者ID:saezlab,项目名称:pypath,代码行数:22,代码来源:edge.py

示例5: get_random_gradient

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def get_random_gradient(square, palette):
    (x, y, size) = square
    g = cairo.LinearGradient(x, y, x + size * RATIO, y + size)
    colors = random_colors(palette, 2)
    g.add_color_stop_rgb(0, *colors[0])
    g.add_color_stop_rgb(1, *colors[1])
    return g 
开发者ID:anaulin,项目名称:generative-art,代码行数:9,代码来源:square-pack.py

示例6: draw_line

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def draw_line(ctx, x, y, x2, y2, line_width, color1, color2):
    ctx.move_to(x, y)
    ctx.line_to(x2, y2)

    ctx.set_line_width(line_width)
    ctx.set_line_cap(cairo.LineCap.ROUND)

    g = cairo.LinearGradient(x, y, x2, y2)
    g.add_color_stop_rgb(0, *color1)
    g.add_color_stop_rgb(1, *color2)
    ctx.set_source(g)
    ctx.stroke() 
开发者ID:anaulin,项目名称:generative-art,代码行数:14,代码来源:fingers.py

示例7: _do_draw

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def _do_draw(self, context, rect):
        """
        Do all the drawing stuff.
        
        @type context: cairo.Context
        @param context: The context to draw on.
        @type rect: gtk.gdk.Rectangle
        @param rect: A rectangle representing the charts area.
        """
        if self._color != None:
            #set source color
            context.set_source_rgb(*color_gdk_to_cairo(self._color))
        elif self._gradient != None:
            #set source gradient
            cs = color_gdk_to_cairo(self._gradient[0])
            ce = color_gdk_to_cairo(self._gradient[1])
            gradient = cairo.LinearGradient(0, 0, 0, rect.height)
            gradient.add_color_stop_rgb(0, cs[0], cs[1], cs[2])
            gradient.add_color_stop_rgb(1, ce[0], ce[1], ce[2])
            context.set_source(gradient)
        elif self._pixbuf:
            context.set_source_pixbuf(self._pixbuf, 0, 0)
        else:
            context.set_source_rgb(1, 1, 1) #fallback to white bg
        #create the background rectangle and fill it:
        context.rectangle(0, 0, rect.width, rect.height)
        context.fill() 
开发者ID:OpenXenManager,项目名称:openxenmanager,代码行数:29,代码来源:chart.py

示例8: get_pattern_h

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def get_pattern_h(self, xmin, xmax):
		pattern = cairo.LinearGradient(xmin, 0.0, xmax, 0.0)
		return pattern 
开发者ID:maoschanz,项目名称:drawing,代码行数:5,代码来源:tool_shape.py

示例9: get_pattern_v

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def get_pattern_v(self, ymin, ymax):
		pattern = cairo.LinearGradient(0.0, ymin, 0.0, ymax)
		return pattern 
开发者ID:maoschanz,项目名称:drawing,代码行数:5,代码来源:tool_shape.py

示例10: do_tool_operation

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def do_tool_operation(self, operation):
		cairo_context = self.start_tool_operation(operation)
		cairo_context.set_operator(operation['operator'])
		cairo_context.set_line_cap(operation['line_cap'])
		line_width = operation['line_width']
		cairo_context.set_line_width(line_width)
		c1 = operation['rgba']
		c2 = operation['rgba2']
		x1 = operation['x_press']
		y1 = operation['y_press']
		x2 = operation['x_release']
		y2 = operation['y_release']
		if operation['use_gradient']:
			pattern = cairo.LinearGradient(x1, y1, x2, y2)
			pattern.add_color_stop_rgba(0.1, c1.red, c1.green, c1.blue, c1.alpha)
			pattern.add_color_stop_rgba(0.9, c2.red, c2.green, c2.blue, c2.alpha)
			cairo_context.set_source(pattern)
		else:
			cairo_context.set_source_rgba(c1.red, c1.green, c1.blue, c1.alpha)
		if operation['use_dashes']:
			cairo_context.set_dash([2 * line_width, 2 * line_width])
		# We don't memorize the path because all coords are here anyway for the
		# linear grandient and/or the arrow.
		cairo_context.move_to(x1, y1)
		cairo_context.line_to(x2, y2)

		self.stroke_with_operator(operation['operator'], cairo_context, \
		                                    line_width, operation['is_preview'])

		if operation['use_arrow']:
			utilities_add_arrow_triangle(cairo_context, x2, y2, x1, y1, line_width)

	############################################################################
################################################################################ 
开发者ID:maoschanz,项目名称:drawing,代码行数:36,代码来源:tool_line.py

示例11: polyp

# 需要导入模块: import cairo [as 别名]
# 或者: from cairo import LinearGradient [as 别名]
def polyp(ctx, x, y, width, height, color):
    min_dimension = min(width, height)
    center_x = x + width // 2
    center_y = y + height // 2
    radius = random.randint(int(min_dimension / 10), int(min_dimension / 6))

    line_width = radius // 5
    ball_radius = int(line_width * 1.5)
    center = Point(0, 0).buffer(radius)
    existing_shapes = center.buffer(-0.1)
    for _ in range(20):
        for _ in range(MAX_ATTEMPTS):
            (end_x, end_y) = make_limb(width, height, ball_radius)
            ball = Point(end_x, end_y).buffer(ball_radius)
            line = LineString([(0, 0), (end_x, end_y)]).buffer(line_width).difference(center)
            limb = line.union(ball)
            if not existing_shapes.intersects(limb):
                break
        else:
            continue

        existing_shapes = existing_shapes.union(limb)

        # Draw line
        ctx.save()
        ctx.translate(center_x, center_y)
        ctx.move_to(0, 0)
        ctx.line_to(end_x, end_y)
        ctx.set_line_width(line_width)
        ctx.set_line_cap(cairo.LineCap.ROUND)
        g = cairo.LinearGradient(0, 0, end_x, end_y)
        add_gradient_stops(color, g)
        ctx.set_source(g)
        ctx.stroke()

        # Draw ball at the end
        g = cairo.RadialGradient(end_x, end_y, 0, end_x, end_y, ball_radius)
        add_gradient_stops(color, g)
        ctx.set_source(g)
        ctx.arc(end_x, end_y, ball_radius, 0, 2 * math.pi)
        ctx.fill()
        ctx.restore()

    # Draw in center
    g = cairo.RadialGradient(center_x, center_y, 0, center_x, center_y, radius)
    add_gradient_stops(color, g)
    ctx.set_source(g)
    ctx.arc(center_x, center_y, radius, 0, 2 * math.pi)
    ctx.fill() 
开发者ID:anaulin,项目名称:generative-art,代码行数:51,代码来源:coral_play.py


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