Py5Graphics.push_style()

Py5Graphics.push_style()#

The push_style() function saves the current style settings and Py5Graphics.pop_style() restores the prior settings.

Examples#

example picture for push_style()

def setup():
    py5.size(100, 100, py5.P2D)

    g = py5.create_graphics(60, 60, py5.P2D)
    with g.begin_draw():
        with g.push_style():
            g.stroke("#F00")
            with g.begin_closed_shape():
                g.vertex(10, 10)
                g.vertex(50, 10)
                g.vertex(50, 50)
                g.vertex(10, 50)
        with g.begin_closed_shape():
            g.vertex(12, 12)
            g.vertex(48, 12)
            g.vertex(48, 48)
            g.vertex(12, 48)

    py5.image(g, 0, 0)
    py5.image(g, 25, 25)

Description#

The push_style() function saves the current style settings and Py5Graphics.pop_style() restores the prior settings. Note that these functions are always used together. They allow you to change the style settings and later return to what you had. When a new style is started with push_style(), it builds on the current style information. The push_style() and Py5Graphics.pop_style() method pairs can be nested to provide more control. (See the second example for a demonstration.)

The style information controlled by the following functions are included in the style: Py5Graphics.fill(), Py5Graphics.stroke(), Py5Graphics.tint(), Py5Graphics.stroke_weight(), Py5Graphics.stroke_cap(), Py5Graphics.stroke_join(), Py5Graphics.image_mode(), Py5Graphics.rect_mode(), Py5Graphics.ellipse_mode(), Py5Graphics.shape_mode(), Py5Graphics.color_mode(), Py5Graphics.text_align(), Py5Graphics.text_font(), Py5Graphics.text_mode(), Py5Graphics.text_size(), Py5Graphics.text_leading(), Py5Graphics.emissive(), Py5Graphics.specular(), Py5Graphics.shininess(), and Py5Graphics.ambient().

This method can be used as a context manager to ensure that Py5Graphics.pop_style() always gets called, as shown in the example.

This method is the same as push_style() but linked to a Py5Graphics object. To see example code for how it can be used, see push_style().

Underlying Processing method: PGraphics.pushStyle

Signatures#

push_style() -> None

Updated on March 06, 2023 02:49:26am UTC