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);

// 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);

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

相關用法
- Processing triangle()用法及代碼示例
- Processing trim()用法及代碼示例
- Processing true用法及代碼示例
- Processing try用法及代碼示例
- Processing texture()用法及代碼示例
- Processing thread()用法及代碼示例
- Processing textSize()用法及代碼示例
- Processing textureMode()用法及代碼示例
- Processing textLeading()用法及代碼示例
- Processing text()用法及代碼示例
- Processing textDescent()用法及代碼示例
- Processing this用法及代碼示例
- Processing textFont()用法及代碼示例
- Processing textAscent()用法及代碼示例
- Processing textAlign()用法及代碼示例
- Processing textMode()用法及代碼示例
- Processing textWidth()用法及代碼示例
- Processing tint()用法及代碼示例
- Processing tan()用法及代碼示例
- Processing textureWrap()用法及代碼示例
- Processing FFT用法及代碼示例
- Processing SawOsc.pan()用法及代碼示例
- Processing FloatDict用法及代碼示例
- Processing FFT.stop()用法及代碼示例
- Processing join()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 translate()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。