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


Processing translate()用法及代碼示例

Processing, translate()用法介紹。

用法

  • translate(x, y)
  • translate(x, y, z)

參數

  • x (float) 左/右翻譯
  • y (float) 上/下翻譯
  • z (float) 向前/向後翻譯

返回

  • void

說明

指定在顯示窗口內置換對象的量。 x 參數指定左/右平移,y 參數指定上/下平移,z 參數指定朝向/遠離屏幕的平移。將此函數與 z 參數一起使用需要使用 P3D 作為參數並結合上例所示的大小。



轉換是累積的,適用於之後發生的所有事情,隨後對函數的調用會累積效果。例如,調用 translate(50, 0) 然後 translate(20, 0)translate(70, 0) 相同。如果在 draw() 中調用 translate() ,則在循環再次開始時將重置轉換。可以使用 pushMatrix()popMatrix() 進一步控製此函數。

例子

size(400, 400);
translate(120, 80);
rect(0, 0, 220, 220);
Image output for example 1
// Translating in 3D requires P3D
// as the parameter to size()
size(400, 400, P3D);
// Translate 30 across, 20 down, and
// 50 back, or "away" from the screen.
translate(120, 80, -200);
rect(0, 0, 220, 220);
Image output for example 2
size(400, 400);
rect(0, 0, 220, 220);  // Draw rect at original 0,0
translate(120, 80);
rect(0, 0, 220, 220);  // Draw rect at new 0,0
translate(56, 56);
rect(0, 0, 220, 220);  // Draw rect at new 0,0
Image output for example 3

相關用法


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