Initial Commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Directional.
|
||||
*
|
||||
* Move the mouse the change the direction of the light.
|
||||
* Directional light comes from one direction and is stronger
|
||||
* when hitting a surface squarely and weaker if it hits at a
|
||||
* a gentle angle. After hitting a surface, a directional lights
|
||||
* scatters in all directions.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
noStroke();
|
||||
background(0);
|
||||
float dirY = (mouseY / float(height) - 0.5) * 2;
|
||||
float dirX = (mouseX / float(width) - 0.5) * 2;
|
||||
directionalLight(204, 204, 204, -dirX, -dirY, -1);
|
||||
translate(width/2 - 100, height/2, 0);
|
||||
sphere(80);
|
||||
translate(200, 0, 0);
|
||||
sphere(80);
|
||||
}
|
||||
|
||||
@@ -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,43 @@
|
||||
/**
|
||||
* Mixture Grid
|
||||
* modified from an example by Simon Greenwold.
|
||||
*
|
||||
* Display a 2D grid of boxes with three different kinds of lights.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
defineLights();
|
||||
background(0);
|
||||
|
||||
for (int x = 0; x <= width; x += 60) {
|
||||
for (int y = 0; y <= height; y += 60) {
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
rotateY(map(mouseX, 0, width, 0, PI));
|
||||
rotateX(map(mouseY, 0, height, 0, PI));
|
||||
box(90);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void defineLights() {
|
||||
// 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
|
||||
}
|
||||
@@ -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,25 @@
|
||||
/**
|
||||
* Reflection
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* Vary the specular reflection component of a material
|
||||
* with the horizontal position of the mouse.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
colorMode(RGB, 1);
|
||||
fill(0.4);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
// Set the specular color of lights that follow
|
||||
lightSpecular(1, 1, 1);
|
||||
directionalLight(0.8, 0.8, 0.8, 0, 0, -1);
|
||||
float s = mouseX / float(width);
|
||||
specular(s, s, s);
|
||||
sphere(120);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Spot.
|
||||
*
|
||||
* Move the mouse the change the position and concentation
|
||||
* of a blue spot light.
|
||||
*/
|
||||
|
||||
int concentration = 600; // Try values 1 -> 10000
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
sphereDetail(60);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
// Light the bottom of the sphere
|
||||
directionalLight(51, 102, 126, 0, -1, 0);
|
||||
|
||||
// Orange light on the upper-right of the sphere
|
||||
spotLight(204, 153, 0, 360, 160, 600, 0, 0, -1, PI/2, 600);
|
||||
|
||||
// Moving spotlight that follows the mouse
|
||||
spotLight(102, 153, 204, 360, mouseY, 600, 0, 0, -1, PI/2, 600);
|
||||
|
||||
translate(width/2, height/2, 0);
|
||||
sphere(120);
|
||||
}
|
||||
Reference in New Issue
Block a user