Adding four elusive examples for 2.0

This commit is contained in:
Casey Reas
2011-09-23 04:30:49 +00:00
parent 761dc861a2
commit 40a75b2bbe
4 changed files with 147 additions and 0 deletions
@@ -0,0 +1,34 @@
/**
* Mixture
* by Simon Greenwold.
*
* Display a box with three different kinds of lights.
*/
void setup() {
size(640, 360, P3D);
noStroke();
}
void draw() {
background(0);
translate(width / 2, height / 2);
// Orange point light on the right
pointLight(150, 100, 0, // Color
200, -150, 0); // Position
// Blue directional light from the left
directionalLight(0, 102, 255, // Color
1, 0, 0); // The x-, y-, z-axis direction
// Yellow spotlight from the front
spotLight(255, 255, 109, // Color
0, 40, 200, // Position
0, -0.5, -0.5, // Direction
PI / 2, 2); // Angle, concentration
rotateY(map(mouseX, 0, width, 0, PI));
rotateX(map(mouseY, 0, height, 0, PI));
box(150);
}
@@ -0,0 +1,31 @@
/**
* On/Off.
*
* Uses the default lights to show a simple box. The lights() function
* is used to turn on the default lighting. Click the mouse to turn the
* lights off.
*/
float spin = 0.0;
void setup() {
size(640, 360, P3D);
noStroke();
}
void draw() {
background(51);
if (!mousePressed) {
lights();
}
spin += 0.01;
pushMatrix();
translate(width/2, height/2, 0);
rotateX(PI/9);
rotateY(PI/5 + spin);
box(150);
popMatrix();
}
@@ -0,0 +1,42 @@
/**
* Rotate Push Pop.
*
* The push() and pop() functions allow for more control over transformations.
* The push function saves the current coordinate system to the stack
* and pop() restores the prior coordinate system.
*/
float a; // Angle of rotation
float offset = PI/24.0; // Angle offset between boxes
int num = 12; // Number of boxes
color[] colors = new color[num]; // Colors of each box
color safecolor;
boolean pink = true;
void setup()
{
size(640, 360, P3D);
noStroke();
for(int i=0; i<num; i++) {
colors[i] = color(255 * (i+1)/num);
}
lights();
}
void draw()
{
background(0, 0, 26);
translate(width/2, height/2);
a += 0.01;
for(int i = 0; i < num; i++) {
pushMatrix();
fill(colors[i]);
rotateY(a + offset*i);
rotateX(a/2 + offset*i);
box(200);
popMatrix();
}
}
@@ -0,0 +1,40 @@
/**
* Rotate 1.
*
* Rotating simultaneously in the X and Y axis.
* Transformation functions such as rotate() are additive.
* Successively calling rotate(1.0) and rotate(2.0)
* is equivalent to calling rotate(3.0).
*/
float a = 0.0;
float rSize; // rectangle size
void setup() {
size(640, 360, P3D);
rSize = width / 6;
noStroke();
fill(204, 204);
}
void draw() {
background(126);
a += 0.005;
if(a > TWO_PI) {
a = 0.0;
}
translate(width/2, height/2);
rotateX(a);
rotateY(a * 2.0);
fill(255);
rect(-rSize, -rSize, rSize*2, rSize*2);
rotateX(a * 1.001);
rotateY(a * 2.002);
fill(0);
rect(-rSize, -rSize, rSize*2, rSize*2);
}