how many polygons is rendering the beginShape() / endShape command
in
Programming Questions
•
2 years ago
hi, I'm developing this sketch:
And I'd like to add some sound to it. So I thought making some noise generated from those wired polygons showing up and hiding (those that beginShape() and endShape() seem to have troubles to render).
The question is:
Is is possible for processing to acces to how many polygons is actually rendering that shape? and other variable information such as size of the polygons and other stuff like that?
Thank you for reading.
I hope the question to be understood.
By the way, this is the code:
- import peasy.*;
- import processing.opengl.*;
- import toxi.geom.*;
- import processing.pdf.*;
- PeasyCam cam;
- Vertice[] vert = new Vertice[12];
- int fondo = 20;
- float fi;
- boolean recordPDF = false;
- void setup()
- {
- //size(900, 562, P3D);
- size(screen.width, screen.height, OPENGL);
- background(fondo);
- cam = new PeasyCam(this, 300);
- fi = (1+sqrt(5))/2;
- vert[0] = new Vertice(0,30,fi*30);
- vert[1] = new Vertice(30,fi*30,0);
- vert[2] = new Vertice(fi*30,0,30);
- vert[3] = new Vertice(0,-30,fi*30);
- vert[4] = new Vertice(-fi*30, 0,30);
- vert[5] = new Vertice(-30,fi*30,0);
- vert[6] = new Vertice(0,30,-fi*30);
- vert[7] = new Vertice(fi*30,0,-30);
- vert[8] = new Vertice(30,-fi*30,0);
- vert[9] = new Vertice(-30,-fi*30,0);
- vert[10] = new Vertice(-fi*30,0,-30);
- vert[11] = new Vertice(0,-30,-fi*30);
- }
- void draw()
- {
- if(frameCount == 2000)
- {
- recordPDF = true;
- }
- if(frameCount > 2000)
- {
- frameCount = 0;
- setup();
- //exit();
- }
- background(fondo);
- if (recordPDF) {
- beginRaw(PDF, "PDF/"+year()+"-"+month()+"-"+day()+"-"+hour()+"-"+minute()+"-"+second()+"-"+millis()+".pdf" );
- noStroke();
- fill(fondo);
- sphereDetail(6);
- sphere(1000);
- }
- lights();
- stroke(0);
- //pushMatrix();
- //rotateX(radians(frameCount));
- rotateY(radians(frameCount/4.0));
- for (int i = 0; i < vert.length; i++)
- {
- vert[i].run();
- }
- //noStroke();
- stroke(255,20);
- strokeWeight(1);
- beginShape(TRIANGLE_FAN);
- for (int i = 0; i < 6; i++)
- {
- fill(vert[i].r, vert[i].g, vert[i].b, vert[i].a);
- vertex(vert[i].pos.x, vert[i].pos.y, vert[i].pos.z);
- }
- fill(vert[1].r, vert[1].g, vert[1].b, vert[1].a);
- vertex(vert[1].pos.x, vert[1].pos.y, vert[1].pos.z);
- endShape();
- beginShape(TRIANGLE_FAN);
- for (int i = 11; i > 5; i--)
- {
- fill(vert[i].r, vert[i].g, vert[i].b, vert[i].a);
- vertex(vert[i].pos.x, vert[i].pos.y, vert[i].pos.z);
- }
- fill(vert[10].r, vert[10].g, vert[10].b, vert[10].a);
- vertex(vert[10].pos.x, vert[10].pos.y, vert[10].pos.z);
- endShape();
- beginShape(TRIANGLE_STRIP);
- int num = 1;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 7;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 2;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 8;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 3;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 9;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 4;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 10;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 5;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 6;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 1;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- num = 7;
- fill(vert[num].r, vert[num].g, vert[num].b, vert[num].a);
- vertex(vert[num].pos.x, vert[num].pos.y, vert[num].pos.z);
- endShape();
- //popMatrix();
- //fill(255);
- //text(frameCount, -width/2 + 20, -height/2 + 20, -400);
- if (recordPDF) {
- endRaw();
- recordPDF = false;
- }
- //saveFrame("SEC/img_####.png");
- }
- void mouseClicked()
- {
- setup();
- }
- void keyPressed()
- {
- if(key == 's')
- {
- recordPDF = true;
- }
- }
- class Vertice
- {
- Vec3D origen;
- Vec3D pos;
- Vec3D vel;
- Vec3D acel;
- int r;
- int g;
- int b;
- int a;
- float sc;
- ArrayList points = new ArrayList();
- int sampleDistance = 10;
- Vertice (float x, float y, float z)
- {
- origen = new Vec3D(x, y, z);
- pos = new Vec3D(x, y, z);
- vel = new Vec3D(random(-0.5,0.5), random(-0.5,0.5), random(-0.5,0.5));
- acel = new Vec3D(0,0,0);
- r = int(random(70, 255));
- g = int(random(70, 255));
- b = int(random(70, 200));
- a = int(random(255));
- sc = random(100);
- //deformar();
- }
- void run()
- {
- //display();
- mover();
- flock();
- volver(10);
- splineDraw();
- }
- void volver(float magnitud)
- {
- if(pos.magnitude() > 300)
- {
- vel = pos.scale(-1);
- }
- Vec3D steer = new Vec3D();
- float distancia = pos.distanceTo(origen);
- if(distancia > 20)
- {
- Vec3D diff = pos.sub(origen);
- diff.normalizeTo(1.0/distancia);
- steer.addSelf(diff);
- }
- steer.scaleSelf(magnitud);
- acel.addSelf(steer);
- }
- void display()
- {
- strokeWeight(5);
- stroke(r, g, b, a);
- point(pos.x, pos.y, pos.z);
- }
- void deformar()
- {
- pos.normalize();
- pos.scaleSelf(sc);
- }
- void mover()
- {
- vel.addSelf(acel);
- vel.limit(2);
- pos.addSelf(vel);
- acel.clear();
- }
- void flock()
- {
- separar(5);
- cohesion(0.001);
- alinear(0.1);
- }
- void separar(float magnitud)
- {
- Vec3D steer = new Vec3D();
- int count = 0;
- for(int i = 0; i < vert.length; i++)
- {
- Vertice otro = (Vertice) vert[i];
- //Vec3D otro = new Vec3D(vert[i].pos);
- float distancia = pos.distanceTo(otro.pos);
- if(distancia > 0 && distancia < 50)
- {
- Vec3D diff = pos.sub(otro.pos);
- diff.normalizeTo(1.0/distancia);
- steer.addSelf(diff);
- count++;
- }
- }
- if(count > 0)
- {
- steer.scaleSelf(1.0/count);
- }
- steer.scaleSelf(magnitud);
- acel.addSelf(steer);
- }
- void cohesion(float magnitud)
- {
- Vec3D sum = new Vec3D();
- int count = 0;
- for(int i = 0; i < vert.length; i++)
- {
- Vertice otro = (Vertice) vert[i];
- float distancia = pos.distanceTo(otro.pos);
- if(distancia > 0 && distancia < 60)
- {
- sum.addSelf(otro.pos);
- count++;
- }
- }
- if(count > 0)
- {
- sum.scaleSelf(1.0/count);
- }
- Vec3D steer = sum.sub(pos);
- steer.scaleSelf(magnitud);
- acel.addSelf(steer);
- }
- void alinear(float magnitud)
- {
- Vec3D steer = new Vec3D();
- int count = 0;
- for(int i = 0; i < vert.length; i++)
- {
- Vertice otro = (Vertice) vert[i];
- float distancia = pos.distanceTo(otro.pos);
- if( distancia > 0 && distancia < 40)
- {
- steer.addSelf(otro.vel);
- count++;
- }
- }
- if(count > 0)
- {
- steer.scaleSelf(1.0/count);
- }
- steer.scaleSelf(magnitud);
- acel.addSelf(steer);
- }
- void splineDraw()
- {
- int numP = points.size();
- Vec3D currP = new Vec3D(pos);
- if(numP > 0)
- {
- Vec3D prevP = (Vec3D) points.get(numP-1);
- if(currP.distanceTo(prevP) > sampleDistance)
- {
- points.add(currP);
- }
- }
- else
- {
- points.add(currP);
- }
- numP = points.size();
- Vec3D[] handles = new Vec3D[numP];
- for(int i = 0; i < numP; i++)
- {
- Vec3D p = (Vec3D) points.get(i);
- handles[i] = p;
- }
- if(numP > 3)
- {
- Spline3D spline = new Spline3D(handles);
- java.util.List vertices = spline.computeVertices(3);
- //noFill();
- fill(r, g, b, a);
- stroke(r, g, b, a);
- strokeWeight(1);
- beginShape();
- for(Iterator i = vertices.iterator(); i.hasNext();)
- {
- Vec3D v = (Vec3D) i.next();
- vertex(v.x, v.y, v.z);
- }
- endShape();
- }
- if(numP > 10)
- {
- //hacer que se vayan borrando los puntos mas antiguos
- }
- }
- }
1