Added new P3D examples

This commit is contained in:
codeanticode
2011-12-12 04:20:41 +00:00
parent 63e688f79a
commit ffbf9af5ed
74 changed files with 4885 additions and 0 deletions
@@ -0,0 +1,53 @@
/**
* 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);
frameRate(120);
noStroke();
}
void draw() {
background(255);
hint(DISABLE_DEPTH_TEST);
// 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();
}
if (frameCount % 10 == 0) {
println(frameRate);
}
}
@@ -0,0 +1,89 @@
/**
* Esfera
* by David Pena.
*
* Distribucion aleatoria uniforme sobre la superficie de una esfera.
*/
int cuantos = 16000;
pelo[] lista ;
float[] z = new float[cuantos];
float[] phi = new float[cuantos];
float[] largos = new float[cuantos];
float radio = 200;
float rx = 0;
float ry =0;
void setup() {
size(1024, 768, P3D);
radio = height/3.5;
lista = new pelo[cuantos];
for (int i=0; i<cuantos; i++){
lista[i] = new pelo();
}
noiseDetail(3);
}
void draw() {
background(0);
translate(width/2,height/2);
float rxp = ((mouseX-(width/2))*0.005);
float ryp = ((mouseY-(height/2))*0.005);
rx = (rx*0.9)+(rxp*0.1);
ry = (ry*0.9)+(ryp*0.1);
rotateY(rx);
rotateX(ry);
fill(0);
noStroke();
sphere(radio);
for (int i=0;i<cuantos;i++){
lista[i].dibujar();
}
if (frameCount % 10 == 0) {
println(frameRate);
}
}
class pelo
{
float z = random(-radio,radio);
float phi = random(TWO_PI);
float largo = random(1.15,1.2);
float theta = asin(z/radio);
void dibujar(){
float off = (noise(millis() * 0.0005,sin(phi))-0.5) * 0.3;
float offb = (noise(millis() * 0.0007,sin(z) * 0.01)-0.5) * 0.3;
float thetaff = theta+off;
float phff = phi+offb;
float x = radio * cos(theta) * cos(phi);
float y = radio * cos(theta) * sin(phi);
float z = radio * sin(theta);
float msx= screenX(x,y,z);
float msy= screenY(x,y,z);
float xo = radio * cos(thetaff) * cos(phff);
float yo = radio * cos(thetaff) * sin(phff);
float zo = radio * sin(thetaff);
float xb = xo * largo;
float yb = yo * largo;
float zb = zo * largo;
strokeWeight(1);
beginShape(LINES);
stroke(0);
vertex(x,y,z);
stroke(200,150);
vertex(xb,yb,zb);
endShape();
}
}
@@ -0,0 +1,25 @@
import processing.opengl.*;
public void setup() {
size(800, 600, OPENGL);
}
public void draw() {
background(255);
stroke(0, 10);
for (int i = 0; i < 50000; i++) {
float x0 = random(width);
float y0 = random(height);
float z0 = random(-100, 100);
float x1 = random(width);
float y1 = random(height);
float z1 = random(-100, 100);
// purely 2D lines will trigger the GLU
// tessellator to add accurate line caps,
// but performance will be substantially
// lower.
line(x0, y0, z0, x1, y1, z1);
}
if (frameCount % 10 == 0) println(frameRate);
}
@@ -0,0 +1,18 @@
import processing.opengl.*;
public void setup() {
size(800, 600, OPENGL);
noStroke();
fill(0, 1);
}
public void draw() {
background(255);
for (int i = 0; i < 50000; i++) {
float x = random(width);
float y = random(height);
rect(x, y, 30, 30);
}
if (frameCount % 10 == 0) println(frameRate);
}
@@ -0,0 +1,16 @@
import processing.opengl.*;
public void setup() {
size(800, 600, OPENGL);
fill(0);
}
public void draw() {
background(255);
for (int i = 0; i < 10000; i++) {
float x = random(width);
float y = random(height);
text("HELLO", x, y);
}
if (frameCount % 10 == 0) println(frameRate);
}