Py5Shape.normal()#

Sets the current normal vector for a Py5Shape object’s vertices.

Examples#

example picture for normal()
 1def setup():
 2    py5.size(100, 100, py5.P3D)
 3    py5.background(0)
 4    py5.directional_light(255, 255, 255, -1, -1, -1)
 5
 6    s1 = py5.create_shape()
 7    s1.begin_shape()
 8    s1.fill(200, 200, 200)
 9    s1.vertex(-20, -20, -25)
10    s1.vertex(20, -20, -25)
11    s1.vertex(20, 20, -25)
12    s1.vertex(-20, 20, -25)
13    s1.end_shape(py5.CLOSE)
14
15    s2 = py5.create_shape()
16    s2.begin_shape()
17    s2.fill(200, 200, 200)
18    s2.normal(-20, -20, 20)
19    s2.vertex(-20, -20, -25)
20    s2.normal(20, -20, 20)
21    s2.vertex(20, -20, -25)
22    s2.normal(20, 20, 20)
23    s2.vertex(20, 20, -25)
24    s2.normal(-20, 20, 20)
25    s2.vertex(-20, 20, -25)
26    s2.end_shape(py5.CLOSE)
27
28    py5.shape(s1, 40, 10)
29    py5.shape(s2, 40, 60)

Description#

Sets the current normal vector for a Py5Shape object’s vertices. Used for drawing three dimensional shapes and surfaces, normal() specifies a vector perpendicular to a shape’s surface which, in turn, determines how lighting affects it. Py5 attempts to automatically assign normals to shapes, but since that’s imperfect, this is a better option when you want more control.

This method can only be used within a Py5Shape.begin_shape() and Py5Shape.end_shape() pair. The normal setting will be applied to vertices added after the call to this method.

Underlying Processing method: PShape.normal

Syntax#

normal(nx: float, ny: float, nz: float, /) -> None

Parameters#

  • nx: float - x direction

  • ny: float - y direction

  • nz: float - z direction

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