Py5Shape.scale()

Increases or decreases the size of a shape by expanding and contracting vertices.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def setup():
    global s
    s = py5.load_shape("bot.svg")


def draw():
    py5.background(204)
    py5.shape(s)


def mouse_pressed():
    # shrink the shape 90% each time the mouse is pressed
    s.scale(0.9)

Description

Increases or decreases the size of a shape by expanding and contracting vertices. Shapes always scale from the relative origin of their bounding box. Scale values are specified as decimal percentages. For example, the method call scale(2.0) increases the dimension of a shape by 200%. Subsequent calls to the method multiply the effect. For example, calling scale(2.0) and then scale(1.5) is the same as scale(3.0). This transformation is applied directly to the shape; it’s not refreshed each time draw() is run.

Using this method with the z parameter requires using the P3D parameter in combination with size.

Underlying Java method: PShape.scale

Syntax

scale(s: float, /) -> None
scale(x: float, y: float, /) -> None
scale(x: float, y: float, z: float, /) -> None

Parameters

  • s: float - percentate to scale the object

  • x: float - percentage to scale the object in the x-axis

  • y: float - percentage to scale the object in the y-axis

  • z: float - percentage to scale the object in the z-axis

Updated on September 11, 2021 16:51:34pm UTC