This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Name

screenX()

Examples
void setup() {
  size(100, 100, P3D);
}

void draw() {
  background(204);
  
  float x = mouseX;
  float y = mouseY;
  float z = -100;
  
  // Draw "X" at z = -100
  stroke(255);
  line(x-10, y-10, z, x+10, y+10, z); 
  line(x+10, y-10, z, x-10, y+10, z); 
  
  // Draw gray line at z = 0 and same 
  // x value. Notice the parallax
  stroke(102);
  line(x, 0, 0, x, height, 0);
  
  // Draw black line at z = 0 to match 
  // the x value element drawn at z = -100 
  stroke(0);
  float theX = screenX(x, y, z);
  line(theX, 0, 0, theX, 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.
Syntax
screenX(x, y)
screenX(x, y, z)
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
Returnsfloat
RelatedscreenY()
screenZ()
Updated on August 17, 2018 03:36:32pm EDT

Creative Commons License