mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
New images and code for Examples 2.0
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Noise Sphere
|
||||
* by David Pena.
|
||||
*
|
||||
* Uniform random distribution on the surface of a sphere.
|
||||
*/
|
||||
|
||||
int cuantos = 4000;
|
||||
Pelo[] lista ;
|
||||
float[] z = new float[cuantos];
|
||||
float[] phi = new float[cuantos];
|
||||
float[] largos = new float[cuantos];
|
||||
float radio;
|
||||
float rx = 0;
|
||||
float ry =0;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
radio = height/3;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
beginShape(LINES);
|
||||
stroke(0);
|
||||
vertex(x, y, z);
|
||||
stroke(200, 150);
|
||||
vertex(xb, yb, zb);
|
||||
endShape();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
|
||||
class Cube {
|
||||
|
||||
// Properties
|
||||
int w, h, d;
|
||||
int shiftX, shiftY, shiftZ;
|
||||
|
||||
// Constructor
|
||||
Cube(int w, int h, int d, int shiftX, int shiftY, int shiftZ){
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
this.shiftX = shiftX;
|
||||
this.shiftY = shiftY;
|
||||
this.shiftZ = shiftZ;
|
||||
}
|
||||
|
||||
// Main cube drawing method, which looks
|
||||
// more confusing than it really is. It's
|
||||
// just a bunch of rectangles drawn for
|
||||
// each cube face
|
||||
void drawCube(){
|
||||
beginShape(QUADS);
|
||||
// Front face
|
||||
vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
|
||||
vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
|
||||
vertex(w + shiftX, h + shiftY, -d/2 + shiftZ);
|
||||
vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ);
|
||||
|
||||
// Back face
|
||||
vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ);
|
||||
vertex(w + shiftX, -h/2 + shiftY, d + shiftZ);
|
||||
vertex(w + shiftX, h + shiftY, d + shiftZ);
|
||||
vertex(-w/2 + shiftX, h + shiftY, d + shiftZ);
|
||||
|
||||
// Left face
|
||||
vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
|
||||
vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ);
|
||||
vertex(-w/2 + shiftX, h + shiftY, d + shiftZ);
|
||||
vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ);
|
||||
|
||||
// Right face
|
||||
vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
|
||||
vertex(w + shiftX, -h/2 + shiftY, d + shiftZ);
|
||||
vertex(w + shiftX, h + shiftY, d + shiftZ);
|
||||
vertex(w + shiftX, h + shiftY, -d/2 + shiftZ);
|
||||
|
||||
// Top face
|
||||
vertex(-w/2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
|
||||
vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ);
|
||||
vertex(w + shiftX, -h/2 + shiftY, d + shiftZ);
|
||||
vertex(-w/2 + shiftX, -h/2 + shiftY, d + shiftZ);
|
||||
|
||||
// Bottom face
|
||||
vertex(-w/2 + shiftX, h + shiftY, -d/2 + shiftZ);
|
||||
vertex(w + shiftX, h + shiftY, -d/2 + shiftZ);
|
||||
vertex(w + shiftX, h + shiftY, d + shiftZ);
|
||||
vertex(-w/2 + shiftX, h + shiftY, d + shiftZ);
|
||||
|
||||
endShape();
|
||||
|
||||
// Add some rotation to each box for pizazz.
|
||||
rotateY(radians(1));
|
||||
rotateX(radians(1));
|
||||
rotateZ(radians(1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Space Junk
|
||||
* by Ira Greenberg (zoom suggestion by Danny Greenberg).
|
||||
*
|
||||
* Rotating cubes in space using a custom Cube class.
|
||||
* Color controlled by light sources. Move the mouse left
|
||||
* and right to zoom.
|
||||
*/
|
||||
|
||||
// Used for oveall rotation
|
||||
float ang;
|
||||
|
||||
// Cube count-lower/raise to test performance
|
||||
int limit = 500;
|
||||
|
||||
// Array for all cubes
|
||||
Cube[]cubes = new Cube[limit];
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
background(0);
|
||||
noStroke();
|
||||
|
||||
// Instantiate cubes, passing in random vals for size and postion
|
||||
for (int i = 0; i< cubes.length; i++){
|
||||
cubes[i] = new Cube(int(random(-10, 10)), int(random(-10, 10)),
|
||||
int(random(-10, 10)), int(random(-140, 140)),
|
||||
int(random(-140, 140)), int(random(-140, 140)));
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(0);
|
||||
fill(200);
|
||||
|
||||
// Set up some different colored lights
|
||||
pointLight(51, 102, 255, 65, 60, 100);
|
||||
pointLight(200, 40, 60, -65, -60, -150);
|
||||
|
||||
// Raise overall light in scene
|
||||
ambientLight(70, 70, 10);
|
||||
|
||||
// Center geometry in display windwow.
|
||||
// you can change 3rd argument ('0')
|
||||
// to move block group closer(+)/further(-)
|
||||
translate(width/2, height/2, -200 + mouseX * 0.65);
|
||||
|
||||
// Rotate around y and x axes
|
||||
rotateY(radians(ang));
|
||||
rotateX(radians(ang));
|
||||
|
||||
// Draw cubes
|
||||
for (int i = 0; i < cubes.length; i++){
|
||||
cubes[i].drawCube();
|
||||
}
|
||||
|
||||
// Used in rotate function calls above
|
||||
ang += 0.2;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user