Py5Graphics.push_matrix()#

Pushes the current transformation matrix onto the matrix stack.

Examples#

example picture for push_matrix()
 1def setup():
 2    py5.size(100, 100, py5.P2D)
 3
 4    g = py5.create_graphics(60, 60, py5.P2D)
 5    with g.begin_draw():
 6        g.translate(30, 30)
 7        with g.push_matrix():
 8            g.scale(2)
 9            with g.begin_closed_shape():
10                g.vertex(-10, -10)
11                g.vertex(10, -10)
12                g.vertex(10, 10)
13                g.vertex(-10, 10)
14        with g.begin_closed_shape():
15            g.vertex(-10, -10)
16            g.vertex(10, -10)
17            g.vertex(10, 10)
18            g.vertex(-10, 10)
19
20    py5.image(g, 0, 0)
21    py5.image(g, 25, 25)

Description#

Pushes the current transformation matrix onto the matrix stack. Understanding push_matrix() and Py5Graphics.pop_matrix() requires understanding the concept of a matrix stack. The push_matrix() function saves the current coordinate system to the stack and Py5Graphics.pop_matrix() restores the prior coordinate system. push_matrix() and Py5Graphics.pop_matrix() are used in conjuction with the other transformation functions and may be embedded to control the scope of the transformations.

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

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

Underlying Processing method: PGraphics.pushMatrix

Syntax#

push_matrix() -> None

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