Previous

Colors

Next

Stroke

More

Fill

Set a fill before drawing a shape.

fill(r: float | None = None, g: float | None = None, b: float | None = None, alpha: float = 1)

Sets the fill color with a red, green, blue and alpha value. Each argument must a value float between 0 and 1.

fill(1, 0, 0, .5)
# draw a rect
rect(10, 10, 200, 980)

# only set a gray value
fill(0)
# draw a rect
rect(200, 10, 200, 980)

# only set a gray value with an alpha
fill(0, .5)
# draw a rect
rect(400, 10, 200, 980)

# set rgb with no alpha
fill(1, 0, 0)
# draw a rect
rect(600, 10, 200, 980)

# set rgb with an alpha value
fill(1, 0, 0, .5)
# draw a rect
rect(800, 10, 190, 980)
linearGradient(startPoint: tuple[float, float] | None = None, endPoint: tuple[float, float] | None = None, colors: list[float | tuple[float, ...] | tuple[float, float, float]] | None = None, locations: list[float] | None = None)

A linear gradient fill with:

  • startPoint as (x, y)

  • endPoint as (x, y)

  • colors as a list of colors, tuples of floating point values (0 → 1)

  • locations of each color as a list of floats. (optionally)

Setting a gradient will ignore the fill.

# set a gradient as the fill color
linearGradient(
    (100, 100),                         # startPoint
    (800, 800),                         # endPoint
    [(1, 0, 0), (0, 0, 1), (0, 1, 0)],  # colors
    [0, .2, 1]                          # locations
    )
# draw a rectangle
rect(10, 10, 980, 980)
radialGradient(startPoint: tuple[float, float] | None = None, endPoint: tuple[float, float] | None = None, colors: list[float | tuple[float, ...]] | None = None, locations: list[float] | None = None, startRadius: float = 0, endRadius: float = 100)

A radial gradient fill with:

  • startPoint as (x, y)

  • endPoint as (x, y)

  • colors as a list of colors, described similary as fill

  • locations of each color as a list of floats. (optionally)

  • startRadius radius around the startPoint in degrees (optionally)

  • endRadius radius around the endPoint in degrees (optionally)

Setting a gradient will ignore the fill.

# set a gradient as the fill color
radialGradient(
    (300, 300),                         # startPoint
    (600, 600),                         # endPoint
    [(1, 0, 0), (0, 0, 1), (0, 1, 0)],  # colors
    [0, .2, 1],                         # locations
    0,                                  # startRadius
    500                                 # endRadius
    )
# draw a rectangle
rect(10, 10, 980, 980)
shadow(offset: tuple[float, float], blur: float | None = None, color: tuple[float, ...] | None = None)

Adds a shadow with an offset (x, y), blur and a color. The color argument must be a tuple similarly as fill. The offset`and `blur argument will be drawn independent of the current context transformations.

# a red shadow with some blur and a offset
shadow((100, 100), 100, (1, 0, 0))
# draw a rect
rect(100, 100, 600, 600)