Py5Shape.set_stroke()#

The set_stroke() method defines the outline 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_stroke() method defines the outline 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() within Py5Shape.begin_shape() and Py5Shape.end_shape(). However, after the shape is created, only the set_stroke() method can define a new stroke 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.setStroke

Signatures#

set_stroke(
    index: int,  # vertex index
    stroke: int,  # any color value
    /,
) -> None

set_stroke(
    stroke: bool,  # allow stroke
    /,
) -> None

set_stroke(
    stroke: int,  # any color value
    /,
) -> None

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