Search⌘ K

SolidPattern

Explore how to use SolidPattern in Pycairo to create solid color fills with customizable RGB and transparency settings. Understand how patterns combine with paths to produce filled shapes and how SolidPattern differs from set_source_rgb.

What does SolidPattern do?

A SolidPattern creates a solid color fill. Here is the full code to draw an orange circle on a white background:

Python 3.8
import cairo
import math
# Set up surface
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 400, 400)
ctx = cairo.Context(surface)
ctx.set_source_rgb(1, 1, 1)
ctx.paint()
# SolidPattern
pattern = cairo.SolidPattern(1, 0.5, 0)
ctx.set_source(pattern)
ctx.arc(200, 200, 100, 0, math.pi*2)
ctx.fill()

The SolidPattern constructor takes three values: r, g, and b, which set the RGB color of the solid fill. The parameters work in the same way as the set_source_rgb function, so the values ...