mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Cubic Grid
|
||||
* by Ira Greenberg.
|
||||
*
|
||||
* 3D translucent colored grid uses nested pushMatrix()
|
||||
* and popMatrix() functions.
|
||||
*/
|
||||
|
||||
float boxSize = 20;
|
||||
float margin = boxSize*2;
|
||||
float depth = 400;
|
||||
color boxFill;
|
||||
|
||||
int fcount, lastm;
|
||||
float frate;
|
||||
int fint = 3;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
frameRate(60);
|
||||
noSmooth();
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
|
||||
hint(DISABLE_DEPTH_TEST);
|
||||
|
||||
// Center and spin grid
|
||||
pushMatrix();
|
||||
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){
|
||||
for (float j =- height+margin; j <= height-margin; j += boxSize){
|
||||
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();
|
||||
|
||||
hint(ENABLE_DEPTH_TEST);
|
||||
|
||||
fcount += 1;
|
||||
int m = millis();
|
||||
if (m - lastm > 1000 * fint) {
|
||||
frate = float(fcount) / fint;
|
||||
fcount = 0;
|
||||
lastm = m;
|
||||
println("fps: " + frate);
|
||||
}
|
||||
fill(0);
|
||||
text("fps: " + frate, 10, 20);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
float boxSize = 20;
|
||||
float margin = boxSize*2;
|
||||
float depth = 400;
|
||||
color boxFill;
|
||||
|
||||
PShape grid;
|
||||
|
||||
int fcount, lastm;
|
||||
float frate;
|
||||
int fint = 3;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
frameRate(60);
|
||||
noSmooth();
|
||||
noStroke();
|
||||
|
||||
grid = createShape(PShape.GROUP);
|
||||
|
||||
// Build grid using multiple translations
|
||||
for (float i =- depth/2+margin; i <= depth/2-margin; i += boxSize){
|
||||
for (float j =- height+margin; j <= height-margin; j += boxSize){
|
||||
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);
|
||||
PShape cube = createShape(BOX, boxSize, boxSize, boxSize);
|
||||
cube.fill(boxFill);
|
||||
cube.translate(k, j, i);
|
||||
grid.addChild(cube);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
|
||||
hint(DISABLE_DEPTH_TEST);
|
||||
|
||||
// Center and spin grid
|
||||
pushMatrix();
|
||||
translate(width/2, height/2, -depth);
|
||||
rotateY(frameCount * 0.01);
|
||||
rotateX(frameCount * 0.01);
|
||||
|
||||
shape(grid);
|
||||
popMatrix();
|
||||
|
||||
hint(ENABLE_DEPTH_TEST);
|
||||
|
||||
fcount += 1;
|
||||
int m = millis();
|
||||
if (m - lastm > 1000 * fint) {
|
||||
frate = float(fcount) / fint;
|
||||
fcount = 0;
|
||||
lastm = m;
|
||||
println("fps: " + frate);
|
||||
}
|
||||
fill(0);
|
||||
text("fps: " + frate, 10, 20);
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
PImage sprite;
|
||||
|
||||
int npartTotal = 10000;
|
||||
int npartPerFrame = 25;
|
||||
float speed = 1.0;
|
||||
float gravity = 0.05;
|
||||
float partSize = 20;
|
||||
|
||||
int partLifetime;
|
||||
PVector positions[];
|
||||
PVector velocities[];
|
||||
int lifetimes[];
|
||||
|
||||
int fcount, lastm;
|
||||
float frate;
|
||||
int fint = 3;
|
||||
|
||||
void setup() {
|
||||
size(640, 480, P3D);
|
||||
frameRate(120);
|
||||
|
||||
sprite = loadImage("sprite.png");
|
||||
|
||||
partLifetime = npartTotal / npartPerFrame;
|
||||
initPositions();
|
||||
initVelocities();
|
||||
initLifetimes();
|
||||
|
||||
// Writing to the depth buffer is disabled to avoid rendering
|
||||
// artifacts due to the fact that the particles are semi-transparent
|
||||
// but not z-sorted.
|
||||
hint(DISABLE_DEPTH_MASK);
|
||||
|
||||
// Testing some hints
|
||||
//hint(DISABLE_TRANSFORM_CACHE);
|
||||
//hint(ENABLE_ACCURATE_2D);
|
||||
}
|
||||
|
||||
void draw () {
|
||||
background(0);
|
||||
|
||||
for (int n = 0; n < npartTotal; n++) {
|
||||
lifetimes[n]++;
|
||||
if (lifetimes[n] == partLifetime) {
|
||||
lifetimes[n] = 0;
|
||||
}
|
||||
|
||||
if (0 <= lifetimes[n]) {
|
||||
float opacity = 1.0 - float(lifetimes[n]) / partLifetime;
|
||||
|
||||
if (lifetimes[n] == 0) {
|
||||
// Re-spawn dead particle
|
||||
positions[n].x = mouseX;
|
||||
positions[n].y = mouseY;
|
||||
|
||||
float angle = random(0, TWO_PI);
|
||||
float s = random(0.5 * speed, 0.5 * speed);
|
||||
velocities[n].x = s * cos(angle);
|
||||
velocities[n].y = s * sin(angle);
|
||||
} else {
|
||||
positions[n].x += velocities[n].x;
|
||||
positions[n].y += velocities[n].y;
|
||||
|
||||
velocities[n].y += gravity;
|
||||
}
|
||||
drawParticle(positions[n], opacity);
|
||||
}
|
||||
}
|
||||
|
||||
fcount += 1;
|
||||
int m = millis();
|
||||
if (m - lastm > 1000 * fint) {
|
||||
frate = float(fcount) / fint;
|
||||
fcount = 0;
|
||||
lastm = m;
|
||||
println("fps: " + frate);
|
||||
}
|
||||
}
|
||||
|
||||
void drawParticle(PVector center, float opacity) {
|
||||
beginShape(QUAD);
|
||||
noStroke();
|
||||
tint(255, opacity * 255);
|
||||
texture(sprite);
|
||||
normal(0, 0, 1);
|
||||
vertex(center.x - partSize/2, center.y - partSize/2, 0, 0);
|
||||
vertex(center.x + partSize/2, center.y - partSize/2, sprite.width, 0);
|
||||
vertex(center.x + partSize/2, center.y + partSize/2, sprite.width, sprite.height);
|
||||
vertex(center.x - partSize/2, center.y + partSize/2, 0, sprite.height);
|
||||
endShape();
|
||||
}
|
||||
|
||||
void initPositions() {
|
||||
positions = new PVector[npartTotal];
|
||||
for (int n = 0; n < positions.length; n++) {
|
||||
positions[n] = new PVector();
|
||||
}
|
||||
}
|
||||
|
||||
void initVelocities() {
|
||||
velocities = new PVector[npartTotal];
|
||||
for (int n = 0; n < velocities.length; n++) {
|
||||
velocities[n] = new PVector();
|
||||
}
|
||||
}
|
||||
|
||||
void initLifetimes() {
|
||||
// Initializing particles with negative lifetimes so they are added
|
||||
// progressively into the screen during the first frames of the sketch
|
||||
lifetimes = new int[npartTotal];
|
||||
int t = -1;
|
||||
for (int n = 0; n < lifetimes.length; n++) {
|
||||
if (n % npartPerFrame == 0) {
|
||||
t++;
|
||||
}
|
||||
lifetimes[n] = -t;
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
PShape particles;
|
||||
PImage sprite;
|
||||
|
||||
int npartTotal = 10000;
|
||||
int npartPerFrame = 25;
|
||||
float speed = 1.0;
|
||||
float gravity = 0.05;
|
||||
float partSize = 20;
|
||||
|
||||
int partLifetime;
|
||||
PVector velocities[];
|
||||
int lifetimes[];
|
||||
|
||||
int fcount, lastm;
|
||||
float frate;
|
||||
int fint = 3;
|
||||
|
||||
void setup() {
|
||||
size(640, 480, P3D);
|
||||
frameRate(120);
|
||||
|
||||
particles = createShape(PShape.GROUP);
|
||||
sprite = loadImage("sprite.png");
|
||||
|
||||
for (int n = 0; n < npartTotal; n++) {
|
||||
PShape part = createShape(QUAD);
|
||||
part.noStroke();
|
||||
part.texture(sprite);
|
||||
part.normal(0, 0, 1);
|
||||
part.vertex(-partSize/2, -partSize/2, 0, 0);
|
||||
part.vertex(+partSize/2, -partSize/2, sprite.width, 0);
|
||||
part.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height);
|
||||
part.vertex(-partSize/2, +partSize/2, 0, sprite.height);
|
||||
part.end();
|
||||
particles.addChild(part);
|
||||
}
|
||||
|
||||
partLifetime = npartTotal / npartPerFrame;
|
||||
initVelocities();
|
||||
initLifetimes();
|
||||
|
||||
// Writing to the depth buffer is disabled to avoid rendering
|
||||
// artifacts due to the fact that the particles are semi-transparent
|
||||
// but not z-sorted.
|
||||
hint(DISABLE_DEPTH_MASK);
|
||||
}
|
||||
|
||||
void draw () {
|
||||
background(0);
|
||||
|
||||
for (int n = 0; n < particles.getChildCount(); n++) {
|
||||
PShape part = particles.getChild(n);
|
||||
|
||||
lifetimes[n]++;
|
||||
if (lifetimes[n] == partLifetime) {
|
||||
lifetimes[n] = 0;
|
||||
}
|
||||
|
||||
if (0 <= lifetimes[n]) {
|
||||
float opacity = 1.0 - float(lifetimes[n]) / partLifetime;
|
||||
part.tint(255, opacity * 255);
|
||||
|
||||
if (lifetimes[n] == 0) {
|
||||
// Re-spawn dead particle
|
||||
part.resetMatrix();
|
||||
part.translate(mouseX, mouseY);
|
||||
float angle = random(0, TWO_PI);
|
||||
float s = random(0.5 * speed, 0.5 * speed);
|
||||
velocities[n].x = s * cos(angle);
|
||||
velocities[n].y = s * sin(angle);
|
||||
} else {
|
||||
part.translate(velocities[n].x, velocities[n].y);
|
||||
velocities[n].y += gravity;
|
||||
}
|
||||
} else {
|
||||
part.tint(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
shape(particles);
|
||||
|
||||
fcount += 1;
|
||||
int m = millis();
|
||||
if (m - lastm > 1000 * fint) {
|
||||
frate = float(fcount) / fint;
|
||||
fcount = 0;
|
||||
lastm = m;
|
||||
println("fps: " + frate);
|
||||
}
|
||||
}
|
||||
|
||||
void initVelocities() {
|
||||
velocities = new PVector[npartTotal];
|
||||
for (int n = 0; n < velocities.length; n++) {
|
||||
velocities[n] = new PVector();
|
||||
}
|
||||
}
|
||||
|
||||
void initLifetimes() {
|
||||
// Initializing particles with negative lifetimes so they are added
|
||||
// progressively into the screen during the first frames of the sketch
|
||||
lifetimes = new int[npartTotal];
|
||||
int t = -1;
|
||||
for (int n = 0; n < lifetimes.length; n++) {
|
||||
if (n % npartPerFrame == 0) {
|
||||
t++;
|
||||
}
|
||||
lifetimes[n] = -t;
|
||||
}
|
||||
}
|
||||
+89
@@ -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);
|
||||
noSmooth();
|
||||
frameRate(120);
|
||||
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 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,24 @@
|
||||
|
||||
public void setup() {
|
||||
size(800, 600, P2D);
|
||||
}
|
||||
|
||||
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,17 @@
|
||||
|
||||
public void setup() {
|
||||
size(800, 600, P2D);
|
||||
|
||||
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,65 @@
|
||||
PImage sprite;
|
||||
|
||||
int npartTotal = 50000;
|
||||
float partSize = 20;
|
||||
|
||||
PVector positions[];
|
||||
|
||||
int fcount, lastm;
|
||||
float frate;
|
||||
int fint = 3;
|
||||
|
||||
void setup() {
|
||||
size(800, 600, P3D);
|
||||
frameRate(60);
|
||||
|
||||
sprite = loadImage("sprite.png");
|
||||
|
||||
initPositions();
|
||||
|
||||
// Writing to the depth buffer is disabled to avoid rendering
|
||||
// artifacts due to the fact that the particles are semi-transparent
|
||||
// but not z-sorted.
|
||||
hint(DISABLE_DEPTH_MASK);
|
||||
}
|
||||
|
||||
void draw () {
|
||||
background(0);
|
||||
|
||||
translate(width/2, height/2);
|
||||
rotateY(frameCount * 0.01);
|
||||
|
||||
for (int n = 0; n < npartTotal; n++) {
|
||||
drawParticle(positions[n]);
|
||||
}
|
||||
|
||||
fcount += 1;
|
||||
int m = millis();
|
||||
if (m - lastm > 1000 * fint) {
|
||||
frate = float(fcount) / fint;
|
||||
fcount = 0;
|
||||
lastm = m;
|
||||
println("fps: " + frate);
|
||||
}
|
||||
}
|
||||
|
||||
void drawParticle(PVector center) {
|
||||
beginShape(QUAD);
|
||||
noStroke();
|
||||
tint(255);
|
||||
texture(sprite);
|
||||
normal(0, 0, 1);
|
||||
vertex(center.x - partSize/2, center.y - partSize/2, center.z, 0, 0);
|
||||
vertex(center.x + partSize/2, center.y - partSize/2, center.z, sprite.width, 0);
|
||||
vertex(center.x + partSize/2, center.y + partSize/2, center.z, sprite.width, sprite.height);
|
||||
vertex(center.x - partSize/2, center.y + partSize/2, center.z, 0, sprite.height);
|
||||
endShape();
|
||||
}
|
||||
|
||||
void initPositions() {
|
||||
positions = new PVector[npartTotal];
|
||||
for (int n = 0; n < positions.length; n++) {
|
||||
positions[n] = new PVector(random(-500, +500), random(-500, +500), random(-500, +500));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
PShape particles;
|
||||
PImage sprite;
|
||||
|
||||
int npartTotal = 50000;
|
||||
float partSize = 20;
|
||||
|
||||
int fcount, lastm;
|
||||
float frate;
|
||||
int fint = 3;
|
||||
|
||||
void setup() {
|
||||
size(800, 600, P3D);
|
||||
frameRate(60);
|
||||
|
||||
particles = createShape(PShape.GROUP);
|
||||
sprite = loadImage("sprite.png");
|
||||
|
||||
for (int n = 0; n < npartTotal; n++) {
|
||||
float cx = random(-500, +500);
|
||||
float cy = random(-500, +500);
|
||||
float cz = random(-500, +500);
|
||||
|
||||
PShape part = createShape(QUAD);
|
||||
part.noStroke();
|
||||
part.tint(255);
|
||||
part.texture(sprite);
|
||||
part.normal(0, 0, 1);
|
||||
part.vertex(cx - partSize/2, cy - partSize/2, cz, 0, 0);
|
||||
part.vertex(cx + partSize/2, cy - partSize/2, cz, sprite.width, 0);
|
||||
part.vertex(cx + partSize/2, cy + partSize/2, cz, sprite.width, sprite.height);
|
||||
part.vertex(cx - partSize/2, cy + partSize/2, cz, 0, sprite.height);
|
||||
part.end();
|
||||
particles.addChild(part);
|
||||
}
|
||||
|
||||
// Writing to the depth buffer is disabled to avoid rendering
|
||||
// artifacts due to the fact that the particles are semi-transparent
|
||||
// but not z-sorted.
|
||||
hint(DISABLE_DEPTH_MASK);
|
||||
}
|
||||
|
||||
void draw () {
|
||||
background(0);
|
||||
|
||||
translate(width/2, height/2);
|
||||
rotateY(frameCount * 0.01);
|
||||
|
||||
shape(particles);
|
||||
|
||||
fcount += 1;
|
||||
int m = millis();
|
||||
if (m - lastm > 1000 * fint) {
|
||||
frate = float(fcount) / fint;
|
||||
fcount = 0;
|
||||
lastm = m;
|
||||
println("fps: " + frate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
public void setup() {
|
||||
size(800, 600, P2D);
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user