Py5Shape.set_fill()

Py5Shape.set_fill()#

The set_fill() method defines the fill color of a Py5Shape.

Examples#

def setup():
    global c
    py5.size(640, 360, py5.P2D)
    c = py5.create_shape(py5.RECT, -20, -20, 40, 40)
    c.set_stroke("#FFFFFF")


def draw():
    py5.background(51)
    c.set_fill(py5.color(py5.random_int(255)))
    py5.translate(py5.mouse_x, py5.mouse_y)
    py5.shape(c)

Description#

The set_fill() method defines the fill color of a Py5Shape. This method is used after shapes are created or when a shape is defined explicitly (e.g. create_shape(RECT, 20, 20, 60, 60)) as shown in the example. When a shape is created with Py5Shape.begin_shape() and Py5Shape.end_shape(), its attributes may be changed with Py5Shape.fill() and Py5Shape.stroke() between the calls to Py5Shape.begin_shape() and Py5Shape.end_shape(). However, after the shape is created, only the set_fill() method can define a new fill value for the Py5Shape.

This method has additional color functionality that is not reflected in the method’s signatures. For example, you can pass the name of a color (e.g. “green”, “mediumpurple”, etc). Look at the online “All About Colors” Python Ecosystem Integration tutorial for more information.

Underlying Processing method: PShape.setFill

Signatures#

set_fill(
    fill: bool,  # allow fill
    /,
) -> None

set_fill(
    fill: int,  # any color value
    /,
) -> None

set_fill(
    index: int,  # vertex index
    fill: int,  # any color value
    /,
) -> None

Updated on December 25, 2023 16:36:33pm UTC