[Processing Example]
本範例乍看之下,會像是齒輪不停的冒出,這時候你可能會心想:不停的產生物件,程式不會當掉嗎?
其實循環不停的視覺效果,是透過偏移全體物件達成的假象,因此本範例不會有程式crash的問題。[Processing code] ↓
import saito.objloader.*; OBJModel model; float gear=6; float gear_s=0.1; void setup() { size(600, 300, OPENGL); model=new OBJModel(this, "Gear.obj", TRIANGLES); model.scale(100); model.translateToCenter(); noStroke(); } void keyPressed() { if (key=='a') { gear_s=gear_s*1.1; } else if (key=='s') { gear_s=gear_s/1.1; } } void draw() { gear_s=gear_s*1.1; background(0); lights(); directionalLight(255, 0, 0, -1, 3, -2); directionalLight(125, 155, 0, 1, -3, -2); camera(mouseX, mouseY, 400, 0, 0, 0, 0, 1, 0); recursion(0, 0, 0, gear_s, 10); if (gear_s>0.214) { gear_s=gear_s/2.14; } else if (gear_s<0.0001) { } } void recursion(float e_x, float e_y, float e_z, float s, int i) { pushMatrix(); translate(e_x, e_y, e_z); scale(s); model.draw(); popMatrix(); if (i>0) { recursion(0, e_y/2+gear*s*2, 0, s*2, i-1); } }
[Pd Example]
Pd的範例多加上一個人型的3D 模型,是我個人小小的惡趣味。
沒有留言:
張貼留言