Py5Graphics.create_shape()

The create_shape() function is used to define a new shape.

Description

The create_shape() function is used to define a new shape. Once created, this shape can be drawn with the Py5Graphics.shape() function. The basic way to use the function defines new primitive shapes. One of the following parameters are used as the first parameter: ELLIPSE, RECT, ARC, TRIANGLE, SPHERE, BOX, QUAD, or LINE. The parameters for each of these different shapes are the same as their corresponding functions: Py5Graphics.ellipse(), Py5Graphics.rect(), Py5Graphics.arc(), Py5Graphics.triangle(), Py5Graphics.sphere(), Py5Graphics.box(), Py5Graphics.quad(), and Py5Graphics.line().

Custom, unique shapes can be made by using create_shape() without a parameter. After the shape is started, the drawing attributes and geometry can be set directly to the shape within the Py5Graphics.begin_shape() and Py5Graphics.end_shape() methods. See reference for Py5Graphics.begin_shape() for all of its options.

The create_shape() function can also be used to make a complex shape made of other shapes. This is called a “group” and it’s created by using the parameter GROUP as the first parameter.

After using create_shape(), stroke and fill color can be set by calling methods like Py5Shape.set_fill() and Py5Shape.set_stroke(), as seen in the examples. The complete list of methods and fields for the Py5Shape class are in the py5 documentation.

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

Underlying Java method: PGraphics.createShape

Syntax

create_shape() -> Py5Shape
create_shape(kind: int, /, *p: float) -> Py5Shape
create_shape(type: int, /) -> Py5Shape

Parameters

  • kind: int - either POINT, LINE, TRIANGLE, QUAD, RECT, ELLIPSE, ARC, BOX, SPHERE

  • p: float - parameters that match the kind of shape

  • type: int - either GROUP, PATH, or GEOMETRY

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