FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

New examples for 2.0 · ereyes/processing@727b363 · GitHub

Repository navigation

Commit 727b363

Browse files
committed
New examples for 2.0
1 parent 11f0f14 commit 727b363

8 files changed

Lines changed: 222 additions & 43 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Move Eye.
3+
* by Simon Greenwold.
4+
*
5+
* The camera lifts up (controlled by mouseY) while looking at the same point.
6+
*/
7+
8+
void setup() {
9+
size(640, 360, P3D);
10+
fill(204);
11+
}
12+
13+
void draw() {
14+
lights();
15+
background(0);
16+
17+
// Change height of the camera with mouseY
18+
camera(30.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
19+
0.0, 0.0, 0.0, // centerX, centerY, centerZ
20+
0.0, 1.0, 0.0); // upX, upY, upZ
21+
22+
noStroke();
23+
box(90);
24+
stroke(255);
25+
line(-100, 0, 0, 100, 0, 0);
26+
line(0, -100, 0, 0, 100, 0);
27+
line(0, 0, -100, 0, 0, 100);
28+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Perspective.
3+
*
4+
* Move the mouse left and right to change the field of view (fov).
5+
* Click to modify the aspect ratio. The perspective() function
6+
* sets a perspective projection applying foreshortening, making
7+
* distant objects appear smaller than closer ones. The parameters
8+
* define a viewing volume with the shape of truncated pyramid.
9+
* Objects near to the front of the volume appear their actual size,
10+
* while farther objects appear smaller. This projection simulates
11+
* the perspective of the world more accurately than orthographic projection.
12+
* The version of perspective without parameters sets the default
13+
* perspective and the version with four parameters allows the programmer
14+
* to set the area precisely.
15+
*/
16+
17+
void setup() {
18+
size(640, 360, P3D);
19+
noStroke();
20+
}
21+
22+
void draw() {
23+
lights();
24+
background(204);
25+
float cameraY = height/2.0;
26+
float fov = mouseX/float(width) * PI/2;
27+
float cameraZ = cameraY / tan(fov / 2.0);
28+
float aspect = float(width)/float(height);
29+
if (mousePressed) {
30+
aspect = aspect / 2.0;
31+
}
32+
perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
33+
34+
translate(width/2+30, height/2, 0);
35+
rotateX(-PI/6);
36+
rotateY(PI/3 + mouseY/float(height) * PI);
37+
box(45);
38+
translate(0, 0, -50);
39+
box(30);
40+
}
41+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Directional.
3+
*
4+
* Move the mouse the change the direction of the light.
5+
* Directional light comes from one direction and is stronger
6+
* when hitting a surface squarely and weaker if it hits at a
7+
* a gentle angle. After hitting a surface, a directional lights
8+
* scatters in all directions.
9+
*/
10+
11+
void setup() {
12+
size(640, 360, P3D);
13+
noStroke();
14+
fill(204);
15+
}
16+
17+
void draw() {
18+
noStroke();
19+
background(0);
20+
float dirY = (mouseY / float(height) - 0.5) * 2;
21+
float dirX = (mouseX / float(width) - 0.5) * 2;
22+
directionalLight(204, 204, 204, -dirX, -dirY, -1);
23+
translate(width/2 - 100, height/2, 0);
24+
sphere(80);
25+
translate(200, 0, 0);
26+
sphere(80);
27+
}
28+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Lights 1.
3+
*
4+
* Uses the default lights to show a simple box. The lights() function
5+
* is used to turn on the default lighting.
6+
*/
7+
8+
float spin = 0.0;
9+
10+
void setup()
11+
{
12+
size(640, 360, P3D);
13+
noStroke();
14+
}
15+
16+
void draw()
17+
{
18+
background(51);
19+
lights();
20+
21+
spin += 0.01;
22+
23+
pushMatrix();
24+
translate(width/2, height/2, 0);
25+
rotateX(PI/9);
26+
rotateY(PI/5 + spin);
27+
box(150);
28+
popMatrix();
29+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Lights 2
3+
* by Simon Greenwold.
4+
*
5+
* Display a box with three different kinds of lights.
6+
*/
7+
8+
void setup()
9+
{
10+
size(640, 360, P3D);
11+
noStroke();
12+
}
13+
14+
void draw()
15+
{
16+
background(0);
17+
translate(width / 2, height / 2);
18+
19+
// Orange point light on the right
20+
pointLight(150, 100, 0, // Color
21+
200, -150, 0); // Position
22+
23+
// Blue directional light from the left
24+
directionalLight(0, 102, 255, // Color
25+
1, 0, 0); // The x-, y-, z-axis direction
26+
27+
// Yellow spotlight from the front
28+
spotLight(255, 255, 109, // Color
29+
0, 40, 200, // Position
30+
0, -0.5, -0.5, // Direction
31+
PI / 2, 2); // Angle, concentration
32+
33+
rotateY(map(mouseX, 0, width, 0, PI));
34+
rotateX(map(mouseY, 0, height, 0, PI));
35+
box(150);
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Reflection
3+
* by Simon Greenwold.
4+
*
5+
* Vary the specular reflection component of a material
6+
* with the horizontal position of the mouse.
7+
*/
8+
9+
void setup() {
10+
size(640, 360, P3D);
11+
noStroke();
12+
colorMode(RGB, 1);
13+
fill(0.4);
14+
}
15+
16+
void draw() {
17+
background(0);
18+
translate(width / 2, height / 2);
19+
// Set the specular color of lights that follow
20+
lightSpecular(1, 1, 1);
21+
directionalLight(0.8, 0.8, 0.8, 0, 0, -1);
22+
float s = mouseX / float(width);
23+
specular(s, s, s);
24+
sphere(120);
25+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Spot.
3+
*
4+
* Move the mouse the change the position and concentation
5+
* of a blue spot light.
6+
*/
7+
8+
int concentration = 600; // Try values 1 -> 10000
9+
10+
void setup()
11+
{
12+
//size(200, 200, P3D);
13+
size(640, 360, P3D);
14+
noStroke();
15+
fill(204);
16+
sphereDetail(60);
17+
}
18+
19+
void draw()
20+
{
21+
background(0);
22+
23+
// Light the bottom of the sphere
24+
directionalLight(51, 102, 126, 0, -1, 0);
25+
26+
// Orange light on the upper-right of the sphere
27+
spotLight(204, 153, 0, 360, 160, 600, 0, 0, -1, PI/2, 600);
28+
29+
// Moving spotlight that follows the mouse
30+
spotLight(102, 153, 204, 360, mouseY, 600, 0, 0, -1, PI/2, 600);
31+
32+
translate(width/2, height/2, 0);
33+
sphere(120);
34+
}
35+

‎java/examples/Basics/Transform/TriangleFlower/TriangleFlower.pde‎

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL