當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing screenY()用法及代碼示例

Processing, screenY()用法介紹。

用法

  • screenY(x, y)
  • screenY(x, y, z)

參數

  • x (float) 要映射的 3D x 坐標
  • y (float) 要映射的 3D y 坐標
  • z (float) 要映射的 3D z 坐標

返回

  • float

說明

獲取一個三維 X、Y、Z 位置並返回它將出現在(二維)屏幕上的位置的 Y 值。

例子

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 
  // y value. Notice the parallax
  stroke(102);
  line(0, y, 0, width, y, 0);
  
  // Draw black line at z = 0 to match 
  // the y value element drawn at z = -100 
  stroke(0);
  float theY = screenY(x, y, z);
  line(0, theY, 0, width, theY, 0);    
}  

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 screenY()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。