22. translation & rotation i
DESCRIPTION
TRANSCRIPT
From last time…• Solar System (with 2 constructors)!
• Using sin() on size, color, and position!
• Using Perlin noise() in 2 and 3 dimensions!
• Let’s talk about recursion…
Recursion• A method which calls itself…
myMethod() { doSomething(); }
doSomething() { print(“Hey!”); }
myMethod() { myMethod(); }
myMethod() { myMethod(); }
myMethod() { myMethod(); }
myMethod() { myMethod(); }
An infinite loop. FOREVER.! This is bad.
Recursion• Therefore you must provide an exit condition!
• “I’m going to keep calling myself until I reach my exit condition.”!
• This is similar to while and for loops!
• Demo: Recursive Square
CAP 3032
Translation &!Rotation I
The Z Axis
+ x– x
+ y
– y
+ z
– z
translate()• translate() shifts the origin of our sketch
temporarily–for the current draw loop!
• Use P3D or OPENGL rendering:!
! size(500, 500, P3D);
• Tell it how far you want to move the origin:!
translate(moveX, moveY, moveZ);
Demo!Translate
Vertex Shapes• To draw arbitrary shapes, use three methods:!
beginShape();
// POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, or QUAD_STRIP
vertex(); OR curveVertex();
endShape(); OR endShape(CLOSE);
Demo!Trapezoid
Vertex Shapes
In 3D!In 3D!• Basically the same method, but compose a 3D
volume out of component shapes in 3D space!
• For example, a cube would be 6 squares placed in 3D space
Demo!Top of the Pyramid
‘Simple’ Rotation
• Rotating using the rotation(); method!
• Processing rotates around the point of origin!
• But the point of origin can move with the translate() method…
Demo!Pyramid Rotation
For next time…
• Iteration 2: present on Monday!!
• Shiffman, p. 239–252 (Translation/Rotation II)!
• Homework 4: moved until after Iteration 2