screen_x()

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def setup():
    py5.size(100, 100, py5.P3D)


def draw():
    py5.background(204)

    x = py5.mouse_x
    y = py5.mouse_y
    z = -100

    # draw "X" at z = -100
    py5.stroke(255)
    py5.line(x-10, y-10, z, x+10, y+10, z)
    py5.line(x+10, y-10, z, x-10, y+10, z)

    # draw gray line at z = 0 and same
    # x value. notice the parallax
    py5.stroke(102)
    py5.line(x, 0, 0, x, py5.height, 0)

    # draw black line at z = 0 to match
    # the x value element drawn at z = -100
    py5.stroke(0)
    the_x = py5.screen_x(x, y, z)
    py5.line(the_x, 0, 0, the_x, py5.height, 0)

Description

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

Underlying Java method: screenX

Syntax

screen_x(x: float, y: float, /) -> float
screen_x(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 September 11, 2021 16:51:34pm UTC