push()#

The push() function saves the current drawing style settings and transformations, while pop() restores these settings.

Examples#

example picture for push()
 1def setup():
 2    py5.fill(255)
 3    py5.rect(0, 0, 50, 50)  # white rectangle
 4
 5    py5.push()
 6    py5.translate(30, 20)
 7    py5.fill(0)
 8    py5.rect(0, 0, 50, 50)  # black rectangle
 9    py5.pop()  # restore original settings
10
11    py5.fill(100)
12    py5.rect(15, 10, 50, 50)  # gray rectangle
example picture for push()
 1def setup():
 2    py5.ellipse(0, 50, 33, 33)  # left circle
 3
 4    py5.push()
 5    py5.stroke_weight(10)
 6    py5.fill(204, 153, 0)
 7    py5.ellipse(50, 50, 33, 33)  # middle circle
 8    py5.pop()  # restore original settings
 9
10    py5.ellipse(100, 50, 33, 33)  # right circle

Description#

The push() function saves the current drawing style settings and transformations, while pop() restores these settings. Note that these functions are always used together. They allow you to change the style and transformation settings and later return to what you had. When a new state is started with push(), it builds on the current style and transform information.

push() stores information related to the current transformation state and style settings controlled by the following functions: rotate(), translate(), scale(), fill(), stroke(), tint(), stroke_weight(), stroke_cap(), stroke_join(), image_mode(), rect_mode(), ellipse_mode(), color_mode(), text_align(), text_font(), text_mode(), text_size(), and text_leading().

The push() and pop() functions can be used in place of push_matrix(), pop_matrix(), push_style(), and pop_style(). The difference is that push() and pop() control both the transformations (rotate, scale, translate) and the drawing styles at the same time.

Underlying Processing method: push

Syntax#

push() -> None

Updated on November 12, 2021 11:30:58am UTC