Py5Shape.add_child()#

Adds a child Py5Shape object to a parent Py5Shape object that is defined as a GROUP.

Examples#

 1def setup():
 2    py5.size(200, 200)
 3    # make a group Py5Shape
 4    house = py5.create_shape(py5.GROUP)
 5
 6    # make three shapes
 7    path = py5.create_shape()
 8    path.begin_shape()
 9    path.vertex(-20, -20)
10    path.vertex(0, -40)
11    path.vertex(20, -20)
12    path.end_shape()
13    rectangle = py5.create_shape(py5.RECT, -20, -20, 40, 40)
14    opening = py5.create_shape(py5.ELLIPSE, 0, 0, 20, 20)
15
16    # add all three as children
17    house.add_child(path)
18    house.add_child(rectangle)
19    house.add_child(opening)
20
21    py5.background(52)
22    py5.translate(py5.mouse_x, py5.mouse_y)
23    py5.shape(house)

Description#

Adds a child Py5Shape object to a parent Py5Shape object that is defined as a GROUP. In the example, the three shapes path, rectangle, and circle are added to a parent Py5Shape variable named house that is a GROUP.

Underlying Processing method: PShape.addChild

Syntax#

add_child(who: Py5Shape, /) -> None
add_child(who: Py5Shape, idx: int, /) -> None

Parameters#

  • idx: int - the layer position in which to insert the new child

  • who: Py5Shape - any variable of type Py5Shape

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