push_style()#
The push_style()
function saves the current style settings and pop_style() restores the prior settings.
Examples#
def setup():
py5.ellipse(0, 50, 33, 33) # left circle
py5.push_style() # start a new style
py5.stroke_weight(10)
py5.fill(204, 153, 0)
py5.ellipse(50, 50, 33, 33) # middle circle
py5.pop_style() # restore original style
py5.ellipse(100, 50, 33, 33) # right circle
def setup():
py5.ellipse(0, 50, 33, 33) # left circle
with py5.push_style(): # start a new style
py5.stroke_weight(10)
py5.fill(204, 153, 0)
py5.ellipse(33, 50, 33, 33) # left-middle circle
with py5.push_style(): # start another new style
py5.stroke(0, 102, 153)
py5.ellipse(66, 50, 33, 33) # right-middle circle
py5.ellipse(100, 50, 33, 33) # right circle
Description#
The push_style()
function saves the current style settings and 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 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: fill(), stroke(), tint(), stroke_weight(), stroke_cap(), stroke_join(), image_mode(), rect_mode(), ellipse_mode(), shape_mode(), color_mode(), text_align(), text_font(), text_mode(), text_size(), text_leading(), emissive(), specular(), shininess(), and ambient().
This method can be used as a context manager to ensure that pop_style() always gets called, as shown in the last example.
Underlying Processing method: pushStyle
Signatures#
push_style() -> None
Updated on March 06, 2023 02:49:26am UTC