mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
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,48 @@
|
||||
import processing.core.*;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Directional extends PApplet {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
noStroke();
|
||||
background(0);
|
||||
float dirY = (mouseY / PApplet.parseFloat(height) - 0.5f) * 2;
|
||||
float dirX = (mouseX / PApplet.parseFloat(width) - 0.5f) * 2;
|
||||
directionalLight(204, 204, 204, -dirX, -dirY, -1);
|
||||
translate(width/2 - 100, height/2, 0);
|
||||
sphere(80);
|
||||
translate(200, 0, 0);
|
||||
sphere(80);
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Directional" });
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -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();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import processing.core.*;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Lights1 extends PApplet {
|
||||
|
||||
/**
|
||||
* 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.0f;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(51);
|
||||
lights();
|
||||
|
||||
spin += 0.01f;
|
||||
|
||||
pushMatrix();
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(PI/9);
|
||||
rotateY(PI/5 + spin);
|
||||
box(150);
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Lights1" });
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import processing.core.*;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Lights2 extends PApplet {
|
||||
|
||||
/**
|
||||
* Lights 2
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* Display a box with three different kinds of lights.
|
||||
*/
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
public 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.5f, -0.5f, // Direction
|
||||
PI / 2, 2); // Angle, concentration
|
||||
|
||||
rotateY(map(mouseX, 0, width, 0, PI));
|
||||
rotateX(map(mouseY, 0, height, 0, PI));
|
||||
box(150);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Lights2" });
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -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,45 @@
|
||||
import processing.core.*;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Reflection extends PApplet {
|
||||
|
||||
/**
|
||||
* Reflection
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* Vary the specular reflection component of a material
|
||||
* with the horizontal position of the mouse.
|
||||
*/
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
colorMode(RGB, 1);
|
||||
fill(0.4f);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
// Set the specular color of lights that follow
|
||||
lightSpecular(1, 1, 1);
|
||||
directionalLight(0.8f, 0.8f, 0.8f, 0, 0, -1);
|
||||
float s = mouseX / PApplet.parseFloat(width);
|
||||
specular(s, s, s);
|
||||
sphere(120);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Reflection" });
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import processing.core.*;
|
||||
|
||||
import java.applet.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Spot extends PApplet {
|
||||
|
||||
/**
|
||||
* Spot.
|
||||
*
|
||||
* Move the mouse the change the position and concentation
|
||||
* of a blue spot light.
|
||||
*/
|
||||
|
||||
int concentration = 600; // Try values 1 -> 10000
|
||||
|
||||
public void setup()
|
||||
{
|
||||
//size(200, 200, P3D);
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
sphereDetail(60);
|
||||
}
|
||||
|
||||
public 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);
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Spot" });
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Reference in New Issue
Block a user