moving the OpenGL examples to the core

This commit is contained in:
benfry
2012-07-20 20:24:58 +00:00
parent b30328bb66
commit 40ecd562e3
133 changed files with 0 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
// CameraLight, by Andres Colubri
// Simple example showing a lit rotating cube. The projection
// is set to orthographic if the mouse is pressed.
float spin = 0.0;
void setup() {
size(400, 400, P3D);
noStroke();
}
void draw() {
background(51);
lights();
if (mousePressed) {
ortho(-width/2, width/2, -height/2, height/2);
} else {
float fov = PI/3.0;
float cameraZ = (height/2.0) / tan(fov/2.0);
perspective(fov, float(width)/float(height),
cameraZ/2.0, cameraZ*2.0);
}
spin += 0.01;
pushMatrix();
translate(width/2, height/2, 0);
rotateX(PI/9);
rotateY(PI/5 + spin);
box(100);
popMatrix();
}
+28
View File
@@ -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);
}
+29
View File
@@ -0,0 +1,29 @@
/**
* Lights 1.
*
* Uses the default lights to show a simple box. The lights() function
* is used to turn on the default lighting.
*/
float spin = 0.0;
void setup()
{
size(640, 360, P3D);
noStroke();
}
void draw()
{
background(51);
lights();
spin += 0.01;
pushMatrix();
translate(width/2, height/2, 0);
rotateX(PI/9);
rotateY(PI/5 + spin);
box(150);
popMatrix();
}
+36
View File
@@ -0,0 +1,36 @@
/**
* Lights 2
* 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);
}
+45
View File
@@ -0,0 +1,45 @@
/**
* LightsGL.
* Modified from an example by Simon Greenwold.
*
* Display a box with three different kinds of lights.
*/
void setup()
{
size(1024, 768, P3D);
noStroke();
}
void draw()
{
defineLights();
background(0);
for (int x = 0; x <= width; x += 100) {
for (int y = 0; y <= height; y += 100) {
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
}
+25
View File
@@ -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);
}
+35
View File
@@ -0,0 +1,35 @@
/**
* 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(200, 200, P3D);
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);
}