screen_y()#

Takes a three-dimensional X, Y, Z position and returns the Y value for where it will appear on a (two-dimensional) screen.

Examples#

 1def setup():
 2    py5.size(100, 100, py5.P3D)
 3
 4
 5def draw():
 6    py5.background(204)
 7
 8    x = py5.mouse_x
 9    y = py5.mouse_y
10    z = -100
11
12    # draw "X" at z = -100
13    py5.stroke(255)
14    py5.line(x-10, y-10, z, x+10, y+10, z)
15    py5.line(x+10, y-10, z, x-10, y+10, z)
16
17    # draw gray line at z = 0 and same
18    # y value. notice the parallax
19    py5.stroke(102)
20    py5.line(0, y, 0, py5.width, y, 0)
21
22    # draw black line at z = 0 to match
23    # the y value element drawn at z = -100
24    py5.stroke(0)
25    the_y = py5.screen_y(x, y, z)
26    py5.line(0, the_y, 0, py5.width, the_y, 0)

Description#

Takes a three-dimensional X, Y, Z position and returns the Y value for where it will appear on a (two-dimensional) screen.

Underlying Processing method: screenY

Syntax#

screen_y(x: float, y: float, /) -> float
screen_y(x: float, y: float, z: float, /) -> float

Parameters#

  • x: float - 3D x-coordinate to be mapped

  • y: float - 3D y-coordinate to be mapped

  • z: float - 3D z-coordinate to be mapped

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