28
java/examples/3D/Camera/MoveEye/MoveEye.pde
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Move Eye.
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* The camera lifts up (controlled by mouseY) while looking at the same point.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
background(0);
|
||||
|
||||
// Change height of the camera with mouseY
|
||||
camera(30.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
|
||||
0.0, 0.0, 0.0, // centerX, centerY, centerZ
|
||||
0.0, 1.0, 0.0); // upX, upY, upZ
|
||||
|
||||
noStroke();
|
||||
box(90);
|
||||
stroke(255);
|
||||
line(-100, 0, 0, 100, 0, 0);
|
||||
line(0, -100, 0, 0, 100, 0);
|
||||
line(0, 0, -100, 0, 0, 100);
|
||||
}
|
||||
48
java/examples/3D/Camera/MoveEye/applet/MoveEye.java
Normal file
@@ -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 MoveEye extends PApplet {
|
||||
|
||||
/**
|
||||
* Move Eye.
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* The camera lifts up (controlled by mouseY) while looking at the same point.
|
||||
*/
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
fill(204);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
lights();
|
||||
background(0);
|
||||
|
||||
// Change height of the camera with mouseY
|
||||
camera(30.0f, mouseY, 220.0f, // eyeX, eyeY, eyeZ
|
||||
0.0f, 0.0f, 0.0f, // centerX, centerY, centerZ
|
||||
0.0f, 1.0f, 0.0f); // upX, upY, upZ
|
||||
|
||||
noStroke();
|
||||
box(90);
|
||||
stroke(255);
|
||||
line(-100, 0, 0, 100, 0, 0);
|
||||
line(0, -100, 0, 0, 100, 0);
|
||||
line(0, 0, -100, 0, 0, 100);
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "MoveEye" });
|
||||
}
|
||||
}
|
||||
28
java/examples/3D/Camera/MoveEye/applet/MoveEye.pde
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Move Eye.
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* The camera lifts up (controlled by mouseY) while looking at the same point.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
background(0);
|
||||
|
||||
// Change height of the camera with mouseY
|
||||
camera(30.0, mouseY, 220.0, // eyeX, eyeY, eyeZ
|
||||
0.0, 0.0, 0.0, // centerX, centerY, centerZ
|
||||
0.0, 1.0, 0.0); // upX, upY, upZ
|
||||
|
||||
noStroke();
|
||||
box(90);
|
||||
stroke(255);
|
||||
line(-100, 0, 0, 100, 0, 0);
|
||||
line(0, -100, 0, 0, 100, 0);
|
||||
line(0, 0, -100, 0, 0, 100);
|
||||
}
|
||||
BIN
java/examples/3D/Camera/MoveEye/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Ortho vs Perspective.
|
||||
*
|
||||
* Click to see the difference between orthographic projection
|
||||
* and perspective projection as applied to a simple box.
|
||||
* The ortho() function sets an orthographic projection and
|
||||
* defines a parallel clipping volume. All objects with the
|
||||
* same dimension appear the same size, regardless of whether
|
||||
* they are near or far from the camera. The parameters to this
|
||||
* function specify the clipping volume where left and right
|
||||
* are the minimum and maximum x values, top and bottom are the
|
||||
* minimum and maximum y values, and near and far are the minimum
|
||||
* and maximum z values.
|
||||
*/
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
if(mousePressed) {
|
||||
float fov = PI/3.0;
|
||||
float cameraZ = (height/2.0) / tan(PI * fov / 360.0);
|
||||
perspective(fov, float(width)/float(height),
|
||||
cameraZ/2.0, cameraZ*2.0);
|
||||
} else {
|
||||
ortho(-width/2, width/2, -height/2, height/2, -10, 10);
|
||||
}
|
||||
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3);
|
||||
box(160);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
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 OrthoVSPerspective extends PApplet {
|
||||
|
||||
/**
|
||||
* Ortho vs Perspective.
|
||||
*
|
||||
* Click to see the difference between orthographic projection
|
||||
* and perspective projection as applied to a simple box.
|
||||
* The ortho() function sets an orthographic projection and
|
||||
* defines a parallel clipping volume. All objects with the
|
||||
* same dimension appear the same size, regardless of whether
|
||||
* they are near or far from the camera. The parameters to this
|
||||
* function specify the clipping volume where left and right
|
||||
* are the minimum and maximum x values, top and bottom are the
|
||||
* minimum and maximum y values, and near and far are the minimum
|
||||
* and maximum z values.
|
||||
*/
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
if(mousePressed) {
|
||||
float fov = PI/3.0f;
|
||||
float cameraZ = (height/2.0f) / tan(PI * fov / 360.0f);
|
||||
perspective(fov, PApplet.parseFloat(width)/PApplet.parseFloat(height),
|
||||
cameraZ/2.0f, cameraZ*2.0f);
|
||||
} else {
|
||||
ortho(-width/2, width/2, -height/2, height/2, -10, 10);
|
||||
}
|
||||
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3);
|
||||
box(160);
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "OrthoVSPerspective" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Ortho vs Perspective.
|
||||
*
|
||||
* Click to see the difference between orthographic projection
|
||||
* and perspective projection as applied to a simple box.
|
||||
* The ortho() function sets an orthographic projection and
|
||||
* defines a parallel clipping volume. All objects with the
|
||||
* same dimension appear the same size, regardless of whether
|
||||
* they are near or far from the camera. The parameters to this
|
||||
* function specify the clipping volume where left and right
|
||||
* are the minimum and maximum x values, top and bottom are the
|
||||
* minimum and maximum y values, and near and far are the minimum
|
||||
* and maximum z values.
|
||||
*/
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
if(mousePressed) {
|
||||
float fov = PI/3.0;
|
||||
float cameraZ = (height/2.0) / tan(PI * fov / 360.0);
|
||||
perspective(fov, float(width)/float(height),
|
||||
cameraZ/2.0, cameraZ*2.0);
|
||||
} else {
|
||||
ortho(-width/2, width/2, -height/2, height/2, -10, 10);
|
||||
}
|
||||
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3);
|
||||
box(160);
|
||||
}
|
||||
|
||||
BIN
java/examples/3D/Camera/OrthoVSPerspective/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
41
java/examples/3D/Camera/Perspective/Perspective.pde
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Perspective.
|
||||
*
|
||||
* Move the mouse left and right to change the field of view (fov).
|
||||
* Click to modify the aspect ratio. The perspective() function
|
||||
* sets a perspective projection applying foreshortening, making
|
||||
* distant objects appear smaller than closer ones. The parameters
|
||||
* define a viewing volume with the shape of truncated pyramid.
|
||||
* Objects near to the front of the volume appear their actual size,
|
||||
* while farther objects appear smaller. This projection simulates
|
||||
* the perspective of the world more accurately than orthographic projection.
|
||||
* The version of perspective without parameters sets the default
|
||||
* perspective and the version with four parameters allows the programmer
|
||||
* to set the area precisely.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
background(204);
|
||||
float cameraY = height/2.0;
|
||||
float fov = mouseX/float(width) * PI/2;
|
||||
float cameraZ = cameraY / tan(fov / 2.0);
|
||||
float aspect = float(width)/float(height);
|
||||
if (mousePressed) {
|
||||
aspect = aspect / 2.0;
|
||||
}
|
||||
perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
|
||||
|
||||
translate(width/2+30, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3 + mouseY/float(height) * PI);
|
||||
box(45);
|
||||
translate(0, 0, -50);
|
||||
box(30);
|
||||
}
|
||||
|
||||
61
java/examples/3D/Camera/Perspective/applet/Perspective.java
Normal file
@@ -0,0 +1,61 @@
|
||||
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 Perspective extends PApplet {
|
||||
|
||||
/**
|
||||
* Perspective.
|
||||
*
|
||||
* Move the mouse left and right to change the field of view (fov).
|
||||
* Click to modify the aspect ratio. The perspective() function
|
||||
* sets a perspective projection applying foreshortening, making
|
||||
* distant objects appear smaller than closer ones. The parameters
|
||||
* define a viewing volume with the shape of truncated pyramid.
|
||||
* Objects near to the front of the volume appear their actual size,
|
||||
* while farther objects appear smaller. This projection simulates
|
||||
* the perspective of the world more accurately than orthographic projection.
|
||||
* The version of perspective without parameters sets the default
|
||||
* perspective and the version with four parameters allows the programmer
|
||||
* to set the area precisely.
|
||||
*/
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
lights();
|
||||
background(204);
|
||||
float cameraY = height/2.0f;
|
||||
float fov = mouseX/PApplet.parseFloat(width) * PI/2;
|
||||
float cameraZ = cameraY / tan(fov / 2.0f);
|
||||
float aspect = PApplet.parseFloat(width)/PApplet.parseFloat(height);
|
||||
if (mousePressed) {
|
||||
aspect = aspect / 2.0f;
|
||||
}
|
||||
perspective(fov, aspect, cameraZ/10.0f, cameraZ*10.0f);
|
||||
|
||||
translate(width/2+30, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3 + mouseY/PApplet.parseFloat(height) * PI);
|
||||
box(45);
|
||||
translate(0, 0, -50);
|
||||
box(30);
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Perspective" });
|
||||
}
|
||||
}
|
||||
41
java/examples/3D/Camera/Perspective/applet/Perspective.pde
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Perspective.
|
||||
*
|
||||
* Move the mouse left and right to change the field of view (fov).
|
||||
* Click to modify the aspect ratio. The perspective() function
|
||||
* sets a perspective projection applying foreshortening, making
|
||||
* distant objects appear smaller than closer ones. The parameters
|
||||
* define a viewing volume with the shape of truncated pyramid.
|
||||
* Objects near to the front of the volume appear their actual size,
|
||||
* while farther objects appear smaller. This projection simulates
|
||||
* the perspective of the world more accurately than orthographic projection.
|
||||
* The version of perspective without parameters sets the default
|
||||
* perspective and the version with four parameters allows the programmer
|
||||
* to set the area precisely.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
lights();
|
||||
background(204);
|
||||
float cameraY = height/2.0;
|
||||
float fov = mouseX/float(width) * PI/2;
|
||||
float cameraZ = cameraY / tan(fov / 2.0);
|
||||
float aspect = float(width)/float(height);
|
||||
if (mousePressed) {
|
||||
aspect = aspect / 2.0;
|
||||
}
|
||||
perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
|
||||
|
||||
translate(width/2+30, height/2, 0);
|
||||
rotateX(-PI/6);
|
||||
rotateY(PI/3 + mouseY/float(height) * PI);
|
||||
box(45);
|
||||
translate(0, 0, -50);
|
||||
box(30);
|
||||
}
|
||||
|
||||
BIN
java/examples/3D/Camera/Perspective/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
59
java/examples/3D/Form/BrickTower/BrickTower.pde
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Brick Tower
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* 3D castle tower constructed out of individual bricks.
|
||||
* Uses the PVector and Cube classes.
|
||||
*/
|
||||
|
||||
float bricksPerLayer = 16.0;
|
||||
float brickLayers = 18.0;
|
||||
Cube brick;
|
||||
float brickWidth = 60, brickHeight = 25, brickDepth = 25;
|
||||
float radius = 175.0;
|
||||
float angle = 0;
|
||||
|
||||
void setup(){
|
||||
size(640, 360, P3D);
|
||||
brick = new Cube(brickWidth, brickHeight, brickDepth);
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(0);
|
||||
float tempX = 0, tempY = 0, tempZ = 0;
|
||||
fill(182, 62, 29);
|
||||
noStroke();
|
||||
// Add basic light setup
|
||||
lights();
|
||||
translate(width/2, height*1.2, -380);
|
||||
// Tip tower to see inside
|
||||
rotateX(radians(-45));
|
||||
// Slowly rotate tower
|
||||
rotateY(frameCount * PI/600);
|
||||
for (int i = 0; i < brickLayers; i++){
|
||||
// Increment rows
|
||||
tempY-=brickHeight;
|
||||
// Alternate brick seams
|
||||
angle = 360.0 / bricksPerLayer * i/2;
|
||||
for (int j = 0; j < bricksPerLayer; j++){
|
||||
tempZ = cos(radians(angle))*radius;
|
||||
tempX = sin(radians(angle))*radius;
|
||||
pushMatrix();
|
||||
translate(tempX, tempY, tempZ);
|
||||
rotateY(radians(angle));
|
||||
// Add crenelation
|
||||
if (i==brickLayers-1){
|
||||
if (j%2 == 0){
|
||||
brick.create();
|
||||
}
|
||||
}
|
||||
// Create main tower
|
||||
else {
|
||||
brick.create();
|
||||
}
|
||||
popMatrix();
|
||||
angle += 360.0/bricksPerLayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
60
java/examples/3D/Form/BrickTower/Cube.pde
Normal file
@@ -0,0 +1,60 @@
|
||||
class Cube {
|
||||
|
||||
PVector[] vertices = new PVector[24];
|
||||
float w, h, d;
|
||||
|
||||
Cube(){ }
|
||||
|
||||
Cube(float w, float h, float d){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
|
||||
// Cube composed of 6 quads
|
||||
// Front
|
||||
vertices[0] = new PVector(-w/2, -h/2, d/2);
|
||||
vertices[1] = new PVector(w/2, -h/2, d/2);
|
||||
vertices[2] = new PVector(w/2, h/2, d/2);
|
||||
vertices[3] = new PVector(-w/2, h/2, d/2);
|
||||
|
||||
// Left
|
||||
vertices[4] = new PVector(-w/2, -h/2, d/2);
|
||||
vertices[5] = new PVector(-w/2, -h/2, -d/2);
|
||||
vertices[6] = new PVector(-w/2, h/2, -d/2);
|
||||
vertices[7] = new PVector(-w/2, h/2, d/2);
|
||||
|
||||
// Right
|
||||
vertices[8] = new PVector(w/2, -h/2, d/2);
|
||||
vertices[9] = new PVector(w/2, -h/2, -d/2);
|
||||
vertices[10] = new PVector(w/2, h/2, -d/2);
|
||||
vertices[11] = new PVector(w/2, h/2, d/2);
|
||||
|
||||
// Back
|
||||
vertices[12] = new PVector(-w/2, -h/2, -d/2);
|
||||
vertices[13] = new PVector(w/2, -h/2, -d/2);
|
||||
vertices[14] = new PVector(w/2, h/2, -d/2);
|
||||
vertices[15] = new PVector(-w/2, h/2, -d/2);
|
||||
|
||||
// Top
|
||||
vertices[16] = new PVector(-w/2, -h/2, d/2);
|
||||
vertices[17] = new PVector(-w/2, -h/2, -d/2);
|
||||
vertices[18] = new PVector(w/2, -h/2, -d/2);
|
||||
vertices[19] = new PVector(w/2, -h/2, d/2);
|
||||
|
||||
// Bottom
|
||||
vertices[20] = new PVector(-w/2, h/2, d/2);
|
||||
vertices[21] = new PVector(-w/2, h/2, -d/2);
|
||||
vertices[22] = new PVector(w/2, h/2, -d/2);
|
||||
vertices[23] = new PVector(w/2, h/2, d/2);
|
||||
}
|
||||
|
||||
void create(){
|
||||
for (int i=0; i<6; i++){
|
||||
beginShape(QUADS);
|
||||
for (int j = 0; j < 4; j++){
|
||||
vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z);
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
152
java/examples/3D/Form/BrickTower/applet/BrickTower.java
Normal file
@@ -0,0 +1,152 @@
|
||||
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 BrickTower extends PApplet {
|
||||
|
||||
/**
|
||||
* Brick Tower
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* 3D castle tower constructed out of individual bricks.
|
||||
* Uses the Point3D and Cube classes.
|
||||
*/
|
||||
|
||||
|
||||
float bricksPerLayer = 16.0f;
|
||||
float brickLayers = 18.0f;
|
||||
Cube brick;
|
||||
float brickWidth = 60, brickHeight = 25, brickDepth = 25;
|
||||
float radius = 175.0f;
|
||||
float angle = 0;
|
||||
|
||||
public void setup(){
|
||||
size(640, 360, P3D);
|
||||
brick = new Cube(brickWidth, brickHeight, brickDepth);
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
background(0);
|
||||
float tempX = 0, tempY = 0, tempZ = 0;
|
||||
fill(182, 62, 29);
|
||||
noStroke();
|
||||
// Add basic light setup
|
||||
lights();
|
||||
translate(width/2, height*1.2f, -380);
|
||||
// Tip tower to see inside
|
||||
rotateX(radians(-45));
|
||||
// Slowly rotate tower
|
||||
rotateY(frameCount * PI/600);
|
||||
for (int i = 0; i < brickLayers; i++){
|
||||
// Increment rows
|
||||
tempY-=brickHeight;
|
||||
// Alternate brick seams
|
||||
angle = 360.0f / bricksPerLayer * i/2;
|
||||
for (int j = 0; j < bricksPerLayer; j++){
|
||||
tempZ = cos(radians(angle))*radius;
|
||||
tempX = sin(radians(angle))*radius;
|
||||
pushMatrix();
|
||||
translate(tempX, tempY, tempZ);
|
||||
rotateY(radians(angle));
|
||||
// Add crenelation
|
||||
if (i==brickLayers-1){
|
||||
if (j%2 == 0){
|
||||
brick.create();
|
||||
}
|
||||
}
|
||||
// Create main tower
|
||||
else {
|
||||
brick.create();
|
||||
}
|
||||
popMatrix();
|
||||
angle += 360.0f/bricksPerLayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Cube {
|
||||
|
||||
Point3D[] vertices = new Point3D[24];
|
||||
float w, h, d;
|
||||
|
||||
Cube(){ }
|
||||
|
||||
Cube(float w, float h, float d){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
|
||||
// Cube composed of 6 quads
|
||||
// Front
|
||||
vertices[0] = new Point3D(-w/2,-h/2,d/2);
|
||||
vertices[1] = new Point3D(w/2,-h/2,d/2);
|
||||
vertices[2] = new Point3D(w/2,h/2,d/2);
|
||||
vertices[3] = new Point3D(-w/2,h/2,d/2);
|
||||
|
||||
// Left
|
||||
vertices[4] = new Point3D(-w/2,-h/2,d/2);
|
||||
vertices[5] = new Point3D(-w/2,-h/2,-d/2);
|
||||
vertices[6] = new Point3D(-w/2,h/2,-d/2);
|
||||
vertices[7] = new Point3D(-w/2,h/2,d/2);
|
||||
|
||||
// Right
|
||||
vertices[8] = new Point3D(w/2,-h/2,d/2);
|
||||
vertices[9] = new Point3D(w/2,-h/2,-d/2);
|
||||
vertices[10] = new Point3D(w/2,h/2,-d/2);
|
||||
vertices[11] = new Point3D(w/2,h/2,d/2);
|
||||
|
||||
// Back
|
||||
vertices[12] = new Point3D(-w/2,-h/2,-d/2);
|
||||
vertices[13] = new Point3D(w/2,-h/2,-d/2);
|
||||
vertices[14] = new Point3D(w/2,h/2,-d/2);
|
||||
vertices[15] = new Point3D(-w/2,h/2,-d/2);
|
||||
|
||||
// Top
|
||||
vertices[16] = new Point3D(-w/2,-h/2,d/2);
|
||||
vertices[17] = new Point3D(-w/2,-h/2,-d/2);
|
||||
vertices[18] = new Point3D(w/2,-h/2,-d/2);
|
||||
vertices[19] = new Point3D(w/2,-h/2,d/2);
|
||||
|
||||
// Bottom
|
||||
vertices[20] = new Point3D(-w/2,h/2,d/2);
|
||||
vertices[21] = new Point3D(-w/2,h/2,-d/2);
|
||||
vertices[22] = new Point3D(w/2,h/2,-d/2);
|
||||
vertices[23] = new Point3D(w/2,h/2,d/2);
|
||||
}
|
||||
|
||||
public void create(){
|
||||
for (int i=0; i<6; i++){
|
||||
beginShape(QUADS);
|
||||
for (int j = 0; j < 4; j++){
|
||||
vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z);
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
class Point3D {
|
||||
float x, y, z;
|
||||
|
||||
Point3D(){ }
|
||||
|
||||
Point3D(float x, float y, float z){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "BrickTower" });
|
||||
}
|
||||
}
|
||||
61
java/examples/3D/Form/BrickTower/applet/BrickTower.pde
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Brick Tower
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* 3D castle tower constructed out of individual bricks.
|
||||
* Uses the Point3D and Cube classes.
|
||||
*/
|
||||
|
||||
|
||||
float bricksPerLayer = 16.0;
|
||||
float brickLayers = 18.0;
|
||||
Cube brick;
|
||||
float brickWidth = 60, brickHeight = 25, brickDepth = 25;
|
||||
float radius = 175.0;
|
||||
float angle = 0;
|
||||
|
||||
void setup(){
|
||||
size(640, 360, P3D);
|
||||
brick = new Cube(brickWidth, brickHeight, brickDepth);
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(0);
|
||||
float tempX = 0, tempY = 0, tempZ = 0;
|
||||
fill(182, 62, 29);
|
||||
noStroke();
|
||||
// Add basic light setup
|
||||
lights();
|
||||
translate(width/2, height*1.2, -380);
|
||||
// Tip tower to see inside
|
||||
rotateX(radians(-45));
|
||||
// Slowly rotate tower
|
||||
rotateY(frameCount * PI/600);
|
||||
for (int i = 0; i < brickLayers; i++){
|
||||
// Increment rows
|
||||
tempY-=brickHeight;
|
||||
// Alternate brick seams
|
||||
angle = 360.0 / bricksPerLayer * i/2;
|
||||
for (int j = 0; j < bricksPerLayer; j++){
|
||||
tempZ = cos(radians(angle))*radius;
|
||||
tempX = sin(radians(angle))*radius;
|
||||
pushMatrix();
|
||||
translate(tempX, tempY, tempZ);
|
||||
rotateY(radians(angle));
|
||||
// Add crenelation
|
||||
if (i==brickLayers-1){
|
||||
if (j%2 == 0){
|
||||
brick.create();
|
||||
}
|
||||
}
|
||||
// Create main tower
|
||||
else {
|
||||
brick.create();
|
||||
}
|
||||
popMatrix();
|
||||
angle += 360.0/bricksPerLayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
60
java/examples/3D/Form/BrickTower/applet/Cube.pde
Normal file
@@ -0,0 +1,60 @@
|
||||
class Cube {
|
||||
|
||||
Point3D[] vertices = new Point3D[24];
|
||||
float w, h, d;
|
||||
|
||||
Cube(){ }
|
||||
|
||||
Cube(float w, float h, float d){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
|
||||
// Cube composed of 6 quads
|
||||
// Front
|
||||
vertices[0] = new Point3D(-w/2,-h/2,d/2);
|
||||
vertices[1] = new Point3D(w/2,-h/2,d/2);
|
||||
vertices[2] = new Point3D(w/2,h/2,d/2);
|
||||
vertices[3] = new Point3D(-w/2,h/2,d/2);
|
||||
|
||||
// Left
|
||||
vertices[4] = new Point3D(-w/2,-h/2,d/2);
|
||||
vertices[5] = new Point3D(-w/2,-h/2,-d/2);
|
||||
vertices[6] = new Point3D(-w/2,h/2,-d/2);
|
||||
vertices[7] = new Point3D(-w/2,h/2,d/2);
|
||||
|
||||
// Right
|
||||
vertices[8] = new Point3D(w/2,-h/2,d/2);
|
||||
vertices[9] = new Point3D(w/2,-h/2,-d/2);
|
||||
vertices[10] = new Point3D(w/2,h/2,-d/2);
|
||||
vertices[11] = new Point3D(w/2,h/2,d/2);
|
||||
|
||||
// Back
|
||||
vertices[12] = new Point3D(-w/2,-h/2,-d/2);
|
||||
vertices[13] = new Point3D(w/2,-h/2,-d/2);
|
||||
vertices[14] = new Point3D(w/2,h/2,-d/2);
|
||||
vertices[15] = new Point3D(-w/2,h/2,-d/2);
|
||||
|
||||
// Top
|
||||
vertices[16] = new Point3D(-w/2,-h/2,d/2);
|
||||
vertices[17] = new Point3D(-w/2,-h/2,-d/2);
|
||||
vertices[18] = new Point3D(w/2,-h/2,-d/2);
|
||||
vertices[19] = new Point3D(w/2,-h/2,d/2);
|
||||
|
||||
// Bottom
|
||||
vertices[20] = new Point3D(-w/2,h/2,d/2);
|
||||
vertices[21] = new Point3D(-w/2,h/2,-d/2);
|
||||
vertices[22] = new Point3D(w/2,h/2,-d/2);
|
||||
vertices[23] = new Point3D(w/2,h/2,d/2);
|
||||
}
|
||||
|
||||
void create(){
|
||||
for (int i=0; i<6; i++){
|
||||
beginShape(QUADS);
|
||||
for (int j = 0; j < 4; j++){
|
||||
vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z);
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
java/examples/3D/Form/BrickTower/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
47
java/examples/3D/Form/CubicGrid/CubicGrid.pde
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Cubic Grid
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* 3D translucent colored grid uses nested pushMatrix()
|
||||
* and popMatrix() functions.
|
||||
*/
|
||||
|
||||
float boxSize = 40;
|
||||
float margin = boxSize*2;
|
||||
float depth = 400;
|
||||
color boxFill;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
|
||||
// Center and spin grid
|
||||
translate(width/2, height/2, -depth);
|
||||
rotateY(frameCount * 0.01);
|
||||
rotateX(frameCount * 0.01);
|
||||
|
||||
// Build grid using multiple translations
|
||||
for (float i =- depth/2+margin; i <= depth/2-margin; i += boxSize){
|
||||
pushMatrix();
|
||||
for (float j =- height+margin; j <= height-margin; j += boxSize){
|
||||
pushMatrix();
|
||||
for (float k =- width+margin; k <= width-margin; k += boxSize){
|
||||
// Base fill color on counter values, abs function
|
||||
// ensures values stay within legal range
|
||||
boxFill = color(abs(i), abs(j), abs(k), 50);
|
||||
pushMatrix();
|
||||
translate(k, j, i);
|
||||
fill(boxFill);
|
||||
box(boxSize, boxSize, boxSize);
|
||||
popMatrix();
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
67
java/examples/3D/Form/CubicGrid/applet/CubicGrid.java
Normal file
@@ -0,0 +1,67 @@
|
||||
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 CubicGrid extends PApplet {
|
||||
|
||||
/**
|
||||
* Cubic Grid
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* 3D translucent colored grid uses nested pushMatrix()
|
||||
* and popMatrix() functions.
|
||||
*/
|
||||
|
||||
float boxSize = 40;
|
||||
float margin = boxSize*2;
|
||||
float depth = 400;
|
||||
int boxFill;
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(255);
|
||||
|
||||
// Center and spin grid
|
||||
translate(width/2, height/2, -depth);
|
||||
rotateY(frameCount * 0.01f);
|
||||
rotateX(frameCount * 0.01f);
|
||||
|
||||
// Build grid using multiple translations
|
||||
for (float i =- depth/2+margin; i <= depth/2-margin; i += boxSize){
|
||||
pushMatrix();
|
||||
for (float j =- height+margin; j <= height-margin; j += boxSize){
|
||||
pushMatrix();
|
||||
for (float k =- width+margin; k <= width-margin; k += boxSize){
|
||||
// Base fill color on counter values, abs function
|
||||
// ensures values stay within legal range
|
||||
boxFill = color(abs(i), abs(j), abs(k), 50);
|
||||
pushMatrix();
|
||||
translate(k, j, i);
|
||||
fill(boxFill);
|
||||
box(boxSize, boxSize, boxSize);
|
||||
popMatrix();
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "CubicGrid" });
|
||||
}
|
||||
}
|
||||
47
java/examples/3D/Form/CubicGrid/applet/CubicGrid.pde
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Cubic Grid
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* 3D translucent colored grid uses nested pushMatrix()
|
||||
* and popMatrix() functions.
|
||||
*/
|
||||
|
||||
float boxSize = 40;
|
||||
float margin = boxSize*2;
|
||||
float depth = 400;
|
||||
color boxFill;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
|
||||
// Center and spin grid
|
||||
translate(width/2, height/2, -depth);
|
||||
rotateY(frameCount * 0.01);
|
||||
rotateX(frameCount * 0.01);
|
||||
|
||||
// Build grid using multiple translations
|
||||
for (float i =- depth/2+margin; i <= depth/2-margin; i += boxSize){
|
||||
pushMatrix();
|
||||
for (float j =- height+margin; j <= height-margin; j += boxSize){
|
||||
pushMatrix();
|
||||
for (float k =- width+margin; k <= width-margin; k += boxSize){
|
||||
// Base fill color on counter values, abs function
|
||||
// ensures values stay within legal range
|
||||
boxFill = color(abs(i), abs(j), abs(k), 50);
|
||||
pushMatrix();
|
||||
translate(k, j, i);
|
||||
fill(boxFill);
|
||||
box(boxSize, boxSize, boxSize);
|
||||
popMatrix();
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
BIN
java/examples/3D/Form/CubicGrid/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
10
java/examples/3D/Form/Icosahedra/Dimension3D.pde
Executable file
@@ -0,0 +1,10 @@
|
||||
class Dimension3D{
|
||||
float w, h, d;
|
||||
|
||||
Dimension3D(float w, float h, float d){
|
||||
this.w=w;
|
||||
this.h=h;
|
||||
this.d=d;
|
||||
}
|
||||
}
|
||||
|
||||
52
java/examples/3D/Form/Icosahedra/Icosahedra.pde
Executable file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* I Like Icosahedra
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* This example plots icosahedra. The Icosahdron is a regular
|
||||
* polyhedron composed of twenty equalateral triangles.
|
||||
*/
|
||||
|
||||
Icosahedron ico1;
|
||||
Icosahedron ico2;
|
||||
Icosahedron ico3;
|
||||
|
||||
void setup(){
|
||||
size(640, 360, P3D);
|
||||
ico1 = new Icosahedron(75);
|
||||
ico2 = new Icosahedron(75);
|
||||
ico3 = new Icosahedron(75);
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(0);
|
||||
lights();
|
||||
translate(width/2, height/2);
|
||||
|
||||
pushMatrix();
|
||||
translate(-width/3.5, 0);
|
||||
rotateX(frameCount*PI/185);
|
||||
rotateY(frameCount*PI/-200);
|
||||
stroke(170, 0, 0);
|
||||
noFill();
|
||||
ico1.create();
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
rotateX(frameCount*PI/200);
|
||||
rotateY(frameCount*PI/300);
|
||||
stroke(150, 0, 180);
|
||||
fill(170, 170, 0);
|
||||
ico2.create();
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
translate(width/3.5, 0);
|
||||
rotateX(frameCount*PI/-200);
|
||||
rotateY(frameCount*PI/200);
|
||||
noStroke();
|
||||
fill(0, 0, 185);
|
||||
ico3.create();
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
|
||||
159
java/examples/3D/Form/Icosahedra/Icosahedron.pde
Executable file
@@ -0,0 +1,159 @@
|
||||
class Icosahedron extends Shape3D{
|
||||
|
||||
// icosahedron
|
||||
PVector topPoint;
|
||||
PVector[] topPent = new PVector[5];
|
||||
PVector bottomPoint;
|
||||
PVector[] bottomPent = new PVector[5];
|
||||
float angle = 0, radius = 150;
|
||||
float triDist;
|
||||
float triHt;
|
||||
float a, b, c;
|
||||
|
||||
// constructor
|
||||
Icosahedron(float radius){
|
||||
this.radius = radius;
|
||||
init();
|
||||
}
|
||||
|
||||
Icosahedron(PVector v, float radius){
|
||||
super(v);
|
||||
this.radius = radius;
|
||||
init();
|
||||
}
|
||||
|
||||
// calculate geometry
|
||||
void init(){
|
||||
c = dist(cos(0)*radius, sin(0)*radius, cos(radians(72))*radius, sin(radians(72))*radius);
|
||||
b = radius;
|
||||
a = (float)(Math.sqrt(((c*c)-(b*b))));
|
||||
|
||||
triHt = (float)(Math.sqrt((c*c)-((c/2)*(c/2))));
|
||||
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
topPent[i] = new PVector(cos(angle)*radius, sin(angle)*radius, triHt/2.0f);
|
||||
angle+=radians(72);
|
||||
}
|
||||
topPoint = new PVector(0, 0, triHt/2.0f+a);
|
||||
angle = 72.0f/2.0f;
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
bottomPent[i] = new PVector(cos(angle)*radius, sin(angle)*radius, -triHt/2.0f);
|
||||
angle+=radians(72);
|
||||
}
|
||||
bottomPoint = new PVector(0, 0, -(triHt/2.0f+a));
|
||||
}
|
||||
|
||||
// draws icosahedron
|
||||
void create(){
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
// icosahedron top
|
||||
beginShape();
|
||||
if (i<topPent.length-1){
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z);
|
||||
vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
|
||||
}
|
||||
else {
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z);
|
||||
vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
|
||||
// icosahedron bottom
|
||||
beginShape();
|
||||
if (i<bottomPent.length-1){
|
||||
vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z);
|
||||
vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z);
|
||||
vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
|
||||
}
|
||||
else {
|
||||
vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z);
|
||||
vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z);
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
}
|
||||
|
||||
// icosahedron body
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
if (i<topPent.length-2){
|
||||
beginShape();
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
|
||||
vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z);
|
||||
endShape(CLOSE);
|
||||
|
||||
beginShape();
|
||||
vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z);
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
else if (i==topPent.length-2){
|
||||
beginShape();
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
endShape(CLOSE);
|
||||
|
||||
beginShape();
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
else if (i==topPent.length-1){
|
||||
beginShape();
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z);
|
||||
endShape(CLOSE);
|
||||
|
||||
beginShape();
|
||||
vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z);
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrided methods fom Shape3D
|
||||
void rotZ(float theta){
|
||||
float tx=0, ty=0, tz=0;
|
||||
// top point
|
||||
tx = cos(theta)*topPoint.x+sin(theta)*topPoint.y;
|
||||
ty = sin(theta)*topPoint.x-cos(theta)*topPoint.y;
|
||||
topPoint.x = tx;
|
||||
topPoint.y = ty;
|
||||
|
||||
// bottom point
|
||||
tx = cos(theta)*bottomPoint.x+sin(theta)*bottomPoint.y;
|
||||
ty = sin(theta)*bottomPoint.x-cos(theta)*bottomPoint.y;
|
||||
bottomPoint.x = tx;
|
||||
bottomPoint.y = ty;
|
||||
|
||||
// top and bottom pentagons
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
tx = cos(theta)*topPent[i].x+sin(theta)*topPent[i].y;
|
||||
ty = sin(theta)*topPent[i].x-cos(theta)*topPent[i].y;
|
||||
topPent[i].x = tx;
|
||||
topPent[i].y = ty;
|
||||
|
||||
tx = cos(theta)*bottomPent[i].x+sin(theta)*bottomPent[i].y;
|
||||
ty = sin(theta)*bottomPent[i].x-cos(theta)*bottomPent[i].y;
|
||||
bottomPent[i].x = tx;
|
||||
bottomPent[i].y = ty;
|
||||
}
|
||||
}
|
||||
|
||||
void rotX(float theta){
|
||||
}
|
||||
|
||||
void rotY(float theta){
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
82
java/examples/3D/Form/Icosahedra/Shape3D.pde
Executable file
@@ -0,0 +1,82 @@
|
||||
abstract class Shape3D{
|
||||
float x, y, z;
|
||||
float w, h, d;
|
||||
|
||||
Shape3D(){
|
||||
}
|
||||
|
||||
Shape3D(float x, float y, float z){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
Shape3D(PVector p){
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
}
|
||||
|
||||
|
||||
Shape3D(Dimension3D dim){
|
||||
w = dim.w;
|
||||
h = dim.h;
|
||||
d = dim.d;
|
||||
}
|
||||
|
||||
Shape3D(float x, float y, float z, float w, float h, float d){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
Shape3D(float x, float y, float z, Dimension3D dim){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
w = dim.w;
|
||||
h = dim.h;
|
||||
d = dim.d;
|
||||
}
|
||||
|
||||
Shape3D(PVector p, Dimension3D dim){
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
w = dim.w;
|
||||
h = dim.h;
|
||||
d = dim.d;
|
||||
}
|
||||
|
||||
void setLoc(PVector p){
|
||||
x=p.x;
|
||||
y=p.y;
|
||||
z=p.z;
|
||||
}
|
||||
|
||||
void setLoc(float x, float y, float z){
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
this.z=z;
|
||||
}
|
||||
|
||||
|
||||
// override if you need these
|
||||
void rotX(float theta){
|
||||
}
|
||||
|
||||
void rotY(float theta){
|
||||
}
|
||||
|
||||
void rotZ(float theta){
|
||||
}
|
||||
|
||||
|
||||
// must be implemented in subclasses
|
||||
abstract void init();
|
||||
abstract void create();
|
||||
}
|
||||
|
||||
10
java/examples/3D/Form/Icosahedra/applet/Dimension3D.pde
Normal file
@@ -0,0 +1,10 @@
|
||||
class Dimension3D {
|
||||
|
||||
float w, h, d;
|
||||
|
||||
Dimension3D(float w, float h, float d){
|
||||
this.w=w;
|
||||
this.h=h;
|
||||
this.d=d;
|
||||
}
|
||||
}
|
||||
416
java/examples/3D/Form/Icosahedra/applet/Icosahedra.java
Normal file
@@ -0,0 +1,416 @@
|
||||
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 Icosahedra extends PApplet {
|
||||
|
||||
/**
|
||||
* I Like Icosahedra
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* This example plots icosahedra. The Icosahdron is a regular
|
||||
* polyhedron composed of 20 equalateral triangles.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
Icosahedron ico1;
|
||||
Icosahedron ico2;
|
||||
Icosahedron ico3;
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
ico1 = new Icosahedron(75);
|
||||
ico2 = new Icosahedron(75);
|
||||
ico3 = new Icosahedron(75);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(0);
|
||||
lights();
|
||||
translate(width/2, height/2);
|
||||
|
||||
pushMatrix();
|
||||
translate(-width/3.5f, 0);
|
||||
rotateX(frameCount * PI/185);
|
||||
rotateY(frameCount * PI/-200);
|
||||
stroke(170, 0, 0);
|
||||
noFill();
|
||||
ico1.create();
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
rotateX(frameCount * PI/200);
|
||||
rotateY(frameCount * PI/300);
|
||||
stroke(150, 0, 180);
|
||||
fill(170, 170, 0);
|
||||
ico2.create();
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
translate(width/3.5f, 0);
|
||||
rotateX(frameCount * PI/-200);
|
||||
rotateY(frameCount * PI/200);
|
||||
noStroke();
|
||||
fill(0, 0, 185);
|
||||
ico3.create();
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
class Dimension3D {
|
||||
|
||||
float w, h, d;
|
||||
|
||||
Dimension3D(float w, float h, float d){
|
||||
this.w=w;
|
||||
this.h=h;
|
||||
this.d=d;
|
||||
}
|
||||
}
|
||||
class Icosahedron extends Shape3D {
|
||||
|
||||
// icosahedron
|
||||
Vector3D topPoint;
|
||||
Vector3D[] topPent = new Vector3D[5];
|
||||
Vector3D bottomPoint;
|
||||
Vector3D[] bottomPent = new Vector3D[5];
|
||||
float angle = 0, radius = 150;
|
||||
float triDist;
|
||||
float triHt;
|
||||
float a, b, c;
|
||||
|
||||
// constructor
|
||||
Icosahedron(float radius) {
|
||||
this.radius = radius;
|
||||
init();
|
||||
}
|
||||
|
||||
Icosahedron(Vector3D v, float radius) {
|
||||
super(v);
|
||||
this.radius = radius;
|
||||
init();
|
||||
}
|
||||
|
||||
// calculate geometry
|
||||
public void init() {
|
||||
c = dist(cos(0)*radius, sin(0)*radius,
|
||||
cos(radians(72))*radius, sin(radians(72))*radius);
|
||||
b = radius;
|
||||
a = (float)(Math.sqrt(((c*c)-(b*b))));
|
||||
|
||||
triHt = (float)(Math.sqrt((c*c)-((c/2)*(c/2))));
|
||||
|
||||
for (int i = 0; i < topPent.length; i++){
|
||||
topPent[i] = new Vector3D(cos(angle)*radius,
|
||||
sin(angle)*radius, triHt/2.0f);
|
||||
angle+=radians(72);
|
||||
}
|
||||
topPoint = new Vector3D(0, 0, triHt/2.0f+a);
|
||||
angle = 72.0f/2.0f;
|
||||
for (int i = 0; i < topPent.length; i++){
|
||||
bottomPent[i] = new Vector3D(cos(angle)*radius,
|
||||
sin(angle)*radius, -triHt/2.0f);
|
||||
angle+=radians(72);
|
||||
}
|
||||
bottomPoint = new Vector3D(0, 0, -(triHt/2.0f+a));
|
||||
}
|
||||
|
||||
// draws icosahedron
|
||||
public void create(){
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
// icosahedron top
|
||||
beginShape();
|
||||
if (i<topPent.length-1){
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z);
|
||||
vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
|
||||
}
|
||||
else {
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z);
|
||||
vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
|
||||
// icosahedron bottom
|
||||
beginShape();
|
||||
if (i<bottomPent.length-1){
|
||||
vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z);
|
||||
vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z);
|
||||
vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
|
||||
}
|
||||
else {
|
||||
vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z);
|
||||
vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z);
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
}
|
||||
|
||||
// icosahedron body
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
if (i<topPent.length-2){
|
||||
beginShape();
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
|
||||
vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z);
|
||||
endShape(CLOSE);
|
||||
|
||||
beginShape();
|
||||
vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z);
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
else if (i==topPent.length-2){
|
||||
beginShape();
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
endShape(CLOSE);
|
||||
|
||||
beginShape();
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
else if (i==topPent.length-1){
|
||||
beginShape();
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z);
|
||||
endShape(CLOSE);
|
||||
|
||||
beginShape();
|
||||
vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z);
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrided methods fom Shape3D
|
||||
public void rotZ(float theta){
|
||||
float tx=0, ty=0, tz=0;
|
||||
// top point
|
||||
tx = cos(theta)*topPoint.x+sin(theta)*topPoint.y;
|
||||
ty = sin(theta)*topPoint.x-cos(theta)*topPoint.y;
|
||||
topPoint.x = tx;
|
||||
topPoint.y = ty;
|
||||
|
||||
// bottom point
|
||||
tx = cos(theta)*bottomPoint.x+sin(theta)*bottomPoint.y;
|
||||
ty = sin(theta)*bottomPoint.x-cos(theta)*bottomPoint.y;
|
||||
bottomPoint.x = tx;
|
||||
bottomPoint.y = ty;
|
||||
|
||||
// top and bottom pentagons
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
tx = cos(theta)*topPent[i].x+sin(theta)*topPent[i].y;
|
||||
ty = sin(theta)*topPent[i].x-cos(theta)*topPent[i].y;
|
||||
topPent[i].x = tx;
|
||||
topPent[i].y = ty;
|
||||
|
||||
tx = cos(theta)*bottomPent[i].x+sin(theta)*bottomPent[i].y;
|
||||
ty = sin(theta)*bottomPent[i].x-cos(theta)*bottomPent[i].y;
|
||||
bottomPent[i].x = tx;
|
||||
bottomPent[i].y = ty;
|
||||
}
|
||||
}
|
||||
|
||||
public void rotX(float theta){
|
||||
}
|
||||
|
||||
public void rotY(float theta){
|
||||
}
|
||||
|
||||
}
|
||||
abstract class Shape3D {
|
||||
|
||||
float x, y, z;
|
||||
float w, h, d;
|
||||
|
||||
Shape3D() { }
|
||||
|
||||
Shape3D(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
Shape3D(Vector3D p) {
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
}
|
||||
|
||||
|
||||
Shape3D(Dimension3D dim) {
|
||||
w = dim.w;
|
||||
h = dim.h;
|
||||
d = dim.d;
|
||||
}
|
||||
|
||||
Shape3D(float x, float y, float z, float w, float h, float d) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
Shape3D(float x, float y, float z, Dimension3D dim) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
w = dim.w;
|
||||
h = dim.h;
|
||||
d = dim.d;
|
||||
}
|
||||
|
||||
Shape3D(Vector3D p, Dimension3D dim) {
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
w = dim.w;
|
||||
h = dim.h;
|
||||
d = dim.d;
|
||||
}
|
||||
|
||||
public void setLoc(Vector3D p) {
|
||||
x=p.x;
|
||||
y=p.y;
|
||||
z=p.z;
|
||||
}
|
||||
|
||||
public void setLoc(float x, float y, float z) {
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
this.z=z;
|
||||
}
|
||||
|
||||
|
||||
// override if you need these
|
||||
public void rotX(float theta) {
|
||||
}
|
||||
|
||||
public void rotY(float theta) {
|
||||
}
|
||||
|
||||
public void rotZ(float theta) {
|
||||
}
|
||||
|
||||
|
||||
// must be implemented in subclasses
|
||||
public abstract void init();
|
||||
public abstract void create();
|
||||
}
|
||||
class Vector3D {
|
||||
|
||||
float x, y, z;
|
||||
float[]origVals;
|
||||
|
||||
Vector3D() { }
|
||||
|
||||
Vector3D(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
// capture original values
|
||||
origVals = new float[]{
|
||||
x, y, z };
|
||||
}
|
||||
|
||||
//methods
|
||||
public void add(Vector3D v) {
|
||||
x+=v.x;
|
||||
y+=v.y;
|
||||
z+=v.z;
|
||||
}
|
||||
|
||||
public void subtract(Vector3D v) {
|
||||
x-=v.x;
|
||||
y-=v.y;
|
||||
z-=v.z;
|
||||
}
|
||||
|
||||
public void multiply(float s) {
|
||||
x*=s;
|
||||
y*=s;
|
||||
z*=s;
|
||||
}
|
||||
|
||||
public void divide(float s) {
|
||||
x/=s;
|
||||
y/=s;
|
||||
z/=s;
|
||||
}
|
||||
|
||||
public Vector3D getAverage(Vector3D v) {
|
||||
Vector3D u = new Vector3D();
|
||||
u.x = (x+v.x)/2;
|
||||
u.y = (y+v.y)/2;
|
||||
u.z = (z+v.z)/2;
|
||||
return u;
|
||||
}
|
||||
|
||||
public void setTo(Vector3D v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
x = origVals[0];
|
||||
y = origVals[1];
|
||||
z = origVals[2];
|
||||
}
|
||||
|
||||
public float getDotProduct(Vector3D v) {
|
||||
return x*v.x + y*v.y + z*v.z;
|
||||
}
|
||||
|
||||
public Vector3D getCrossProduct(Vector3D v, Vector3D u) {
|
||||
Vector3D v1 = new Vector3D(v.x-x, v.y-y, v.z-z);
|
||||
Vector3D v2 = new Vector3D(u.x-x, u.y-y, u.z-z);
|
||||
float xx = v1.y*v2.z-v1.z*v2.y;
|
||||
float yy = v1.z*v2.x-v1.x*v2.z;
|
||||
float zz = v1.x*v2.y-v1.y*v2.x;
|
||||
return new Vector3D(xx, yy, zz);
|
||||
}
|
||||
|
||||
public Vector3D getNormal(Vector3D v, Vector3D u) {
|
||||
Vector3D n = getCrossProduct(v, u);
|
||||
n.normalize();
|
||||
return(n);
|
||||
}
|
||||
|
||||
public void normalize() {
|
||||
float m = getMagnitude();
|
||||
x/=m;
|
||||
y/=m;
|
||||
z/=m;
|
||||
}
|
||||
|
||||
public float getMagnitude() {
|
||||
return sqrt(x*x+y*y+z*z);
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Icosahedra" });
|
||||
}
|
||||
}
|
||||
53
java/examples/3D/Form/Icosahedra/applet/Icosahedra.pde
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* I Like Icosahedra
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* This example plots icosahedra. The Icosahdron is a regular
|
||||
* polyhedron composed of 20 equalateral triangles.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
Icosahedron ico1;
|
||||
Icosahedron ico2;
|
||||
Icosahedron ico3;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
ico1 = new Icosahedron(75);
|
||||
ico2 = new Icosahedron(75);
|
||||
ico3 = new Icosahedron(75);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
lights();
|
||||
translate(width/2, height/2);
|
||||
|
||||
pushMatrix();
|
||||
translate(-width/3.5, 0);
|
||||
rotateX(frameCount * PI/185);
|
||||
rotateY(frameCount * PI/-200);
|
||||
stroke(170, 0, 0);
|
||||
noFill();
|
||||
ico1.create();
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
rotateX(frameCount * PI/200);
|
||||
rotateY(frameCount * PI/300);
|
||||
stroke(150, 0, 180);
|
||||
fill(170, 170, 0);
|
||||
ico2.create();
|
||||
popMatrix();
|
||||
|
||||
pushMatrix();
|
||||
translate(width/3.5, 0);
|
||||
rotateX(frameCount * PI/-200);
|
||||
rotateY(frameCount * PI/200);
|
||||
noStroke();
|
||||
fill(0, 0, 185);
|
||||
ico3.create();
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
160
java/examples/3D/Form/Icosahedra/applet/Icosahedron.pde
Normal file
@@ -0,0 +1,160 @@
|
||||
class Icosahedron extends Shape3D {
|
||||
|
||||
// icosahedron
|
||||
Vector3D topPoint;
|
||||
Vector3D[] topPent = new Vector3D[5];
|
||||
Vector3D bottomPoint;
|
||||
Vector3D[] bottomPent = new Vector3D[5];
|
||||
float angle = 0, radius = 150;
|
||||
float triDist;
|
||||
float triHt;
|
||||
float a, b, c;
|
||||
|
||||
// constructor
|
||||
Icosahedron(float radius) {
|
||||
this.radius = radius;
|
||||
init();
|
||||
}
|
||||
|
||||
Icosahedron(Vector3D v, float radius) {
|
||||
super(v);
|
||||
this.radius = radius;
|
||||
init();
|
||||
}
|
||||
|
||||
// calculate geometry
|
||||
void init() {
|
||||
c = dist(cos(0)*radius, sin(0)*radius,
|
||||
cos(radians(72))*radius, sin(radians(72))*radius);
|
||||
b = radius;
|
||||
a = (float)(Math.sqrt(((c*c)-(b*b))));
|
||||
|
||||
triHt = (float)(Math.sqrt((c*c)-((c/2)*(c/2))));
|
||||
|
||||
for (int i = 0; i < topPent.length; i++){
|
||||
topPent[i] = new Vector3D(cos(angle)*radius,
|
||||
sin(angle)*radius, triHt/2.0);
|
||||
angle+=radians(72);
|
||||
}
|
||||
topPoint = new Vector3D(0, 0, triHt/2.0+a);
|
||||
angle = 72.0/2.0;
|
||||
for (int i = 0; i < topPent.length; i++){
|
||||
bottomPent[i] = new Vector3D(cos(angle)*radius,
|
||||
sin(angle)*radius, -triHt/2.0);
|
||||
angle+=radians(72);
|
||||
}
|
||||
bottomPoint = new Vector3D(0, 0, -(triHt/2.0+a));
|
||||
}
|
||||
|
||||
// draws icosahedron
|
||||
void create(){
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
// icosahedron top
|
||||
beginShape();
|
||||
if (i<topPent.length-1){
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z);
|
||||
vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
|
||||
}
|
||||
else {
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z);
|
||||
vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
|
||||
// icosahedron bottom
|
||||
beginShape();
|
||||
if (i<bottomPent.length-1){
|
||||
vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z);
|
||||
vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z);
|
||||
vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
|
||||
}
|
||||
else {
|
||||
vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z);
|
||||
vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z);
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
}
|
||||
|
||||
// icosahedron body
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
if (i<topPent.length-2){
|
||||
beginShape();
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
|
||||
vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z);
|
||||
endShape(CLOSE);
|
||||
|
||||
beginShape();
|
||||
vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z);
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
else if (i==topPent.length-2){
|
||||
beginShape();
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
endShape(CLOSE);
|
||||
|
||||
beginShape();
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
else if (i==topPent.length-1){
|
||||
beginShape();
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
|
||||
vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z);
|
||||
endShape(CLOSE);
|
||||
|
||||
beginShape();
|
||||
vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z);
|
||||
vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
|
||||
vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrided methods fom Shape3D
|
||||
void rotZ(float theta){
|
||||
float tx=0, ty=0, tz=0;
|
||||
// top point
|
||||
tx = cos(theta)*topPoint.x+sin(theta)*topPoint.y;
|
||||
ty = sin(theta)*topPoint.x-cos(theta)*topPoint.y;
|
||||
topPoint.x = tx;
|
||||
topPoint.y = ty;
|
||||
|
||||
// bottom point
|
||||
tx = cos(theta)*bottomPoint.x+sin(theta)*bottomPoint.y;
|
||||
ty = sin(theta)*bottomPoint.x-cos(theta)*bottomPoint.y;
|
||||
bottomPoint.x = tx;
|
||||
bottomPoint.y = ty;
|
||||
|
||||
// top and bottom pentagons
|
||||
for (int i=0; i<topPent.length; i++){
|
||||
tx = cos(theta)*topPent[i].x+sin(theta)*topPent[i].y;
|
||||
ty = sin(theta)*topPent[i].x-cos(theta)*topPent[i].y;
|
||||
topPent[i].x = tx;
|
||||
topPent[i].y = ty;
|
||||
|
||||
tx = cos(theta)*bottomPent[i].x+sin(theta)*bottomPent[i].y;
|
||||
ty = sin(theta)*bottomPent[i].x-cos(theta)*bottomPent[i].y;
|
||||
bottomPent[i].x = tx;
|
||||
bottomPent[i].y = ty;
|
||||
}
|
||||
}
|
||||
|
||||
void rotX(float theta){
|
||||
}
|
||||
|
||||
void rotY(float theta){
|
||||
}
|
||||
|
||||
}
|
||||
81
java/examples/3D/Form/Icosahedra/applet/Shape3D.pde
Normal file
@@ -0,0 +1,81 @@
|
||||
abstract class Shape3D {
|
||||
|
||||
float x, y, z;
|
||||
float w, h, d;
|
||||
|
||||
Shape3D() { }
|
||||
|
||||
Shape3D(float x, float y, float z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
Shape3D(Vector3D p) {
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
}
|
||||
|
||||
|
||||
Shape3D(Dimension3D dim) {
|
||||
w = dim.w;
|
||||
h = dim.h;
|
||||
d = dim.d;
|
||||
}
|
||||
|
||||
Shape3D(float x, float y, float z, float w, float h, float d) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
Shape3D(float x, float y, float z, Dimension3D dim) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
w = dim.w;
|
||||
h = dim.h;
|
||||
d = dim.d;
|
||||
}
|
||||
|
||||
Shape3D(Vector3D p, Dimension3D dim) {
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
w = dim.w;
|
||||
h = dim.h;
|
||||
d = dim.d;
|
||||
}
|
||||
|
||||
void setLoc(Vector3D p) {
|
||||
x=p.x;
|
||||
y=p.y;
|
||||
z=p.z;
|
||||
}
|
||||
|
||||
void setLoc(float x, float y, float z) {
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
this.z=z;
|
||||
}
|
||||
|
||||
|
||||
// override if you need these
|
||||
void rotX(float theta) {
|
||||
}
|
||||
|
||||
void rotY(float theta) {
|
||||
}
|
||||
|
||||
void rotZ(float theta) {
|
||||
}
|
||||
|
||||
|
||||
// must be implemented in subclasses
|
||||
abstract void init();
|
||||
abstract void create();
|
||||
}
|
||||
BIN
java/examples/3D/Form/Icosahedra/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
30
java/examples/3D/Form/Primitives3D/Primitives3D.pde
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Primitives 3D.
|
||||
*
|
||||
* Placing mathematically 3D objects in synthetic space.
|
||||
* The lights() method reveals their imagined dimension.
|
||||
* The box() and sphere() functions each have one parameter
|
||||
* which is used to specify their size. These shapes are
|
||||
* positioned using the translate() function.
|
||||
*/
|
||||
|
||||
size(640, 360, P3D);
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
noStroke();
|
||||
pushMatrix();
|
||||
translate(130, height/2, 0);
|
||||
rotateY(1.25);
|
||||
rotateX(-0.4);
|
||||
box(100);
|
||||
popMatrix();
|
||||
|
||||
noFill();
|
||||
stroke(255);
|
||||
pushMatrix();
|
||||
translate(500, height*0.35, -200);
|
||||
sphere(280);
|
||||
popMatrix();
|
||||
|
||||
|
||||
51
java/examples/3D/Form/Primitives3D/applet/Primitives3D.java
Normal file
@@ -0,0 +1,51 @@
|
||||
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 Primitives3D extends PApplet {
|
||||
public void setup() {/**
|
||||
* Primitives 3D.
|
||||
*
|
||||
* Placing mathematically 3D objects in synthetic space.
|
||||
* The lights() method reveals their imagined dimension.
|
||||
* The box() and sphere() functions each have one parameter
|
||||
* which is used to specify their size. These shapes are
|
||||
* positioned using the translate() function.
|
||||
*/
|
||||
|
||||
size(640, 360, P3D);
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
noStroke();
|
||||
pushMatrix();
|
||||
translate(130, height/2, 0);
|
||||
rotateY(1.25f);
|
||||
rotateX(-0.4f);
|
||||
box(100);
|
||||
popMatrix();
|
||||
|
||||
noFill();
|
||||
stroke(255);
|
||||
pushMatrix();
|
||||
translate(500, height*0.35f, -200);
|
||||
sphere(280);
|
||||
popMatrix();
|
||||
|
||||
|
||||
|
||||
noLoop();
|
||||
}
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Primitives3D" });
|
||||
}
|
||||
}
|
||||
30
java/examples/3D/Form/Primitives3D/applet/Primitives3D.pde
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Primitives 3D.
|
||||
*
|
||||
* Placing mathematically 3D objects in synthetic space.
|
||||
* The lights() method reveals their imagined dimension.
|
||||
* The box() and sphere() functions each have one parameter
|
||||
* which is used to specify their size. These shapes are
|
||||
* positioned using the translate() function.
|
||||
*/
|
||||
|
||||
size(640, 360, P3D);
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
noStroke();
|
||||
pushMatrix();
|
||||
translate(130, height/2, 0);
|
||||
rotateY(1.25);
|
||||
rotateX(-0.4);
|
||||
box(100);
|
||||
popMatrix();
|
||||
|
||||
noFill();
|
||||
stroke(255);
|
||||
pushMatrix();
|
||||
translate(500, height*0.35, -200);
|
||||
sphere(280);
|
||||
popMatrix();
|
||||
|
||||
|
||||
BIN
java/examples/3D/Form/Primitives3D/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
74
java/examples/3D/Form/RGBCube/RGBCube.pde
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* RGB Cube.
|
||||
*
|
||||
* The three primary colors of the additive color model are red, green, and blue.
|
||||
* This RGB color cube displays smooth transitions between these colors.
|
||||
*/
|
||||
|
||||
float xmag, ymag = 0;
|
||||
float newXmag, newYmag = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
colorMode(RGB, 1);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0.5);
|
||||
|
||||
pushMatrix();
|
||||
|
||||
translate(width/2, height/2, -30);
|
||||
|
||||
newXmag = mouseX/float(width) * TWO_PI;
|
||||
newYmag = mouseY/float(height) * TWO_PI;
|
||||
|
||||
float diff = xmag-newXmag;
|
||||
if (abs(diff) > 0.01) { xmag -= diff/4.0; }
|
||||
|
||||
diff = ymag-newYmag;
|
||||
if (abs(diff) > 0.01) { ymag -= diff/4.0; }
|
||||
|
||||
rotateX(-ymag);
|
||||
rotateY(-xmag);
|
||||
|
||||
scale(90);
|
||||
beginShape(QUADS);
|
||||
|
||||
fill(0, 1, 1); vertex(-1, 1, 1);
|
||||
fill(1, 1, 1); vertex( 1, 1, 1);
|
||||
fill(1, 0, 1); vertex( 1, -1, 1);
|
||||
fill(0, 0, 1); vertex(-1, -1, 1);
|
||||
|
||||
fill(1, 1, 1); vertex( 1, 1, 1);
|
||||
fill(1, 1, 0); vertex( 1, 1, -1);
|
||||
fill(1, 0, 0); vertex( 1, -1, -1);
|
||||
fill(1, 0, 1); vertex( 1, -1, 1);
|
||||
|
||||
fill(1, 1, 0); vertex( 1, 1, -1);
|
||||
fill(0, 1, 0); vertex(-1, 1, -1);
|
||||
fill(0, 0, 0); vertex(-1, -1, -1);
|
||||
fill(1, 0, 0); vertex( 1, -1, -1);
|
||||
|
||||
fill(0, 1, 0); vertex(-1, 1, -1);
|
||||
fill(0, 1, 1); vertex(-1, 1, 1);
|
||||
fill(0, 0, 1); vertex(-1, -1, 1);
|
||||
fill(0, 0, 0); vertex(-1, -1, -1);
|
||||
|
||||
fill(0, 1, 0); vertex(-1, 1, -1);
|
||||
fill(1, 1, 0); vertex( 1, 1, -1);
|
||||
fill(1, 1, 1); vertex( 1, 1, 1);
|
||||
fill(0, 1, 1); vertex(-1, 1, 1);
|
||||
|
||||
fill(0, 0, 0); vertex(-1, -1, -1);
|
||||
fill(1, 0, 0); vertex( 1, -1, -1);
|
||||
fill(1, 0, 1); vertex( 1, -1, 1);
|
||||
fill(0, 0, 1); vertex(-1, -1, 1);
|
||||
|
||||
endShape();
|
||||
|
||||
popMatrix();
|
||||
}
|
||||
94
java/examples/3D/Form/RGBCube/applet/RGBCube.java
Normal file
@@ -0,0 +1,94 @@
|
||||
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 RGBCube extends PApplet {
|
||||
|
||||
/**
|
||||
* RGB Cube.
|
||||
*
|
||||
* The three primary colors of the additive color model are red, green, and blue.
|
||||
* This RGB color cube displays smooth transitions between these colors.
|
||||
*/
|
||||
|
||||
float xmag, ymag = 0;
|
||||
float newXmag, newYmag = 0;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
colorMode(RGB, 1);
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(0.5f);
|
||||
|
||||
pushMatrix();
|
||||
|
||||
translate(width/2, height/2, -30);
|
||||
|
||||
newXmag = mouseX/PApplet.parseFloat(width) * TWO_PI;
|
||||
newYmag = mouseY/PApplet.parseFloat(height) * TWO_PI;
|
||||
|
||||
float diff = xmag-newXmag;
|
||||
if (abs(diff) > 0.01f) { xmag -= diff/4.0f; }
|
||||
|
||||
diff = ymag-newYmag;
|
||||
if (abs(diff) > 0.01f) { ymag -= diff/4.0f; }
|
||||
|
||||
rotateX(-ymag);
|
||||
rotateY(-xmag);
|
||||
|
||||
scale(90);
|
||||
beginShape(QUADS);
|
||||
|
||||
fill(0, 1, 1); vertex(-1, 1, 1);
|
||||
fill(1, 1, 1); vertex( 1, 1, 1);
|
||||
fill(1, 0, 1); vertex( 1, -1, 1);
|
||||
fill(0, 0, 1); vertex(-1, -1, 1);
|
||||
|
||||
fill(1, 1, 1); vertex( 1, 1, 1);
|
||||
fill(1, 1, 0); vertex( 1, 1, -1);
|
||||
fill(1, 0, 0); vertex( 1, -1, -1);
|
||||
fill(1, 0, 1); vertex( 1, -1, 1);
|
||||
|
||||
fill(1, 1, 0); vertex( 1, 1, -1);
|
||||
fill(0, 1, 0); vertex(-1, 1, -1);
|
||||
fill(0, 0, 0); vertex(-1, -1, -1);
|
||||
fill(1, 0, 0); vertex( 1, -1, -1);
|
||||
|
||||
fill(0, 1, 0); vertex(-1, 1, -1);
|
||||
fill(0, 1, 1); vertex(-1, 1, 1);
|
||||
fill(0, 0, 1); vertex(-1, -1, 1);
|
||||
fill(0, 0, 0); vertex(-1, -1, -1);
|
||||
|
||||
fill(0, 1, 0); vertex(-1, 1, -1);
|
||||
fill(1, 1, 0); vertex( 1, 1, -1);
|
||||
fill(1, 1, 1); vertex( 1, 1, 1);
|
||||
fill(0, 1, 1); vertex(-1, 1, 1);
|
||||
|
||||
fill(0, 0, 0); vertex(-1, -1, -1);
|
||||
fill(1, 0, 0); vertex( 1, -1, -1);
|
||||
fill(1, 0, 1); vertex( 1, -1, 1);
|
||||
fill(0, 0, 1); vertex(-1, -1, 1);
|
||||
|
||||
endShape();
|
||||
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "RGBCube" });
|
||||
}
|
||||
}
|
||||
74
java/examples/3D/Form/RGBCube/applet/RGBCube.pde
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* RGB Cube.
|
||||
*
|
||||
* The three primary colors of the additive color model are red, green, and blue.
|
||||
* This RGB color cube displays smooth transitions between these colors.
|
||||
*/
|
||||
|
||||
float xmag, ymag = 0;
|
||||
float newXmag, newYmag = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
colorMode(RGB, 1);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0.5);
|
||||
|
||||
pushMatrix();
|
||||
|
||||
translate(width/2, height/2, -30);
|
||||
|
||||
newXmag = mouseX/float(width) * TWO_PI;
|
||||
newYmag = mouseY/float(height) * TWO_PI;
|
||||
|
||||
float diff = xmag-newXmag;
|
||||
if (abs(diff) > 0.01) { xmag -= diff/4.0; }
|
||||
|
||||
diff = ymag-newYmag;
|
||||
if (abs(diff) > 0.01) { ymag -= diff/4.0; }
|
||||
|
||||
rotateX(-ymag);
|
||||
rotateY(-xmag);
|
||||
|
||||
scale(90);
|
||||
beginShape(QUADS);
|
||||
|
||||
fill(0, 1, 1); vertex(-1, 1, 1);
|
||||
fill(1, 1, 1); vertex( 1, 1, 1);
|
||||
fill(1, 0, 1); vertex( 1, -1, 1);
|
||||
fill(0, 0, 1); vertex(-1, -1, 1);
|
||||
|
||||
fill(1, 1, 1); vertex( 1, 1, 1);
|
||||
fill(1, 1, 0); vertex( 1, 1, -1);
|
||||
fill(1, 0, 0); vertex( 1, -1, -1);
|
||||
fill(1, 0, 1); vertex( 1, -1, 1);
|
||||
|
||||
fill(1, 1, 0); vertex( 1, 1, -1);
|
||||
fill(0, 1, 0); vertex(-1, 1, -1);
|
||||
fill(0, 0, 0); vertex(-1, -1, -1);
|
||||
fill(1, 0, 0); vertex( 1, -1, -1);
|
||||
|
||||
fill(0, 1, 0); vertex(-1, 1, -1);
|
||||
fill(0, 1, 1); vertex(-1, 1, 1);
|
||||
fill(0, 0, 1); vertex(-1, -1, 1);
|
||||
fill(0, 0, 0); vertex(-1, -1, -1);
|
||||
|
||||
fill(0, 1, 0); vertex(-1, 1, -1);
|
||||
fill(1, 1, 0); vertex( 1, 1, -1);
|
||||
fill(1, 1, 1); vertex( 1, 1, 1);
|
||||
fill(0, 1, 1); vertex(-1, 1, 1);
|
||||
|
||||
fill(0, 0, 0); vertex(-1, -1, -1);
|
||||
fill(1, 0, 0); vertex( 1, -1, -1);
|
||||
fill(1, 0, 1); vertex( 1, -1, 1);
|
||||
fill(0, 0, 1); vertex(-1, -1, 1);
|
||||
|
||||
endShape();
|
||||
|
||||
popMatrix();
|
||||
}
|
||||
BIN
java/examples/3D/Form/RGBCube/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
162
java/examples/3D/Form/RunAmuck/Legs.pde
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Legs class
|
||||
* By Ira Greenberg <br />
|
||||
* Processing for Flash Developers,
|
||||
* Friends of ED, 2009
|
||||
*/
|
||||
|
||||
class Legs {
|
||||
// Instance properties with default values
|
||||
float x = 0, y = 0, z = 0, w = 150, ht = 125;
|
||||
color col = #77AA22;
|
||||
// Advanced properties
|
||||
float detailW = w/6.0;
|
||||
float detailHt = ht/8.0;
|
||||
float shoeBulge = detailHt*2.0;
|
||||
float legGap = w/7.0;
|
||||
|
||||
// Dynamics properties
|
||||
float velocity = .02, stepL, stepR, stepRate = random(10, 50);
|
||||
float speedX = 1.0, speedZ, spring, damping = .5, theta;
|
||||
|
||||
// Default constructor
|
||||
Legs() {
|
||||
}
|
||||
|
||||
// Standard constructor
|
||||
Legs(float x, float z, float w, float ht, color col) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
this.ht = ht;
|
||||
this.col = col;
|
||||
fill(col);
|
||||
detailW = w/6.0;
|
||||
detailHt = ht/8.0;
|
||||
shoeBulge = detailHt*2.0;
|
||||
legGap = w/7.0;
|
||||
speedX = random(-speedX, speedX);
|
||||
}
|
||||
|
||||
// Advanced constructor
|
||||
Legs(float x, float z, float w, float ht, color col, float detailW,
|
||||
float detailHt, float shoeBulge, float legGap) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
this.ht = ht;
|
||||
this.col = col;
|
||||
this.detailW = detailW;
|
||||
this.detailHt = detailHt;
|
||||
this.shoeBulge = shoeBulge;
|
||||
this.legGap = legGap;
|
||||
speedX = random(-speedX, speedX);
|
||||
}
|
||||
|
||||
// Draw legs
|
||||
void create() {
|
||||
fill(col);
|
||||
float footWidth = (w - legGap)/2;
|
||||
beginShape();
|
||||
vertex(x - w/2, y - ht, z);
|
||||
vertex(x - w/2, y - ht + detailHt, z);
|
||||
vertex(x - w/2 + detailW, y - ht + detailHt, z);
|
||||
// left foot
|
||||
vertex(x - w/2 + detailW, y + stepL, z);
|
||||
curveVertex(x - w/2 + detailW, y + stepL, z);
|
||||
curveVertex(x - w/2 + detailW, y + stepL, z);
|
||||
curveVertex(x - w/2 + detailW - shoeBulge, y + detailHt/2 + stepL, z);
|
||||
curveVertex(x - w/2, y + detailHt + stepL, z);
|
||||
curveVertex(x - w/2, y + detailHt + stepL, z);
|
||||
vertex(x - w/2 + footWidth, y + detailHt + stepL*.9, z);
|
||||
// end left foot
|
||||
vertex(x - w/2 + footWidth + legGap/2, y - ht + detailHt, z);
|
||||
vertex(x - w/2 + footWidth + legGap/2, y - ht + detailHt, z);
|
||||
// right foot
|
||||
vertex(x - w/2 + footWidth + legGap, y + detailHt + stepR*.9, z);
|
||||
vertex(x + w/2, y + detailHt + stepR, z);
|
||||
curveVertex(x + w/2, y + detailHt + stepR, z);
|
||||
curveVertex(x + w/2, y + detailHt + stepR, z);
|
||||
curveVertex(x + w/2 - detailW + shoeBulge, y + detailHt/2 + stepR, z);
|
||||
curveVertex(x + w/2 - detailW, y + stepR, z);
|
||||
vertex(x + w/2 - detailW, y + stepR, z);
|
||||
// end right foot
|
||||
vertex(x + w/2 - detailW, y - ht + detailHt, z);
|
||||
vertex(x + w/2, y - ht + detailHt, z);
|
||||
vertex(x + w/2, y - ht, z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
|
||||
// Set advanced property values
|
||||
void setDetails(float detailW, float detailHt, float shoeBulge, float legGap) {
|
||||
this.detailW = detailW;
|
||||
this.detailHt = detailHt;
|
||||
this.shoeBulge = shoeBulge;
|
||||
this.legGap = legGap;
|
||||
}
|
||||
|
||||
// Make the legs step
|
||||
void step(float stepRate) {
|
||||
this.stepRate = stepRate;
|
||||
spring = ht/2.0;
|
||||
stepL = sin(theta)*spring;
|
||||
stepR = cos(theta)*spring;
|
||||
theta += radians(stepRate);
|
||||
}
|
||||
|
||||
// Alternative overloaded step method
|
||||
void step() {
|
||||
spring = ht/2.0;
|
||||
stepL = sin(theta)*spring;
|
||||
stepR = cos(theta)*spring;
|
||||
theta += radians(stepRate);
|
||||
}
|
||||
|
||||
|
||||
// Moves legs along x, y, z axes
|
||||
void move() {
|
||||
// Move legs along y-axis
|
||||
y = stepR*damping;
|
||||
|
||||
// Move legs along x-axis and
|
||||
// check for collision against frame edge
|
||||
x += speedX;
|
||||
if (screenX(x, y, z) > width) {
|
||||
speedX *= -1;
|
||||
}
|
||||
if (screenX(x, y, z) < 0) {
|
||||
speedX *= -1;
|
||||
}
|
||||
|
||||
// Move legs along z-axis based on speed of stepping
|
||||
// and check for collision against extremes
|
||||
speedZ = (stepRate*velocity);
|
||||
z += speedZ;
|
||||
if (z > 400) {
|
||||
z = 400;
|
||||
velocity *= -1;
|
||||
}
|
||||
if (z < -100) {
|
||||
z = -100;
|
||||
velocity *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
void setDynamics(float speedX, float spring, float damping) {
|
||||
this.speedX = speedX;
|
||||
this.spring = spring;
|
||||
this.damping = damping;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
45
java/examples/3D/Form/RunAmuck/RunAmuck.pde
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Run-Amuck
|
||||
* By Ira Greenberg <br />
|
||||
* Processing for Flash Developers,
|
||||
* Friends of ED, 2009
|
||||
*/
|
||||
|
||||
int count = 250;
|
||||
Legs[] legs = new Legs[count];
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
for (int i = 0; i < legs.length; i++) {
|
||||
legs[i] = new Legs(random(-10, 10), random(-50, 150), random(.5, 5),
|
||||
random(.5, 5), color(random(255), random(255), random(255)));
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width/2, height/2);
|
||||
noStroke();
|
||||
fill(35);
|
||||
|
||||
// Draw ground plane
|
||||
beginShape();
|
||||
vertex(-width*2, 0, -1000);
|
||||
vertex(width*2, 0, -1000);
|
||||
vertex(width/2, height/2, 400);
|
||||
vertex(-width/2, height/2, 400);
|
||||
endShape(CLOSE);
|
||||
|
||||
// Update and draw the legs
|
||||
for (int i = 0; i < legs.length; i++) {
|
||||
legs[i].create();
|
||||
// Set foot step rate
|
||||
legs[i].step(random(10, 50));
|
||||
// Move legs along x, y, z axes
|
||||
// z-movement dependent upon step rate
|
||||
legs[i].move();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
162
java/examples/3D/Form/RunAmuck/applet/Legs.pde
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Legs class
|
||||
* By Ira Greenberg <br />
|
||||
* Processing for Flash Developers,
|
||||
* Friends of ED, 2009
|
||||
*/
|
||||
|
||||
class Legs {
|
||||
// Instance properties with default values
|
||||
float x = 0, y = 0, z = 0, w = 150, ht = 125;
|
||||
color col = #77AA22;
|
||||
// Advanced properties
|
||||
float detailW = w/6.0;
|
||||
float detailHt = ht/8.0;
|
||||
float shoeBulge = detailHt*2.0;
|
||||
float legGap = w/7.0;
|
||||
|
||||
// Dynamics properties
|
||||
float velocity = .02, stepL, stepR, stepRate = random(10, 50);
|
||||
float speedX = 1.0, speedZ, spring, damping = .5, theta;
|
||||
|
||||
// Default constructor
|
||||
Legs() {
|
||||
}
|
||||
|
||||
// Standard constructor
|
||||
Legs(float x, float z, float w, float ht, color col) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
this.ht = ht;
|
||||
this.col = col;
|
||||
fill(col);
|
||||
detailW = w/6.0;
|
||||
detailHt = ht/8.0;
|
||||
shoeBulge = detailHt*2.0;
|
||||
legGap = w/7.0;
|
||||
speedX = random(-speedX, speedX);
|
||||
}
|
||||
|
||||
// Advanced constructor
|
||||
Legs(float x, float z, float w, float ht, color col, float detailW,
|
||||
float detailHt, float shoeBulge, float legGap) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
this.ht = ht;
|
||||
this.col = col;
|
||||
this.detailW = detailW;
|
||||
this.detailHt = detailHt;
|
||||
this.shoeBulge = shoeBulge;
|
||||
this.legGap = legGap;
|
||||
speedX = random(-speedX, speedX);
|
||||
}
|
||||
|
||||
// Draw legs
|
||||
void create() {
|
||||
fill(col);
|
||||
float footWidth = (w - legGap)/2;
|
||||
beginShape();
|
||||
vertex(x - w/2, y - ht, z);
|
||||
vertex(x - w/2, y - ht + detailHt, z);
|
||||
vertex(x - w/2 + detailW, y - ht + detailHt, z);
|
||||
// left foot
|
||||
vertex(x - w/2 + detailW, y + stepL, z);
|
||||
curveVertex(x - w/2 + detailW, y + stepL, z);
|
||||
curveVertex(x - w/2 + detailW, y + stepL, z);
|
||||
curveVertex(x - w/2 + detailW - shoeBulge, y + detailHt/2 + stepL, z);
|
||||
curveVertex(x - w/2, y + detailHt + stepL, z);
|
||||
curveVertex(x - w/2, y + detailHt + stepL, z);
|
||||
vertex(x - w/2 + footWidth, y + detailHt + stepL*.9, z);
|
||||
// end left foot
|
||||
vertex(x - w/2 + footWidth + legGap/2, y - ht + detailHt, z);
|
||||
vertex(x - w/2 + footWidth + legGap/2, y - ht + detailHt, z);
|
||||
// right foot
|
||||
vertex(x - w/2 + footWidth + legGap, y + detailHt + stepR*.9, z);
|
||||
vertex(x + w/2, y + detailHt + stepR, z);
|
||||
curveVertex(x + w/2, y + detailHt + stepR, z);
|
||||
curveVertex(x + w/2, y + detailHt + stepR, z);
|
||||
curveVertex(x + w/2 - detailW + shoeBulge, y + detailHt/2 + stepR, z);
|
||||
curveVertex(x + w/2 - detailW, y + stepR, z);
|
||||
vertex(x + w/2 - detailW, y + stepR, z);
|
||||
// end right foot
|
||||
vertex(x + w/2 - detailW, y - ht + detailHt, z);
|
||||
vertex(x + w/2, y - ht + detailHt, z);
|
||||
vertex(x + w/2, y - ht, z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
|
||||
// Set advanced property values
|
||||
void setDetails(float detailW, float detailHt, float shoeBulge, float legGap) {
|
||||
this.detailW = detailW;
|
||||
this.detailHt = detailHt;
|
||||
this.shoeBulge = shoeBulge;
|
||||
this.legGap = legGap;
|
||||
}
|
||||
|
||||
// Make the legs step
|
||||
void step(float stepRate) {
|
||||
this.stepRate = stepRate;
|
||||
spring = ht/2.0;
|
||||
stepL = sin(theta)*spring;
|
||||
stepR = cos(theta)*spring;
|
||||
theta += radians(stepRate);
|
||||
}
|
||||
|
||||
// Alternative overloaded step method
|
||||
void step() {
|
||||
spring = ht/2.0;
|
||||
stepL = sin(theta)*spring;
|
||||
stepR = cos(theta)*spring;
|
||||
theta += radians(stepRate);
|
||||
}
|
||||
|
||||
|
||||
// Moves legs along x, y, z axes
|
||||
void move() {
|
||||
// Move legs along y-axis
|
||||
y = stepR*damping;
|
||||
|
||||
// Move legs along x-axis and
|
||||
// check for collision against frame edge
|
||||
x += speedX;
|
||||
if (screenX(x, y, z) > width) {
|
||||
speedX *= -1;
|
||||
}
|
||||
if (screenX(x, y, z) < 0) {
|
||||
speedX *= -1;
|
||||
}
|
||||
|
||||
// Move legs along z-axis based on speed of stepping
|
||||
// and check for collision against extremes
|
||||
speedZ = (stepRate*velocity);
|
||||
z += speedZ;
|
||||
if (z > 400) {
|
||||
z = 400;
|
||||
velocity *= -1;
|
||||
}
|
||||
if (z < -100) {
|
||||
z = -100;
|
||||
velocity *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
void setDynamics(float speedX, float spring, float damping) {
|
||||
this.speedX = speedX;
|
||||
this.spring = spring;
|
||||
this.damping = damping;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
228
java/examples/3D/Form/RunAmuck/applet/RunAmuck.java
Normal file
@@ -0,0 +1,228 @@
|
||||
import processing.core.*;
|
||||
import processing.xml.*;
|
||||
|
||||
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 RunAmuck extends PApplet {
|
||||
|
||||
/**
|
||||
* Run-Amuck
|
||||
* By Ira Greenberg <br />
|
||||
* Processing for Flash Developers,
|
||||
* Friends of ED, 2009
|
||||
*/
|
||||
|
||||
int count = 250;
|
||||
Legs[] legs = new Legs[count];
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
for (int i = 0; i < legs.length; i++) {
|
||||
legs[i] = new Legs(random(-10, 10), random(-50, 150), random(.5f, 5),
|
||||
random(.5f, 5), color(random(255), random(255), random(255)));
|
||||
}
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(0);
|
||||
translate(width/2, height/2);
|
||||
noStroke();
|
||||
fill(35);
|
||||
|
||||
// Draw ground plane
|
||||
beginShape();
|
||||
vertex(-width*2, 0, -1000);
|
||||
vertex(width*2, 0, -1000);
|
||||
vertex(width/2, height/2, 400);
|
||||
vertex(-width/2, height/2, 400);
|
||||
endShape(CLOSE);
|
||||
|
||||
// Update and draw the legs
|
||||
for (int i = 0; i < legs.length; i++) {
|
||||
legs[i].create();
|
||||
// Set foot step rate
|
||||
legs[i].step(random(10, 50));
|
||||
// Move legs along x, y, z axes
|
||||
// z-movement dependent upon step rate
|
||||
legs[i].move();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Legs class
|
||||
* By Ira Greenberg <br />
|
||||
* Processing for Flash Developers,
|
||||
* Friends of ED, 2009
|
||||
*/
|
||||
|
||||
class Legs {
|
||||
// Instance properties with default values
|
||||
float x = 0, y = 0, z = 0, w = 150, ht = 125;
|
||||
int col = 0xff77AA22;
|
||||
// Advanced properties
|
||||
float detailW = w/6.0f;
|
||||
float detailHt = ht/8.0f;
|
||||
float shoeBulge = detailHt*2.0f;
|
||||
float legGap = w/7.0f;
|
||||
|
||||
// Dynamics properties
|
||||
float velocity = .02f, stepL, stepR, stepRate = random(10, 50);
|
||||
float speedX = 1.0f, speedZ, spring, damping = .5f, theta;
|
||||
|
||||
// Default constructor
|
||||
Legs() {
|
||||
}
|
||||
|
||||
// Standard constructor
|
||||
Legs(float x, float z, float w, float ht, int col) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
this.ht = ht;
|
||||
this.col = col;
|
||||
fill(col);
|
||||
detailW = w/6.0f;
|
||||
detailHt = ht/8.0f;
|
||||
shoeBulge = detailHt*2.0f;
|
||||
legGap = w/7.0f;
|
||||
speedX = random(-speedX, speedX);
|
||||
}
|
||||
|
||||
// Advanced constructor
|
||||
Legs(float x, float z, float w, float ht, int col, float detailW,
|
||||
float detailHt, float shoeBulge, float legGap) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
this.ht = ht;
|
||||
this.col = col;
|
||||
this.detailW = detailW;
|
||||
this.detailHt = detailHt;
|
||||
this.shoeBulge = shoeBulge;
|
||||
this.legGap = legGap;
|
||||
speedX = random(-speedX, speedX);
|
||||
}
|
||||
|
||||
// Draw legs
|
||||
public void create() {
|
||||
fill(col);
|
||||
float footWidth = (w - legGap)/2;
|
||||
beginShape();
|
||||
vertex(x - w/2, y - ht, z);
|
||||
vertex(x - w/2, y - ht + detailHt, z);
|
||||
vertex(x - w/2 + detailW, y - ht + detailHt, z);
|
||||
// left foot
|
||||
vertex(x - w/2 + detailW, y + stepL, z);
|
||||
curveVertex(x - w/2 + detailW, y + stepL, z);
|
||||
curveVertex(x - w/2 + detailW, y + stepL, z);
|
||||
curveVertex(x - w/2 + detailW - shoeBulge, y + detailHt/2 + stepL, z);
|
||||
curveVertex(x - w/2, y + detailHt + stepL, z);
|
||||
curveVertex(x - w/2, y + detailHt + stepL, z);
|
||||
vertex(x - w/2 + footWidth, y + detailHt + stepL*.9f, z);
|
||||
// end left foot
|
||||
vertex(x - w/2 + footWidth + legGap/2, y - ht + detailHt, z);
|
||||
vertex(x - w/2 + footWidth + legGap/2, y - ht + detailHt, z);
|
||||
// right foot
|
||||
vertex(x - w/2 + footWidth + legGap, y + detailHt + stepR*.9f, z);
|
||||
vertex(x + w/2, y + detailHt + stepR, z);
|
||||
curveVertex(x + w/2, y + detailHt + stepR, z);
|
||||
curveVertex(x + w/2, y + detailHt + stepR, z);
|
||||
curveVertex(x + w/2 - detailW + shoeBulge, y + detailHt/2 + stepR, z);
|
||||
curveVertex(x + w/2 - detailW, y + stepR, z);
|
||||
vertex(x + w/2 - detailW, y + stepR, z);
|
||||
// end right foot
|
||||
vertex(x + w/2 - detailW, y - ht + detailHt, z);
|
||||
vertex(x + w/2, y - ht + detailHt, z);
|
||||
vertex(x + w/2, y - ht, z);
|
||||
endShape(CLOSE);
|
||||
}
|
||||
|
||||
// Set advanced property values
|
||||
public void setDetails(float detailW, float detailHt, float shoeBulge, float legGap) {
|
||||
this.detailW = detailW;
|
||||
this.detailHt = detailHt;
|
||||
this.shoeBulge = shoeBulge;
|
||||
this.legGap = legGap;
|
||||
}
|
||||
|
||||
// Make the legs step
|
||||
public void step(float stepRate) {
|
||||
this.stepRate = stepRate;
|
||||
spring = ht/2.0f;
|
||||
stepL = sin(theta)*spring;
|
||||
stepR = cos(theta)*spring;
|
||||
theta += radians(stepRate);
|
||||
}
|
||||
|
||||
// Alternative overloaded step method
|
||||
public void step() {
|
||||
spring = ht/2.0f;
|
||||
stepL = sin(theta)*spring;
|
||||
stepR = cos(theta)*spring;
|
||||
theta += radians(stepRate);
|
||||
}
|
||||
|
||||
|
||||
// Moves legs along x, y, z axes
|
||||
public void move() {
|
||||
// Move legs along y-axis
|
||||
y = stepR*damping;
|
||||
|
||||
// Move legs along x-axis and
|
||||
// check for collision against frame edge
|
||||
x += speedX;
|
||||
if (screenX(x, y, z) > width) {
|
||||
speedX *= -1;
|
||||
}
|
||||
if (screenX(x, y, z) < 0) {
|
||||
speedX *= -1;
|
||||
}
|
||||
|
||||
// Move legs along z-axis based on speed of stepping
|
||||
// and check for collision against extremes
|
||||
speedZ = (stepRate*velocity);
|
||||
z += speedZ;
|
||||
if (z > 400) {
|
||||
z = 400;
|
||||
velocity *= -1;
|
||||
}
|
||||
if (z < -100) {
|
||||
z = -100;
|
||||
velocity *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDynamics(float speedX, float spring, float damping) {
|
||||
this.speedX = speedX;
|
||||
this.spring = spring;
|
||||
this.damping = damping;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "--present", "--bgcolor=#666666", "--hide-stop", "RunAmuck" });
|
||||
}
|
||||
}
|
||||
45
java/examples/3D/Form/RunAmuck/applet/RunAmuck.pde
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Run-Amuck
|
||||
* By Ira Greenberg <br />
|
||||
* Processing for Flash Developers,
|
||||
* Friends of ED, 2009
|
||||
*/
|
||||
|
||||
int count = 250;
|
||||
Legs[] legs = new Legs[count];
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
for (int i = 0; i < legs.length; i++) {
|
||||
legs[i] = new Legs(random(-10, 10), random(-50, 150), random(.5, 5),
|
||||
random(.5, 5), color(random(255), random(255), random(255)));
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width/2, height/2);
|
||||
noStroke();
|
||||
fill(35);
|
||||
|
||||
// Draw ground plane
|
||||
beginShape();
|
||||
vertex(-width*2, 0, -1000);
|
||||
vertex(width*2, 0, -1000);
|
||||
vertex(width/2, height/2, 400);
|
||||
vertex(-width/2, height/2, 400);
|
||||
endShape(CLOSE);
|
||||
|
||||
// Update and draw the legs
|
||||
for (int i = 0; i < legs.length; i++) {
|
||||
legs[i].create();
|
||||
// Set foot step rate
|
||||
legs[i].step(random(10, 50));
|
||||
// Move legs along x, y, z axes
|
||||
// z-movement dependent upon step rate
|
||||
legs[i].move();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
java/examples/3D/Form/RunAmuck/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
116
java/examples/3D/Form/ShapeTransform/ShapeTransform.pde
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Shape Transform
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* Illustrates the geometric relationship
|
||||
* between Cube, Pyramid, Cone and
|
||||
* Cylinder 3D primitives.
|
||||
*
|
||||
* Instructions:<br />
|
||||
* Up Arrow - increases points<br />
|
||||
* Down Arrow - decreases points<br />
|
||||
* 'p' key toggles between cube/pyramid<br />
|
||||
*/
|
||||
|
||||
int pts = 4;
|
||||
float angle = 0;
|
||||
float radius = 99;
|
||||
float cylinderLength = 95;
|
||||
|
||||
//vertices
|
||||
PVector vertices[][];
|
||||
boolean isPyramid = false;
|
||||
|
||||
float angleInc;
|
||||
|
||||
void setup(){
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
angleInc = PI/300.0;
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(170, 95, 95);
|
||||
lights();
|
||||
fill(255, 200, 200);
|
||||
translate(width/2, height/2);
|
||||
rotateX(frameCount * angleInc);
|
||||
rotateY(frameCount * angleInc);
|
||||
rotateZ(frameCount * angleInc);
|
||||
|
||||
// initialize vertex arrays
|
||||
vertices = new PVector[2][pts+1];
|
||||
|
||||
// fill arrays
|
||||
for (int i = 0; i < 2; i++){
|
||||
angle = 0;
|
||||
for(int j = 0; j <= pts; j++){
|
||||
vertices[i][j] = new PVector();
|
||||
if (isPyramid){
|
||||
if (i==1){
|
||||
vertices[i][j].x = 0;
|
||||
vertices[i][j].y = 0;
|
||||
}
|
||||
else {
|
||||
vertices[i][j].x = cos(radians(angle)) * radius;
|
||||
vertices[i][j].y = sin(radians(angle)) * radius;
|
||||
}
|
||||
}
|
||||
else {
|
||||
vertices[i][j].x = cos(radians(angle)) * radius;
|
||||
vertices[i][j].y = sin(radians(angle)) * radius;
|
||||
}
|
||||
vertices[i][j].z = cylinderLength;
|
||||
// the .0 after the 360 is critical
|
||||
angle += 360.0/pts;
|
||||
}
|
||||
cylinderLength *= -1;
|
||||
}
|
||||
|
||||
// draw cylinder tube
|
||||
beginShape(QUAD_STRIP);
|
||||
for(int j = 0; j <= pts; j++){
|
||||
vertex(vertices[0][j].x, vertices[0][j].y, vertices[0][j].z);
|
||||
vertex(vertices[1][j].x, vertices[1][j].y, vertices[1][j].z);
|
||||
}
|
||||
endShape();
|
||||
|
||||
//draw cylinder ends
|
||||
for (int i = 0; i < 2; i++){
|
||||
beginShape();
|
||||
for(int j = 0; j < pts; j++){
|
||||
vertex(vertices[i][j].x, vertices[i][j].y, vertices[i][j].z);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
up/down arrow keys control
|
||||
polygon detail.
|
||||
*/
|
||||
void keyPressed(){
|
||||
if(key == CODED) {
|
||||
// pts
|
||||
if (keyCode == UP) {
|
||||
if (pts < 90){
|
||||
pts++;
|
||||
}
|
||||
}
|
||||
else if (keyCode == DOWN) {
|
||||
if (pts > 4){
|
||||
pts--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (key =='p'){
|
||||
if (isPyramid){
|
||||
isPyramid = false;
|
||||
}
|
||||
else {
|
||||
isPyramid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
147
java/examples/3D/Form/ShapeTransform/applet/ShapeTransform.java
Normal file
@@ -0,0 +1,147 @@
|
||||
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 ShapeTransform extends PApplet {
|
||||
|
||||
/**
|
||||
* Shape Transform
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* Illustrates the geometric relationship
|
||||
* between Cube, Pyramid, Cone and
|
||||
* Cylinder 3D primitives.
|
||||
*
|
||||
* Instructions:
|
||||
* Up Arrow - increases points
|
||||
* Down Arrow - decreases points
|
||||
* 'p' key toggles between cube/pyramid
|
||||
*/
|
||||
|
||||
int pts = 7;
|
||||
float angle = 0;
|
||||
float radius = 89;
|
||||
float cylinderLength = 85;
|
||||
|
||||
Point3D vertices[][];
|
||||
boolean isPyramid = false;
|
||||
|
||||
public void setup(){
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
background(102);
|
||||
lights();
|
||||
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(frameCount * 0.006f);
|
||||
rotateY(frameCount * 0.006f);
|
||||
rotateZ(frameCount * 0.006f);
|
||||
|
||||
// initialize point arrays
|
||||
vertices = new Point3D[2][pts+1];
|
||||
|
||||
// fill arrays
|
||||
for (int i = 0; i < 2; i++){
|
||||
angle = 0;
|
||||
for(int j = 0; j <= pts; j++){
|
||||
vertices[i][j] = new Point3D();
|
||||
if (isPyramid){
|
||||
if (i==1){
|
||||
vertices[i][j].x = 0;
|
||||
vertices[i][j].y = 0;
|
||||
}
|
||||
else {
|
||||
vertices[i][j].x = cos(radians(angle))*radius;
|
||||
vertices[i][j].y = sin(radians(angle))*radius;
|
||||
}
|
||||
}
|
||||
else {
|
||||
vertices[i][j].x = cos(radians(angle))*radius;
|
||||
vertices[i][j].y = sin(radians(angle))*radius;
|
||||
}
|
||||
vertices[i][j].z = cylinderLength;
|
||||
// the .0 after the 360 is critical
|
||||
angle += 360.0f/pts;
|
||||
}
|
||||
cylinderLength*=-1;
|
||||
}
|
||||
|
||||
// draw cylinder tube
|
||||
beginShape(QUAD_STRIP);
|
||||
for (int j = 0; j <= pts; j++){
|
||||
vertex(vertices[0][j].x, vertices[0][j].y, vertices[0][j].z);
|
||||
vertex(vertices[1][j].x, vertices[1][j].y, vertices[1][j].z);
|
||||
}
|
||||
endShape();
|
||||
|
||||
//draw cylinder ends
|
||||
for (int i = 0; i < 2; i++){
|
||||
beginShape();
|
||||
for (int j = 0; j < pts; j++){
|
||||
vertex(vertices[i][j].x, vertices[i][j].y, vertices[i][j].z);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
up/down arrow keys control
|
||||
polygon detail.
|
||||
*/
|
||||
public void keyPressed(){
|
||||
if(key == CODED) {
|
||||
// pts
|
||||
if (keyCode == UP) {
|
||||
if (pts<90){
|
||||
pts++;
|
||||
}
|
||||
}
|
||||
else if (keyCode == DOWN) {
|
||||
if (pts > 4){
|
||||
pts--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (key == 'p'){
|
||||
if (isPyramid){
|
||||
isPyramid=false;
|
||||
}
|
||||
else {
|
||||
isPyramid=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Point3D{
|
||||
float x, y, z;
|
||||
|
||||
// constructors
|
||||
Point3D(){
|
||||
}
|
||||
|
||||
Point3D(float x, float y, float z){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "ShapeTransform" });
|
||||
}
|
||||
}
|
||||
114
java/examples/3D/Form/ShapeTransform/applet/ShapeTransform.pde
Normal file
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Shape Transform
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* Illustrates the geometric relationship
|
||||
* between Cube, Pyramid, Cone and
|
||||
* Cylinder 3D primitives.
|
||||
*
|
||||
* Instructions:
|
||||
* Up Arrow - increases points
|
||||
* Down Arrow - decreases points
|
||||
* 'p' key toggles between cube/pyramid
|
||||
*/
|
||||
|
||||
int pts = 7;
|
||||
float angle = 0;
|
||||
float radius = 89;
|
||||
float cylinderLength = 85;
|
||||
|
||||
Point3D vertices[][];
|
||||
boolean isPyramid = false;
|
||||
|
||||
void setup(){
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(102);
|
||||
lights();
|
||||
|
||||
translate(width/2, height/2, 0);
|
||||
rotateX(frameCount * 0.006);
|
||||
rotateY(frameCount * 0.006);
|
||||
rotateZ(frameCount * 0.006);
|
||||
|
||||
// initialize point arrays
|
||||
vertices = new Point3D[2][pts+1];
|
||||
|
||||
// fill arrays
|
||||
for (int i = 0; i < 2; i++){
|
||||
angle = 0;
|
||||
for(int j = 0; j <= pts; j++){
|
||||
vertices[i][j] = new Point3D();
|
||||
if (isPyramid){
|
||||
if (i==1){
|
||||
vertices[i][j].x = 0;
|
||||
vertices[i][j].y = 0;
|
||||
}
|
||||
else {
|
||||
vertices[i][j].x = cos(radians(angle))*radius;
|
||||
vertices[i][j].y = sin(radians(angle))*radius;
|
||||
}
|
||||
}
|
||||
else {
|
||||
vertices[i][j].x = cos(radians(angle))*radius;
|
||||
vertices[i][j].y = sin(radians(angle))*radius;
|
||||
}
|
||||
vertices[i][j].z = cylinderLength;
|
||||
// the .0 after the 360 is critical
|
||||
angle += 360.0/pts;
|
||||
}
|
||||
cylinderLength*=-1;
|
||||
}
|
||||
|
||||
// draw cylinder tube
|
||||
beginShape(QUAD_STRIP);
|
||||
for (int j = 0; j <= pts; j++){
|
||||
vertex(vertices[0][j].x, vertices[0][j].y, vertices[0][j].z);
|
||||
vertex(vertices[1][j].x, vertices[1][j].y, vertices[1][j].z);
|
||||
}
|
||||
endShape();
|
||||
|
||||
//draw cylinder ends
|
||||
for (int i = 0; i < 2; i++){
|
||||
beginShape();
|
||||
for (int j = 0; j < pts; j++){
|
||||
vertex(vertices[i][j].x, vertices[i][j].y, vertices[i][j].z);
|
||||
}
|
||||
endShape(CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
up/down arrow keys control
|
||||
polygon detail.
|
||||
*/
|
||||
void keyPressed(){
|
||||
if(key == CODED) {
|
||||
// pts
|
||||
if (keyCode == UP) {
|
||||
if (pts<90){
|
||||
pts++;
|
||||
}
|
||||
}
|
||||
else if (keyCode == DOWN) {
|
||||
if (pts > 4){
|
||||
pts--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (key == 'p'){
|
||||
if (isPyramid){
|
||||
isPyramid=false;
|
||||
}
|
||||
else {
|
||||
isPyramid=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
BIN
java/examples/3D/Form/ShapeTransform/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
182
java/examples/3D/Form/Toroid/Toroid.pde
Normal file
@@ -0,0 +1,182 @@
|
||||
/**
|
||||
* Interactive Toroid
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* Illustrates the geometric relationship between Toroid, Sphere, and Helix
|
||||
* 3D primitives, as well as lathing principal.
|
||||
*
|
||||
* Instructions: <br />
|
||||
* UP arrow key pts++ <br />
|
||||
* DOWN arrow key pts-- <br />
|
||||
* LEFT arrow key segments-- <br />
|
||||
* RIGHT arrow key segments++ <br />
|
||||
* 'a' key toroid radius-- <br />
|
||||
* 's' key toroid radius++ <br />
|
||||
* 'z' key initial polygon radius-- <br />
|
||||
* 'x' key initial polygon radius++ <br />
|
||||
* 'w' key toggle wireframe/solid shading <br />
|
||||
* 'h' key toggle sphere/helix <br />
|
||||
*/
|
||||
|
||||
int pts = 40;
|
||||
float angle = 0;
|
||||
float radius = 60.0;
|
||||
|
||||
// lathe segments
|
||||
int segments = 60;
|
||||
float latheAngle = 0;
|
||||
float latheRadius = 100.0;
|
||||
|
||||
//vertices
|
||||
PVector vertices[], vertices2[];
|
||||
|
||||
// for shaded or wireframe rendering
|
||||
boolean isWireFrame = false;
|
||||
|
||||
// for optional helix
|
||||
boolean isHelix = false;
|
||||
float helixOffset = 5.0;
|
||||
|
||||
void setup(){
|
||||
size(640, 360, P3D);
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(50, 64, 42);
|
||||
// basic lighting setup
|
||||
lights();
|
||||
// 2 rendering styles
|
||||
// wireframe or solid
|
||||
if (isWireFrame){
|
||||
stroke(255, 255, 150);
|
||||
noFill();
|
||||
}
|
||||
else {
|
||||
noStroke();
|
||||
fill(150, 195, 125);
|
||||
}
|
||||
//center and spin toroid
|
||||
translate(width/2, height/2, -100);
|
||||
|
||||
rotateX(frameCount*PI/150);
|
||||
rotateY(frameCount*PI/170);
|
||||
rotateZ(frameCount*PI/90);
|
||||
|
||||
// initialize point arrays
|
||||
vertices = new PVector[pts+1];
|
||||
vertices2 = new PVector[pts+1];
|
||||
|
||||
// fill arrays
|
||||
for(int i=0; i<=pts; i++){
|
||||
vertices[i] = new PVector();
|
||||
vertices2[i] = new PVector();
|
||||
vertices[i].x = latheRadius + sin(radians(angle))*radius;
|
||||
if (isHelix){
|
||||
vertices[i].z = cos(radians(angle))*radius-(helixOffset*
|
||||
segments)/2;
|
||||
}
|
||||
else{
|
||||
vertices[i].z = cos(radians(angle))*radius;
|
||||
}
|
||||
angle+=360.0/pts;
|
||||
}
|
||||
|
||||
// draw toroid
|
||||
latheAngle = 0;
|
||||
for(int i=0; i<=segments; i++){
|
||||
beginShape(QUAD_STRIP);
|
||||
for(int j=0; j<=pts; j++){
|
||||
if (i>0){
|
||||
vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
|
||||
}
|
||||
vertices2[j].x = cos(radians(latheAngle))*vertices[j].x;
|
||||
vertices2[j].y = sin(radians(latheAngle))*vertices[j].x;
|
||||
vertices2[j].z = vertices[j].z;
|
||||
// optional helix offset
|
||||
if (isHelix){
|
||||
vertices[j].z+=helixOffset;
|
||||
}
|
||||
vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
|
||||
}
|
||||
// create extra rotation for helix
|
||||
if (isHelix){
|
||||
latheAngle+=720.0/segments;
|
||||
}
|
||||
else {
|
||||
latheAngle+=360.0/segments;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
left/right arrow keys control ellipse detail
|
||||
up/down arrow keys control segment detail.
|
||||
'a','s' keys control lathe radius
|
||||
'z','x' keys control ellipse radius
|
||||
'w' key toggles between wireframe and solid
|
||||
'h' key toggles between toroid and helix
|
||||
*/
|
||||
void keyPressed(){
|
||||
if(key == CODED) {
|
||||
// pts
|
||||
if (keyCode == UP) {
|
||||
if (pts<40){
|
||||
pts++;
|
||||
}
|
||||
}
|
||||
else if (keyCode == DOWN) {
|
||||
if (pts>3){
|
||||
pts--;
|
||||
}
|
||||
}
|
||||
// extrusion length
|
||||
if (keyCode == LEFT) {
|
||||
if (segments>3){
|
||||
segments--;
|
||||
}
|
||||
}
|
||||
else if (keyCode == RIGHT) {
|
||||
if (segments<80){
|
||||
segments++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// lathe radius
|
||||
if (key =='a'){
|
||||
if (latheRadius>0){
|
||||
latheRadius--;
|
||||
}
|
||||
}
|
||||
else if (key == 's'){
|
||||
latheRadius++;
|
||||
}
|
||||
// ellipse radius
|
||||
if (key =='z'){
|
||||
if (radius>10){
|
||||
radius--;
|
||||
}
|
||||
}
|
||||
else if (key == 'x'){
|
||||
radius++;
|
||||
}
|
||||
// wireframe
|
||||
if (key =='w'){
|
||||
if (isWireFrame){
|
||||
isWireFrame=false;
|
||||
}
|
||||
else {
|
||||
isWireFrame=true;
|
||||
}
|
||||
}
|
||||
// helix
|
||||
if (key =='h'){
|
||||
if (isHelix){
|
||||
isHelix=false;
|
||||
}
|
||||
else {
|
||||
isHelix=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
215
java/examples/3D/Form/Toroid/applet/Toroid.java
Normal file
@@ -0,0 +1,215 @@
|
||||
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 Toroid extends PApplet {
|
||||
|
||||
/**
|
||||
* Interactive Toroid
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* Illustrates the geometric relationship
|
||||
* between Toroid, Sphere, and Helix
|
||||
* 3D primitives, as well as lathing
|
||||
* principal.
|
||||
*
|
||||
* Instructions:
|
||||
* UP arrow key pts++;
|
||||
* DOWN arrow key pts--;
|
||||
* LEFT arrow key segments--;
|
||||
* RIGHT arrow key segments++;
|
||||
* 'a' key toroid radius--;
|
||||
* 's' key toroid radius++;
|
||||
* 'z' key initial polygon radius--;
|
||||
* 'x' key initial polygon radius++;
|
||||
* 'w' key toggle wireframe/solid shading
|
||||
* 'h' key toggle sphere/helix
|
||||
*/
|
||||
|
||||
|
||||
int pts = 40;
|
||||
float angle = 0;
|
||||
float radius = 40.0f;
|
||||
// Lathe segments
|
||||
int segments = 60;
|
||||
float latheAngle = 0;
|
||||
float latheRadius = 100.0f;
|
||||
// Vertices
|
||||
Point3D vertices[], vertices2[];
|
||||
// For shaded or wireframe rendering
|
||||
boolean isWireFrame = false;
|
||||
// For optional helix
|
||||
boolean isHelix = false;
|
||||
float helixOffset = 5.0f;
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
background(51);
|
||||
// Basic lighting setup
|
||||
lights();
|
||||
// Two rendering styles
|
||||
// Wireframe or solid
|
||||
if (isWireFrame){
|
||||
stroke(255);
|
||||
noFill();
|
||||
}
|
||||
else {
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
// Center and spin toroid
|
||||
translate(width/2, height/2, -100);
|
||||
|
||||
rotateX(frameCount*PI/150);
|
||||
rotateY(frameCount*PI/170);
|
||||
rotateZ(frameCount*PI/90);
|
||||
|
||||
// Initialize point arrays
|
||||
vertices = new Point3D[pts+1];
|
||||
vertices2 = new Point3D[pts+1];
|
||||
|
||||
// Fill arrays
|
||||
for(int i = 0; i <= pts; i++){
|
||||
vertices[i] = new Point3D();
|
||||
vertices2[i] = new Point3D();
|
||||
vertices[i].x = latheRadius + sin(radians(angle))*radius;
|
||||
if (isHelix){
|
||||
vertices[i].z = cos(radians(angle))*radius-(helixOffset*
|
||||
segments)/2;
|
||||
}
|
||||
else{
|
||||
vertices[i].z = cos(radians(angle))*radius;
|
||||
}
|
||||
angle+=360.0f/pts;
|
||||
}
|
||||
|
||||
// Draw toroid
|
||||
latheAngle = 0;
|
||||
for(int i = 0; i <= segments; i++){
|
||||
beginShape(QUAD_STRIP);
|
||||
for(int j = 0; j <= pts; j++){
|
||||
if (i > 0){
|
||||
vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
|
||||
}
|
||||
vertices2[j].x = cos(radians(latheAngle))*vertices[j].x;
|
||||
vertices2[j].y = sin(radians(latheAngle))*vertices[j].x;
|
||||
vertices2[j].z = vertices[j].z;
|
||||
// Optional helix offset
|
||||
if (isHelix){
|
||||
vertices[j].z+=helixOffset;
|
||||
}
|
||||
vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
|
||||
}
|
||||
// Create extra rotation for helix
|
||||
if (isHelix){
|
||||
latheAngle += 720.0f/segments;
|
||||
}
|
||||
else {
|
||||
latheAngle += 360.0f/segments;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
left/right arrow keys control ellipse detail
|
||||
up/down arrow keys control segment detail.
|
||||
'a','s' keys control lathe radius
|
||||
'z','x' keys control ellipse radius
|
||||
'w' key toggles between wireframe and solid
|
||||
'h' key toggles between toroid and helix
|
||||
*/
|
||||
public void keyPressed(){
|
||||
if(key == CODED) {
|
||||
// pts
|
||||
if (keyCode == UP) {
|
||||
if (pts < 40){
|
||||
pts++;
|
||||
}
|
||||
}
|
||||
else if (keyCode == DOWN) {
|
||||
if (pts > 3){
|
||||
pts--;
|
||||
}
|
||||
}
|
||||
// Extrusion length
|
||||
if (keyCode == LEFT) {
|
||||
if (segments > 3){
|
||||
segments--;
|
||||
}
|
||||
}
|
||||
else if (keyCode == RIGHT) {
|
||||
if (segments < 80){
|
||||
segments++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Lathe radius
|
||||
if (key =='a'){
|
||||
if (latheRadius > 0){
|
||||
latheRadius--;
|
||||
}
|
||||
}
|
||||
else if (key == 's'){
|
||||
latheRadius++;
|
||||
}
|
||||
// Ellipse radius
|
||||
if (key =='z'){
|
||||
if (radius > 10){
|
||||
radius--;
|
||||
}
|
||||
}
|
||||
else if (key == 'x'){
|
||||
radius++;
|
||||
}
|
||||
// Wireframe
|
||||
if (key == 'w'){
|
||||
if (isWireFrame){
|
||||
isWireFrame=false;
|
||||
}
|
||||
else {
|
||||
isWireFrame=true;
|
||||
}
|
||||
}
|
||||
// Helix
|
||||
if (key == 'h'){
|
||||
if (isHelix){
|
||||
isHelix=false;
|
||||
}
|
||||
else {
|
||||
isHelix=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Point3D{
|
||||
float x, y, z;
|
||||
|
||||
// constructors
|
||||
Point3D(){
|
||||
}
|
||||
|
||||
Point3D(float x, float y, float z){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Toroid" });
|
||||
}
|
||||
}
|
||||
182
java/examples/3D/Form/Toroid/applet/Toroid.pde
Normal file
@@ -0,0 +1,182 @@
|
||||
/**
|
||||
* Interactive Toroid
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* Illustrates the geometric relationship
|
||||
* between Toroid, Sphere, and Helix
|
||||
* 3D primitives, as well as lathing
|
||||
* principal.
|
||||
*
|
||||
* Instructions:
|
||||
* UP arrow key pts++;
|
||||
* DOWN arrow key pts--;
|
||||
* LEFT arrow key segments--;
|
||||
* RIGHT arrow key segments++;
|
||||
* 'a' key toroid radius--;
|
||||
* 's' key toroid radius++;
|
||||
* 'z' key initial polygon radius--;
|
||||
* 'x' key initial polygon radius++;
|
||||
* 'w' key toggle wireframe/solid shading
|
||||
* 'h' key toggle sphere/helix
|
||||
*/
|
||||
|
||||
|
||||
int pts = 40;
|
||||
float angle = 0;
|
||||
float radius = 40.0;
|
||||
// Lathe segments
|
||||
int segments = 60;
|
||||
float latheAngle = 0;
|
||||
float latheRadius = 100.0;
|
||||
// Vertices
|
||||
Point3D vertices[], vertices2[];
|
||||
// For shaded or wireframe rendering
|
||||
boolean isWireFrame = false;
|
||||
// For optional helix
|
||||
boolean isHelix = false;
|
||||
float helixOffset = 5.0;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(51);
|
||||
// Basic lighting setup
|
||||
lights();
|
||||
// Two rendering styles
|
||||
// Wireframe or solid
|
||||
if (isWireFrame){
|
||||
stroke(255);
|
||||
noFill();
|
||||
}
|
||||
else {
|
||||
noStroke();
|
||||
fill(204);
|
||||
}
|
||||
// Center and spin toroid
|
||||
translate(width/2, height/2, -100);
|
||||
|
||||
rotateX(frameCount*PI/150);
|
||||
rotateY(frameCount*PI/170);
|
||||
rotateZ(frameCount*PI/90);
|
||||
|
||||
// Initialize point arrays
|
||||
vertices = new Point3D[pts+1];
|
||||
vertices2 = new Point3D[pts+1];
|
||||
|
||||
// Fill arrays
|
||||
for(int i = 0; i <= pts; i++){
|
||||
vertices[i] = new Point3D();
|
||||
vertices2[i] = new Point3D();
|
||||
vertices[i].x = latheRadius + sin(radians(angle))*radius;
|
||||
if (isHelix){
|
||||
vertices[i].z = cos(radians(angle))*radius-(helixOffset*
|
||||
segments)/2;
|
||||
}
|
||||
else{
|
||||
vertices[i].z = cos(radians(angle))*radius;
|
||||
}
|
||||
angle+=360.0/pts;
|
||||
}
|
||||
|
||||
// Draw toroid
|
||||
latheAngle = 0;
|
||||
for(int i = 0; i <= segments; i++){
|
||||
beginShape(QUAD_STRIP);
|
||||
for(int j = 0; j <= pts; j++){
|
||||
if (i > 0){
|
||||
vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
|
||||
}
|
||||
vertices2[j].x = cos(radians(latheAngle))*vertices[j].x;
|
||||
vertices2[j].y = sin(radians(latheAngle))*vertices[j].x;
|
||||
vertices2[j].z = vertices[j].z;
|
||||
// Optional helix offset
|
||||
if (isHelix){
|
||||
vertices[j].z+=helixOffset;
|
||||
}
|
||||
vertex(vertices2[j].x, vertices2[j].y, vertices2[j].z);
|
||||
}
|
||||
// Create extra rotation for helix
|
||||
if (isHelix){
|
||||
latheAngle += 720.0/segments;
|
||||
}
|
||||
else {
|
||||
latheAngle += 360.0/segments;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
left/right arrow keys control ellipse detail
|
||||
up/down arrow keys control segment detail.
|
||||
'a','s' keys control lathe radius
|
||||
'z','x' keys control ellipse radius
|
||||
'w' key toggles between wireframe and solid
|
||||
'h' key toggles between toroid and helix
|
||||
*/
|
||||
void keyPressed(){
|
||||
if(key == CODED) {
|
||||
// pts
|
||||
if (keyCode == UP) {
|
||||
if (pts < 40){
|
||||
pts++;
|
||||
}
|
||||
}
|
||||
else if (keyCode == DOWN) {
|
||||
if (pts > 3){
|
||||
pts--;
|
||||
}
|
||||
}
|
||||
// Extrusion length
|
||||
if (keyCode == LEFT) {
|
||||
if (segments > 3){
|
||||
segments--;
|
||||
}
|
||||
}
|
||||
else if (keyCode == RIGHT) {
|
||||
if (segments < 80){
|
||||
segments++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Lathe radius
|
||||
if (key =='a'){
|
||||
if (latheRadius > 0){
|
||||
latheRadius--;
|
||||
}
|
||||
}
|
||||
else if (key == 's'){
|
||||
latheRadius++;
|
||||
}
|
||||
// Ellipse radius
|
||||
if (key =='z'){
|
||||
if (radius > 10){
|
||||
radius--;
|
||||
}
|
||||
}
|
||||
else if (key == 'x'){
|
||||
radius++;
|
||||
}
|
||||
// Wireframe
|
||||
if (key == 'w'){
|
||||
if (isWireFrame){
|
||||
isWireFrame=false;
|
||||
}
|
||||
else {
|
||||
isWireFrame=true;
|
||||
}
|
||||
}
|
||||
// Helix
|
||||
if (key == 'h'){
|
||||
if (isHelix){
|
||||
isHelix=false;
|
||||
}
|
||||
else {
|
||||
isHelix=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
java/examples/3D/Form/Toroid/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
67
java/examples/3D/Form/Vertices/Vertices.pde
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Vertices
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* Draw a cylinder centered on the y-axis, going down
|
||||
* from y=0 to y=height. The radius at the top can be
|
||||
* different from the radius at the bottom, and the
|
||||
* number of sides drawn is variable.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
lights();
|
||||
translate(width / 2, height / 2);
|
||||
rotateY(map(mouseX, 0, width, 0, PI));
|
||||
rotateZ(map(mouseY, 0, height, 0, -PI));
|
||||
noStroke();
|
||||
fill(255, 255, 255);
|
||||
translate(0, -40, 0);
|
||||
drawCylinder(10, 180, 200, 16); // Draw a mix between a cylinder and a cone
|
||||
//drawCylinder(70, 70, 120, 64); // Draw a cylinder
|
||||
//drawCylinder(0, 180, 200, 4); // Draw a pyramid
|
||||
}
|
||||
|
||||
void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {
|
||||
float angle = 0;
|
||||
float angleIncrement = TWO_PI / sides;
|
||||
beginShape(QUAD_STRIP);
|
||||
for (int i = 0; i < sides + 1; ++i) {
|
||||
vertex(topRadius*cos(angle), 0, topRadius*sin(angle));
|
||||
vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
|
||||
// If it is not a cone, draw the circular top cap
|
||||
if (topRadius != 0) {
|
||||
angle = 0;
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
// Center point
|
||||
vertex(0, 0, 0);
|
||||
for (int i = 0; i < sides + 1; i++) {
|
||||
vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
|
||||
// If it is not a cone, draw the circular bottom cap
|
||||
if (bottomRadius != 0) {
|
||||
angle = 0;
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
// Center point
|
||||
vertex(0, tall, 0);
|
||||
for (int i = 0; i < sides + 1; i++) {
|
||||
vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
87
java/examples/3D/Form/Vertices/applet/Vertices.java
Normal file
@@ -0,0 +1,87 @@
|
||||
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 Vertices extends PApplet {
|
||||
|
||||
/**
|
||||
* Vertices
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* Draw a cylinder centered on the y-axis, going down
|
||||
* from y=0 to y=height. The radius at the top can be
|
||||
* different from the radius at the bottom, and the
|
||||
* number of sides drawn is variable.
|
||||
*/
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(0);
|
||||
lights();
|
||||
translate(width / 2, height / 2);
|
||||
rotateY(map(mouseX, 0, width, 0, PI));
|
||||
rotateZ(map(mouseY, 0, height, 0, -PI));
|
||||
noStroke();
|
||||
fill(255, 255, 255);
|
||||
translate(0, -40, 0);
|
||||
drawCylinder(10, 180, 200, 16); // Draw a mix between a cylinder and a cone
|
||||
//drawCylinder(70, 70, 120, 64); // Draw a cylinder
|
||||
//drawCylinder(0, 180, 200, 4); // Draw a pyramid
|
||||
}
|
||||
|
||||
public void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {
|
||||
float angle = 0;
|
||||
float angleIncrement = TWO_PI / sides;
|
||||
beginShape(QUAD_STRIP);
|
||||
for (int i = 0; i < sides + 1; ++i) {
|
||||
vertex(topRadius*cos(angle), 0, topRadius*sin(angle));
|
||||
vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
|
||||
// If it is not a cone, draw the circular top cap
|
||||
if (topRadius != 0) {
|
||||
angle = 0;
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
// Center point
|
||||
vertex(0, 0, 0);
|
||||
for (int i = 0; i < sides + 1; i++) {
|
||||
vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
|
||||
// If it is not a cone, draw the circular bottom cap
|
||||
if (bottomRadius != 0) {
|
||||
angle = 0;
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
// Center point
|
||||
vertex(0, tall, 0);
|
||||
for (int i = 0; i < sides + 1; i++) {
|
||||
vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Vertices" });
|
||||
}
|
||||
}
|
||||
67
java/examples/3D/Form/Vertices/applet/Vertices.pde
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Vertices
|
||||
* by Simon Greenwold.
|
||||
*
|
||||
* Draw a cylinder centered on the y-axis, going down
|
||||
* from y=0 to y=height. The radius at the top can be
|
||||
* different from the radius at the bottom, and the
|
||||
* number of sides drawn is variable.
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
lights();
|
||||
translate(width / 2, height / 2);
|
||||
rotateY(map(mouseX, 0, width, 0, PI));
|
||||
rotateZ(map(mouseY, 0, height, 0, -PI));
|
||||
noStroke();
|
||||
fill(255, 255, 255);
|
||||
translate(0, -40, 0);
|
||||
drawCylinder(10, 180, 200, 16); // Draw a mix between a cylinder and a cone
|
||||
//drawCylinder(70, 70, 120, 64); // Draw a cylinder
|
||||
//drawCylinder(0, 180, 200, 4); // Draw a pyramid
|
||||
}
|
||||
|
||||
void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {
|
||||
float angle = 0;
|
||||
float angleIncrement = TWO_PI / sides;
|
||||
beginShape(QUAD_STRIP);
|
||||
for (int i = 0; i < sides + 1; ++i) {
|
||||
vertex(topRadius*cos(angle), 0, topRadius*sin(angle));
|
||||
vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
|
||||
// If it is not a cone, draw the circular top cap
|
||||
if (topRadius != 0) {
|
||||
angle = 0;
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
// Center point
|
||||
vertex(0, 0, 0);
|
||||
for (int i = 0; i < sides + 1; i++) {
|
||||
vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
|
||||
// If it is not a cone, draw the circular bottom cap
|
||||
if (bottomRadius != 0) {
|
||||
angle = 0;
|
||||
beginShape(TRIANGLE_FAN);
|
||||
|
||||
// Center point
|
||||
vertex(0, tall, 0);
|
||||
for (int i = 0; i < sides + 1; i++) {
|
||||
vertex(bottomRadius * cos(angle), tall, bottomRadius * sin(angle));
|
||||
angle += angleIncrement;
|
||||
}
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
BIN
java/examples/3D/Form/Vertices/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
43
java/examples/3D/Image/Explode/Explode.pde
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Explode
|
||||
* by Daniel Shiffman.
|
||||
*
|
||||
* Mouse horizontal location controls breaking apart of image and
|
||||
* Maps pixels from a 2D image into 3D space. Pixel brightness controls
|
||||
* translation along z axis.
|
||||
*/
|
||||
|
||||
PImage img; // The source image
|
||||
int cellsize = 2; // Dimensions of each cell in the grid
|
||||
int columns, rows; // Number of columns and rows in our system
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("eames.jpg"); // Load the image
|
||||
columns = img.width / cellsize; // Calculate # of columns
|
||||
rows = img.height / cellsize; // Calculate # of rows
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
// Begin loop for columns
|
||||
for ( int i = 0; i < columns; i++) {
|
||||
// Begin loop for rows
|
||||
for ( int j = 0; j < rows; j++) {
|
||||
int x = i*cellsize + cellsize/2; // x position
|
||||
int y = j*cellsize + cellsize/2; // y position
|
||||
int loc = x + y*img.width; // Pixel array location
|
||||
color c = img.pixels[loc]; // Grab the color
|
||||
// Calculate a z position as a function of mouseX and pixel brightness
|
||||
float z = (mouseX / float(width)) * brightness(img.pixels[loc]) - 20.0;
|
||||
// Translate to the location, set fill and stroke, and draw the rect
|
||||
pushMatrix();
|
||||
translate(x + 200, y + 100, z);
|
||||
fill(c, 204);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
rect(0, 0, cellsize, cellsize);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
63
java/examples/3D/Image/Explode/applet/Explode.java
Normal file
@@ -0,0 +1,63 @@
|
||||
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 Explode extends PApplet {
|
||||
|
||||
/**
|
||||
* Explode
|
||||
* by Daniel Shiffman.
|
||||
*
|
||||
* Mouse horizontal location controls breaking apart of image and
|
||||
* Maps pixels from a 2D image into 3D space. Pixel brightness controls
|
||||
* translation along z axis.
|
||||
*/
|
||||
|
||||
PImage img; // The source image
|
||||
int cellsize = 2; // Dimensions of each cell in the grid
|
||||
int columns, rows; // Number of columns and rows in our system
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("eames.jpg"); // Load the image
|
||||
columns = img.width / cellsize; // Calculate # of columns
|
||||
rows = img.height / cellsize; // Calculate # of rows
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(0);
|
||||
// Begin loop for columns
|
||||
for ( int i = 0; i < columns; i++) {
|
||||
// Begin loop for rows
|
||||
for ( int j = 0; j < rows; j++) {
|
||||
int x = i*cellsize + cellsize/2; // x position
|
||||
int y = j*cellsize + cellsize/2; // y position
|
||||
int loc = x + y*img.width; // Pixel array location
|
||||
int c = img.pixels[loc]; // Grab the color
|
||||
// Calculate a z position as a function of mouseX and pixel brightness
|
||||
float z = (mouseX / PApplet.parseFloat(width)) * brightness(img.pixels[loc]) - 20.0f;
|
||||
// Translate to the location, set fill and stroke, and draw the rect
|
||||
pushMatrix();
|
||||
translate(x + 200, y + 100, z);
|
||||
fill(c, 204);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
rect(0, 0, cellsize, cellsize);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Explode" });
|
||||
}
|
||||
}
|
||||
43
java/examples/3D/Image/Explode/applet/Explode.pde
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Explode
|
||||
* by Daniel Shiffman.
|
||||
*
|
||||
* Mouse horizontal location controls breaking apart of image and
|
||||
* Maps pixels from a 2D image into 3D space. Pixel brightness controls
|
||||
* translation along z axis.
|
||||
*/
|
||||
|
||||
PImage img; // The source image
|
||||
int cellsize = 2; // Dimensions of each cell in the grid
|
||||
int columns, rows; // Number of columns and rows in our system
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("eames.jpg"); // Load the image
|
||||
columns = img.width / cellsize; // Calculate # of columns
|
||||
rows = img.height / cellsize; // Calculate # of rows
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
// Begin loop for columns
|
||||
for ( int i = 0; i < columns; i++) {
|
||||
// Begin loop for rows
|
||||
for ( int j = 0; j < rows; j++) {
|
||||
int x = i*cellsize + cellsize/2; // x position
|
||||
int y = j*cellsize + cellsize/2; // y position
|
||||
int loc = x + y*img.width; // Pixel array location
|
||||
color c = img.pixels[loc]; // Grab the color
|
||||
// Calculate a z position as a function of mouseX and pixel brightness
|
||||
float z = (mouseX / float(width)) * brightness(img.pixels[loc]) - 20.0;
|
||||
// Translate to the location, set fill and stroke, and draw the rect
|
||||
pushMatrix();
|
||||
translate(x + 200, y + 100, z);
|
||||
fill(c, 204);
|
||||
noStroke();
|
||||
rectMode(CENTER);
|
||||
rect(0, 0, cellsize, cellsize);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
java/examples/3D/Image/Explode/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
java/examples/3D/Image/Explode/data/eames.jpg.tmp
Normal file
|
After Width: | Height: | Size: 44 KiB |
46
java/examples/3D/Image/Extrusion/Extrusion.pde
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Extrusion.
|
||||
*
|
||||
* Converts a flat image into spatial data points and rotates the points
|
||||
* around the center.
|
||||
*/
|
||||
|
||||
PImage extrude;
|
||||
int[][] values;
|
||||
float angle = 0;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
|
||||
// Load the image into a new array
|
||||
extrude = loadImage("ystone08.jpg");
|
||||
extrude.loadPixels();
|
||||
values = new int[extrude.width][extrude.height];
|
||||
for (int y = 0; y < extrude.height; y++) {
|
||||
for (int x = 0; x < extrude.width; x++) {
|
||||
color pixel = extrude.get(x, y);
|
||||
values[x][y] = int(brightness(pixel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
// Update the angle
|
||||
angle += 0.005;
|
||||
|
||||
// Rotate around the center axis
|
||||
translate(width/2, 0, -128);
|
||||
rotateY(angle);
|
||||
translate(-extrude.width/2, 100, -128);
|
||||
|
||||
// Display the image mass
|
||||
for (int y = 0; y < extrude.height; y++) {
|
||||
for (int x = 0; x < extrude.width; x++) {
|
||||
stroke(values[x][y]);
|
||||
point(x, y, -values[x][y]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
67
java/examples/3D/Image/Extrusion/applet/Extrusion.java
Normal file
@@ -0,0 +1,67 @@
|
||||
import processing.core.*;
|
||||
import processing.xml.*;
|
||||
|
||||
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 Extrusion extends PApplet {
|
||||
|
||||
/**
|
||||
* Extrusion.
|
||||
*
|
||||
* Converts a flat image into spatial data points and rotates the points
|
||||
* around the center.
|
||||
*/
|
||||
|
||||
PImage extrude;
|
||||
int[][] values;
|
||||
float angle = 0;
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
|
||||
// Load the image into a new array
|
||||
extrude = loadImage("ystone08.jpg");
|
||||
extrude.loadPixels();
|
||||
values = new int[extrude.width][extrude.height];
|
||||
for (int y = 0; y < extrude.height; y++) {
|
||||
for (int x = 0; x < extrude.width; x++) {
|
||||
int pixel = extrude.get(x, y);
|
||||
values[x][y] = PApplet.parseInt(brightness(pixel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(0);
|
||||
|
||||
// Update the angle
|
||||
angle += 0.005f;
|
||||
|
||||
// Rotate around the center axis
|
||||
translate(width/2, 0, -128);
|
||||
rotateY(angle);
|
||||
translate(-extrude.width/2, 100, -128);
|
||||
|
||||
// Display the image mass
|
||||
for (int y = 0; y < extrude.height; y++) {
|
||||
for (int x = 0; x < extrude.width; x++) {
|
||||
stroke(values[x][y]);
|
||||
point(x, y, -values[x][y]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Extrusion" });
|
||||
}
|
||||
}
|
||||
46
java/examples/3D/Image/Extrusion/applet/Extrusion.pde
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Extrusion.
|
||||
*
|
||||
* Converts a flat image into spatial data points and rotates the points
|
||||
* around the center.
|
||||
*/
|
||||
|
||||
PImage extrude;
|
||||
int[][] values;
|
||||
float angle = 0;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
|
||||
// Load the image into a new array
|
||||
extrude = loadImage("ystone08.jpg");
|
||||
extrude.loadPixels();
|
||||
values = new int[extrude.width][extrude.height];
|
||||
for (int y = 0; y < extrude.height; y++) {
|
||||
for (int x = 0; x < extrude.width; x++) {
|
||||
color pixel = extrude.get(x, y);
|
||||
values[x][y] = int(brightness(pixel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
// Update the angle
|
||||
angle += 0.005;
|
||||
|
||||
// Rotate around the center axis
|
||||
translate(width/2, 0, -128);
|
||||
rotateY(angle);
|
||||
translate(-extrude.width/2, 100, -128);
|
||||
|
||||
// Display the image mass
|
||||
for (int y = 0; y < extrude.height; y++) {
|
||||
for (int x = 0; x < extrude.width; x++) {
|
||||
stroke(values[x][y]);
|
||||
point(x, y, -values[x][y]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BIN
java/examples/3D/Image/Extrusion/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
89
java/examples/3D/Image/Zoom/Zoom.pde
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Zoom.
|
||||
*
|
||||
* Move the cursor over the image to alter its position. Click and press
|
||||
* the mouse to zoom and set the density of the matrix by typing numbers 1-5.
|
||||
* This program displays a series of lines with their heights corresponding to
|
||||
* a color value read from an image.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
//boolean onetime = true;
|
||||
int[][] imgPixels;
|
||||
float sval = 1.0;
|
||||
float nmx, nmy;
|
||||
int res = 5;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noFill();
|
||||
stroke(255);
|
||||
img = loadImage("ystone08.jpg");
|
||||
imgPixels = new int[img.width][img.height];
|
||||
for (int i = 0; i < img.height; i++) {
|
||||
for (int j = 0; j < img.width; j++) {
|
||||
imgPixels[j][i] = img.get(j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
nmx = nmx + (mouseX-nmx)/20;
|
||||
nmy += (mouseY-nmy)/20;
|
||||
|
||||
if(mousePressed) {
|
||||
sval += 0.005;
|
||||
}
|
||||
else {
|
||||
sval -= 0.01;
|
||||
}
|
||||
|
||||
sval = constrain(sval, 1.0, 2.5);
|
||||
|
||||
translate(width/2 + nmx * sval-100, height/2 + nmy*sval - 200, -50);
|
||||
scale(sval);
|
||||
rotateZ(PI/9 - sval + 1.0);
|
||||
rotateX(PI/sval/8 - 0.125);
|
||||
rotateY(sval/8 - 0.125);
|
||||
|
||||
translate(-width/2, -height/2, 0);
|
||||
|
||||
for (int i = 0; i < img.height; i += res) {
|
||||
for (int j = 0; j < img.width; j += res) {
|
||||
float rr = red(imgPixels[j][i]);
|
||||
float gg = green(imgPixels[j][i]);
|
||||
float bb = blue(imgPixels[j][i]);
|
||||
float tt = rr+gg+bb;
|
||||
stroke(rr, gg, gg);
|
||||
line(i, j, tt/10-20, i, j, tt/10 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if(key == '1') {
|
||||
res = 1;
|
||||
}
|
||||
else if (key == '2') {
|
||||
res = 2;
|
||||
}
|
||||
else if (key == '3') {
|
||||
res = 3;
|
||||
}
|
||||
else if (key == '4') {
|
||||
res = 4;
|
||||
}
|
||||
else if (key == '5') {
|
||||
res = 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
109
java/examples/3D/Image/Zoom/applet/Zoom.java
Normal file
@@ -0,0 +1,109 @@
|
||||
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 Zoom extends PApplet {
|
||||
|
||||
/**
|
||||
* Zoom.
|
||||
*
|
||||
* Move the cursor over the image to alter its position. Click and press
|
||||
* the mouse to zoom and set the density of the matrix by typing numbers 1-5.
|
||||
* This program displays a series of lines with their heights corresponding to
|
||||
* a color value read from an image.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
//boolean onetime = true;
|
||||
int[][] imgPixels;
|
||||
float sval = 1.0f;
|
||||
float nmx, nmy;
|
||||
int res = 5;
|
||||
|
||||
public void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noFill();
|
||||
stroke(255);
|
||||
img = loadImage("ystone08.jpg");
|
||||
imgPixels = new int[img.width][img.height];
|
||||
for (int i = 0; i < img.height; i++) {
|
||||
for (int j = 0; j < img.width; j++) {
|
||||
imgPixels[j][i] = img.get(j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
nmx = nmx + (mouseX-nmx)/20;
|
||||
nmy += (mouseY-nmy)/20;
|
||||
|
||||
if(mousePressed) {
|
||||
sval += 0.005f;
|
||||
}
|
||||
else {
|
||||
sval -= 0.01f;
|
||||
}
|
||||
|
||||
sval = constrain(sval, 1.0f, 2.5f);
|
||||
|
||||
translate(width/2 + nmx * sval-100, height/2 + nmy*sval - 200, -50);
|
||||
scale(sval);
|
||||
rotateZ(PI/9 - sval + 1.0f);
|
||||
rotateX(PI/sval/8 - 0.125f);
|
||||
rotateY(sval/8 - 0.125f);
|
||||
|
||||
translate(-width/2, -height/2, 0);
|
||||
|
||||
for (int i = 0; i < img.height; i += res) {
|
||||
for (int j = 0; j < img.width; j += res) {
|
||||
float rr = red(imgPixels[j][i]);
|
||||
float gg = green(imgPixels[j][i]);
|
||||
float bb = blue(imgPixels[j][i]);
|
||||
float tt = rr+gg+bb;
|
||||
stroke(rr, gg, gg);
|
||||
line(i, j, tt/10-20, i, j, tt/10 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void keyPressed() {
|
||||
if(key == '1') {
|
||||
res = 1;
|
||||
}
|
||||
else if (key == '2') {
|
||||
res = 2;
|
||||
}
|
||||
else if (key == '3') {
|
||||
res = 3;
|
||||
}
|
||||
else if (key == '4') {
|
||||
res = 4;
|
||||
}
|
||||
else if (key == '5') {
|
||||
res = 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Zoom" });
|
||||
}
|
||||
}
|
||||
89
java/examples/3D/Image/Zoom/applet/Zoom.pde
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Zoom.
|
||||
*
|
||||
* Move the cursor over the image to alter its position. Click and press
|
||||
* the mouse to zoom and set the density of the matrix by typing numbers 1-5.
|
||||
* This program displays a series of lines with their heights corresponding to
|
||||
* a color value read from an image.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
//boolean onetime = true;
|
||||
int[][] imgPixels;
|
||||
float sval = 1.0;
|
||||
float nmx, nmy;
|
||||
int res = 5;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
noFill();
|
||||
stroke(255);
|
||||
img = loadImage("ystone08.jpg");
|
||||
imgPixels = new int[img.width][img.height];
|
||||
for (int i = 0; i < img.height; i++) {
|
||||
for (int j = 0; j < img.width; j++) {
|
||||
imgPixels[j][i] = img.get(j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(0);
|
||||
|
||||
nmx = nmx + (mouseX-nmx)/20;
|
||||
nmy += (mouseY-nmy)/20;
|
||||
|
||||
if(mousePressed) {
|
||||
sval += 0.005;
|
||||
}
|
||||
else {
|
||||
sval -= 0.01;
|
||||
}
|
||||
|
||||
sval = constrain(sval, 1.0, 2.5);
|
||||
|
||||
translate(width/2 + nmx * sval-100, height/2 + nmy*sval - 200, -50);
|
||||
scale(sval);
|
||||
rotateZ(PI/9 - sval + 1.0);
|
||||
rotateX(PI/sval/8 - 0.125);
|
||||
rotateY(sval/8 - 0.125);
|
||||
|
||||
translate(-width/2, -height/2, 0);
|
||||
|
||||
for (int i = 0; i < img.height; i += res) {
|
||||
for (int j = 0; j < img.width; j += res) {
|
||||
float rr = red(imgPixels[j][i]);
|
||||
float gg = green(imgPixels[j][i]);
|
||||
float bb = blue(imgPixels[j][i]);
|
||||
float tt = rr+gg+bb;
|
||||
stroke(rr, gg, gg);
|
||||
line(i, j, tt/10-20, i, j, tt/10 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if(key == '1') {
|
||||
res = 1;
|
||||
}
|
||||
else if (key == '2') {
|
||||
res = 2;
|
||||
}
|
||||
else if (key == '3') {
|
||||
res = 3;
|
||||
}
|
||||
else if (key == '4') {
|
||||
res = 4;
|
||||
}
|
||||
else if (key == '5') {
|
||||
res = 5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
java/examples/3D/Image/Zoom/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
28
java/examples/3D/Lights/Directional/Directional.pde
Normal 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);
|
||||
}
|
||||
|
||||
48
java/examples/3D/Lights/Directional/applet/Directional.java
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
28
java/examples/3D/Lights/Directional/applet/Directional.pde
Normal 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);
|
||||
}
|
||||
|
||||
BIN
java/examples/3D/Lights/Directional/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
29
java/examples/3D/Lights/Lights1/Lights1.pde
Normal 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();
|
||||
}
|
||||
49
java/examples/3D/Lights/Lights1/applet/Lights1.java
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
29
java/examples/3D/Lights/Lights1/applet/Lights1.pde
Normal 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();
|
||||
}
|
||||
BIN
java/examples/3D/Lights/Lights1/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
36
java/examples/3D/Lights/Lights2/Lights2.pde
Normal 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);
|
||||
}
|
||||
56
java/examples/3D/Lights/Lights2/applet/Lights2.java
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
36
java/examples/3D/Lights/Lights2/applet/Lights2.pde
Normal 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);
|
||||
}
|
||||
BIN
java/examples/3D/Lights/Lights2/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
25
java/examples/3D/Lights/Reflection/Reflection.pde
Normal 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);
|
||||
}
|
||||
45
java/examples/3D/Lights/Reflection/applet/Reflection.java
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
25
java/examples/3D/Lights/Reflection/applet/Reflection.pde
Normal 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);
|
||||
}
|
||||
BIN
java/examples/3D/Lights/Reflection/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
35
java/examples/3D/Lights/Spot/Spot.pde
Normal 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);
|
||||
}
|
||||
|
||||
55
java/examples/3D/Lights/Spot/applet/Spot.java
Normal file
@@ -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" });
|
||||
}
|
||||
}
|
||||
35
java/examples/3D/Lights/Spot/applet/Spot.pde
Normal 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);
|
||||
}
|
||||
|
||||
BIN
java/examples/3D/Lights/Spot/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
28
java/examples/3D/Textures/Texture1/Texture1.pde
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Texture 1.
|
||||
*
|
||||
* Load an image and draw it onto a quad. The texture() function sets
|
||||
* the texture image. The vertex() function maps the image to the geometry.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("berlin-1.jpg");
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
rotateY(map(mouseX, 0, width, -PI, PI));
|
||||
rotateZ(PI/6);
|
||||
beginShape();
|
||||
texture(img);
|
||||
vertex(-100, -100, 0, 0, 0);
|
||||
vertex(100, -100, 0, 400, 0);
|
||||
vertex(100, 100, 0, 400, 400);
|
||||
vertex(-100, 100, 0, 0, 400);
|
||||
endShape();
|
||||
}
|
||||
48
java/examples/3D/Textures/Texture1/applet/Texture1.java
Normal file
@@ -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 Texture1 extends PApplet {
|
||||
|
||||
/**
|
||||
* Texture 1.
|
||||
*
|
||||
* Load an image and draw it onto a quad. The texture() function sets
|
||||
* the texture image. The vertex() function maps the image to the geometry.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("berlin-1.jpg");
|
||||
noStroke();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
rotateY(map(mouseX, 0, width, -PI, PI));
|
||||
rotateZ(PI/6);
|
||||
beginShape();
|
||||
texture(img);
|
||||
vertex(-100, -100, 0, 0, 0);
|
||||
vertex(100, -100, 0, 400, 0);
|
||||
vertex(100, 100, 0, 400, 400);
|
||||
vertex(-100, 100, 0, 0, 400);
|
||||
endShape();
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Texture1" });
|
||||
}
|
||||
}
|
||||
28
java/examples/3D/Textures/Texture1/applet/Texture1.pde
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Texture 1.
|
||||
*
|
||||
* Load an image and draw it onto a quad. The texture() function sets
|
||||
* the texture image. The vertex() function maps the image to the geometry.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("berlin-1.jpg");
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
rotateY(map(mouseX, 0, width, -PI, PI));
|
||||
rotateZ(PI/6);
|
||||
beginShape();
|
||||
texture(img);
|
||||
vertex(-100, -100, 0, 0, 0);
|
||||
vertex(100, -100, 0, 400, 0);
|
||||
vertex(100, 100, 0, 400, 400);
|
||||
vertex(-100, 100, 0, 0, 400);
|
||||
endShape();
|
||||
}
|
||||
BIN
java/examples/3D/Textures/Texture1/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
25
java/examples/3D/Textures/Texture2/Texture2.pde
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Texture 2.
|
||||
*
|
||||
* Using a rectangular image to map a texture onto a triangle.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("berlin-1.jpg");
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
rotateY(map(mouseX, 0, width, -PI, PI));
|
||||
beginShape();
|
||||
texture(img);
|
||||
vertex(-100, -100, 0, 0, 0);
|
||||
vertex(100, -40, 0, 400, 120);
|
||||
vertex(0, 100, 0, 200, 400);
|
||||
endShape();
|
||||
}
|
||||
45
java/examples/3D/Textures/Texture2/applet/Texture2.java
Normal file
@@ -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 Texture2 extends PApplet {
|
||||
|
||||
/**
|
||||
* Texture 2.
|
||||
*
|
||||
* Using a rectangular image to map a texture onto a triangle.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
|
||||
public void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("berlin-1.jpg");
|
||||
noStroke();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
rotateY(map(mouseX, 0, width, -PI, PI));
|
||||
beginShape();
|
||||
texture(img);
|
||||
vertex(-100, -100, 0, 0, 0);
|
||||
vertex(100, -40, 0, 400, 120);
|
||||
vertex(0, 100, 0, 200, 400);
|
||||
endShape();
|
||||
}
|
||||
|
||||
static public void main(String args[]) {
|
||||
PApplet.main(new String[] { "Texture2" });
|
||||
}
|
||||
}
|
||||
25
java/examples/3D/Textures/Texture2/applet/Texture2.pde
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Texture 2.
|
||||
*
|
||||
* Using a rectangular image to map a texture onto a triangle.
|
||||
*/
|
||||
|
||||
PImage img;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("berlin-1.jpg");
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
rotateY(map(mouseX, 0, width, -PI, PI));
|
||||
beginShape();
|
||||
texture(img);
|
||||
vertex(-100, -100, 0, 0, 0);
|
||||
vertex(100, -40, 0, 400, 120);
|
||||
vertex(0, 100, 0, 200, 400);
|
||||
endShape();
|
||||
}
|
||||
BIN
java/examples/3D/Textures/Texture2/applet/loading.gif
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
46
java/examples/3D/Textures/Texture3/Texture3.pde
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Texture 3.
|
||||
*
|
||||
* Load an image and draw it onto a cylinder and a quad.
|
||||
*/
|
||||
|
||||
|
||||
int tubeRes = 32;
|
||||
float[] tubeX = new float[tubeRes];
|
||||
float[] tubeY = new float[tubeRes];
|
||||
PImage img;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
img = loadImage("berlin-1.jpg");
|
||||
float angle = 270.0 / tubeRes;
|
||||
for (int i = 0; i < tubeRes; i++) {
|
||||
tubeX[i] = cos(radians(i * angle));
|
||||
tubeY[i] = sin(radians(i * angle));
|
||||
}
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
translate(width / 2, height / 2);
|
||||
rotateX(map(mouseY, 0, height, -PI, PI));
|
||||
rotateY(map(mouseX, 0, width, -PI, PI));
|
||||
beginShape(QUAD_STRIP);
|
||||
texture(img);
|
||||
for (int i = 0; i < tubeRes; i++) {
|
||||
float x = tubeX[i] * 100;
|
||||
float z = tubeY[i] * 100;
|
||||
float u = img.width / tubeRes * i;
|
||||
vertex(x, -100, z, u, 0);
|
||||
vertex(x, 100, z, u, img.height);
|
||||
}
|
||||
endShape();
|
||||
beginShape(QUADS);
|
||||
texture(img);
|
||||
vertex(0, -100, 0, 0, 0);
|
||||
vertex(100, -100, 0, 100, 0);
|
||||
vertex(100, 100, 0, 100, 100);
|
||||
vertex(0, 100, 0, 0, 100);
|
||||
endShape();
|
||||
}
|
||||