Sound Vase
in
Share your Work
•
1 year ago
What's the role of Computational Design in Industrial Design?
A series of experiments in how we might design physical objects with code.
Tell me what you think!
This one uses sound as an input and manipulates a 3d mesh with the sound wave.
- import ddf.minim.*;
- Minim minim;
- AudioInput in;
- import superCAD.*;
- boolean saveOneFrame = false;
- PVector [] thisrow;
- PVector [] lastrow;
- import peasy.*;
- PeasyCam cam;
- float buffSize;
- float ang;
- float angInc;
- float rad = 50;
- float amp = 10;
- float zSpacing = 5;
- boolean wireframe = false;
- float numHeight = 50;
- float htRadInc = (TWO_PI*.9)/numHeight;
- float vaseRadScayl = 20;
- PVector [][] points;
- PVector [][] origpoints;
- Quad [][] quads;
- //ArrayList lines = new ArrayList();
- //ArrayList tris = new ArrayList();
- //ArrayList quads = new ArrayList();
- void setup(){
- size(800, 800, P3D);
- //frameRate(60);
- //lights();
- minim = new Minim(this);
- // get a line in from Minim, default bit depth is 16
- in = minim.getLineIn(Minim.STEREO, 512);
- buffSize = in.bufferSize();
- cam = new PeasyCam(this,0,0,(numHeight*zSpacing/2), 300);
- thisrow = new PVector[int(buffSize)];
- lastrow = new PVector[int(buffSize)];
- points = new PVector[int(numHeight)][int(buffSize)];
- origpoints = new PVector[int(numHeight)][int(buffSize)];
- quads = new Quad[int(numHeight)][int(buffSize)];
- angInc = TWO_PI/buffSize;
- for(int i=0; i<numHeight; i++){
- rad = 50 + (vaseRadScayl*sin(i*htRadInc));
- for (int j=0; j<buffSize; j++){
- ang = j*angInc;
- points[i][j] = new PVector(rad*cos(ang), rad*sin(ang), i*zSpacing);
- origpoints [i][j] = points[i][j];
- }
- }
- for(int i=0; i<numHeight-1; i++){
- for (int j=0; j<buffSize; j++){
- if(j<buffSize-1){
- quads[i][j] = new Quad(new PVector(i, j), new PVector(i,j+1), new PVector(i+1, j+1), new PVector(i+1, j));
- } else {
- quads[i][j] = new Quad(new PVector(i, j), new PVector(i,0), new PVector(i+1, 0), new PVector(i+1, j));
- }
- }
- }
- }
- boolean run = false;
- float z=0;
- int pindex = 0;
- void draw(){
- background(255);
- if(saveOneFrame == true) {
- String Dateobj = year() + "-" + month() + "-" + day() + "-" + hour() + "-" + minute() + "-" + second() + ".obj";
- beginRaw("superCAD.ObjFile", Dateobj);
- }
- //println(z);
- //stroke(255);
- // draw the waveforms
- for(int i = 0; i < buffSize; i++){
- ang = i*angInc;
- PVector p = new PVector(in.left.get(i)*amp*cos(ang) + origpoints[int(z/abs(zSpacing))][i].x, in.left.get(i)*amp*sin(ang) + origpoints[int(z/abs(zSpacing))][i].y, z);
- PVector pSound = new PVector(in.left.get(i)*amp*cos(ang), in.left.get(i)*amp*sin(ang), 0);
- thisrow[i] = p;
- if (run) {
- points[int(z/abs(zSpacing))][i].add(pSound);
- }
- }
- stroke(150);
- PVector p0, p1, p2, p3;
- for(int i=0; i<numHeight; i++){
- for (int j=0; j<buffSize; j++){
- if(i<numHeight-1){
- quads[i][j].render();
- }
- }
- }
- for(int i = 0; i < buffSize; i++){
- strokeWeight(2);
- stroke(0,255,0);
- if (i<buffSize-1){
- line(points[int(z/abs(zSpacing))][i].x, points[int(z/abs(zSpacing))][i].y, points[int(z/abs(zSpacing))][i].z, points[int(z/abs(zSpacing))][i+1].x, points[int(z/abs(zSpacing))][i+1].y, points[int(z/abs(zSpacing))][i+1].z);
- } else {
- line(points[int(z/abs(zSpacing))][i].x, points[int(z/abs(zSpacing))][i].y, points[int(z/abs(zSpacing))][i].z, points[int(z/abs(zSpacing))][0].x, points[int(z/abs(zSpacing))][0].y, points[int(z/abs(zSpacing))][0].z);
- }
- stroke(255,0,0);
- if (i<buffSize-1){
- line(thisrow[i].x, thisrow[i].y, thisrow[i].z, thisrow[i+1].x, thisrow[i+1].y, thisrow[i+1].z);
- } else {
- line(thisrow[i].x, thisrow[i].y, thisrow[i].z, thisrow[0].x, thisrow[0].y, thisrow[0].z);
- }
- }
- // for (int i=0; i<quads.size(); i++){
- // Quad q = (Quad) quads.get(i);
- // q.render();
- // }
- for (int i=0; i<buffSize; i++){
- lastrow[i] = thisrow[i];
- }
- z += zSpacing;
- if(frameCount%(numHeight-1) == 0){
- zSpacing *= -1;
- }
- // if (run){
- // cam.lookAt(buffSize/2,0,z, 250);
- // z+=20;
- // }
- if (frameCount%5==0){
- //println("save!");
- String Date = year() + "-" + month() + "-" + day() + "-" + hour() + "-" + minute() + "-" + second() + ".tiff";
- save(Date);
- }
- if(saveOneFrame == true) {
- endRaw();
- saveOneFrame = false;
- }
- }
- void keyPressed(){
- if (key == 'r'){
- run = !run;
- println(run);
- }
- if (key == 's'){
- saveOneFrame = true;
- }
- if (key == 'w'){
- wireframe = !wireframe;
- }
- }
- void stop()
- {
- // always close Minim audio classes when you are done with them
- in.close();
- minim.stop();
- super.stop();
- }
- class Triangle{
- PVector a;
- PVector b;
- PVector c;
- Triangle(PVector A, PVector B, PVector C){
- a = A;
- b = B;
- c = C;
- }
- void render(){
- beginShape(TRIANGLES);
- vertex(a.x, a.y, a.z);
- vertex(b.x, b.y, b.z);
- vertex(c.x, c.y, c.z);
- endShape();
- }
- }
- class Quad{
- PVector a;
- PVector b;
- PVector c;
- PVector d;
- Quad(PVector A, PVector B, PVector C, PVector D){
- a = A;
- b = B;
- c = C;
- d = D;
- }
- void render(){
- strokeWeight(1);
- stroke(50);
- if (wireframe){
- noFill();
- } else {
- fill(240);
- }
- beginShape(QUADS);
- vertex(points[int(a.x)][int(a.y)].x, points[int(a.x)][int(a.y)].y, points[int(a.x)][int(a.y)].z);
- vertex(points[int(b.x)][int(b.y)].x, points[int(b.x)][int(b.y)].y, points[int(b.x)][int(b.y)].z);
- vertex(points[int(c.x)][int(c.y)].x, points[int(c.x)][int(c.y)].y, points[int(c.x)][int(c.y)].z);
- vertex(points[int(d.x)][int(d.y)].x, points[int(d.x)][int(d.y)].y, points[int(d.x)][int(d.y)].z);
- endShape();
- }
- }