how to connect processing with madmapper

edited March 2016 in Library Questions

if anyone know how to stream this into Madmapper as video?

import processing.sound.*;

AudioIn input;
Amplitude vol;
Icosahedron ico1;
Icosahedron ico2;
Icosahedron ico3;
Icosahedron ico4;
Icosahedron ico5;
Icosahedron ico6;
Icosahedron ico7;
Icosahedron ico8;
Icosahedron ico9;

void setup(){
     //fullScreen(P3D);
    size(1200,800,P3D);
    input = new AudioIn(this,0);
    input.start();
    vol = new Amplitude(this);
    vol.input(input);
    int scale;
    scale = int(map(vol.analyze(), 0,1.0,1,350));
    ico1 = new Icosahedron(90+scale);
    ico2 = new Icosahedron(50+scale);
    ico3 = new Icosahedron(30+scale);
    ico4 = new Icosahedron(35+scale);
    ico5 = new Icosahedron(20+scale);
    ico6 = new Icosahedron(125+scale);
    ico7 = new Icosahedron(220+scale);
    ico8 = new Icosahedron(300+scale);
    ico9 = new Icosahedron(65+scale);

}

void draw(){
  background(0);
  lights();
  translate(width/2, height/2);
  int scale;
  scale = int(map(vol.analyze(), 0,1.0,1,350));


  pushMatrix();
  //translate(-width/3.5, 0);
  rotateX(frameCount*PI/100/scale);
  rotateY(frameCount*PI/120/scale); 
  stroke(255, 255, 255);
  noFill();
  ico1.create();
  popMatrix();

    pushMatrix();
  //translate(-width/3.5, 0);
  rotateX(frameCount*PI/90/scale);
  rotateY(frameCount*PI/90/scale);
  stroke(255, 255, 255);
  noFill();
  ico2.create();
  popMatrix();

  pushMatrix();
  rotateX(frameCount*PI/60/scale);
  rotateY(frameCount*PI/70/scale);
  stroke(255, 255, 255);
  noFill();
  ico3.create();
  popMatrix();

  pushMatrix();
  //translate(width/3.5, 0);
  rotateX(frameCount*PI/10/scale);
  rotateY(frameCount*PI/10/scale);
  stroke(255,255,255);
  noFill();
  ico4.create();
  popMatrix();

    pushMatrix();
  rotateX(frameCount*PI/4/scale);
  rotateY(frameCount*PI/1/scale);
  stroke(255, 255, 255);
  noFill();
  ico5.create();
  popMatrix();

    pushMatrix();
  rotateX(frameCount*PI/20/scale);
  rotateY(frameCount*PI/-300/scale);
  stroke(255, 255, 255);
  noFill();
  ico6.create();
  popMatrix();

    pushMatrix();
  rotateX(frameCount*PI/100/scale);
  rotateY(frameCount*PI/100/scale);
  stroke(255, 255, 255);
  noFill();
  ico7.create();
  popMatrix();

      pushMatrix();
  rotateX(frameCount*PI/350/scale);
  rotateY(frameCount*PI/400/scale);
  stroke(255, 255, 255);
  noFill();
  ico8.create();
  popMatrix();

        pushMatrix();
  rotateX(frameCount*PI/150/scale);
  rotateY(frameCount*PI/2000/scale);
  stroke(255, 255, 255);
  noFill();
  ico9.create();
  popMatrix();


 }


class Dimension3D{
   float w, h, d;

   Dimension3D(float w, float h, float d){    

     this.w=w;
     this.h=h;
     this.d=d;
  }
}




abstract class Shape3D{
  float x, y, z;
  float w, h, d;

  Shape3D(){   
  }

  Shape3D(float x, float y, float z){    

    this.x = x;
    this.y = y;
    this.z = z;
  }

  Shape3D(PVector p){    

    x = p.x;
    y = p.y;
    z = p.z;
  }


  Shape3D(Dimension3D dim){    

    w = dim.w;
    h = dim.h;
    d = dim.d;
  }

  Shape3D(float x, float y, float z, float w, float h, float d){   

    this.x = x;
    this.y = y;
    this.z = z;
    this.w = w;
    this.h = h;
    this.d = d;
  }

  Shape3D(float x, float y, float z, Dimension3D dim){  

    this.x = x;
    this.y = y;
    this.z = z;
    w = dim.w;
    h = dim.h;
    d = dim.d;
  }

  Shape3D(PVector p, Dimension3D dim){
    x = p.x;
    y = p.y;
    z = p.z;
    w = dim.w;
    h = dim.h;
    d = dim.d;
  }

  void setLoc(PVector p){
    x=p.x;
    y=p.y;
    z=p.z;
  }

  void setLoc(float x, float y, float z){
    this.x=x;
    this.y=y;
    this.z=z;
  }


  // override if you need these
  void rotX(float theta){ 
  }

  void rotY(float theta){  
  }

  void rotZ(float theta){  
  }


  // must be implemented in subclasses
  abstract void init();
  abstract void create();
}




class Icosahedron extends Shape3D{

  // icosahedron
  PVector topPoint;
  PVector[] topPent = new PVector[5];
  PVector bottomPoint;
  PVector[] bottomPent = new PVector[5];
  float angle = 220, radius = 10;
  float triDist;
  float triHt;
  float a, b, c;

  // constructor
  Icosahedron(float radius){    
    this.radius = radius;
    init();
  }

  Icosahedron(PVector v, float radius){    
    super(v);

    this.radius = radius;
    init();

  }

  // calculate geometry
  void init(){
    c = dist(cos(0)*radius, sin(0)*radius, cos(radians(72))*radius,  sin(radians(72))*radius);
    b = radius;
    a = (float)(Math.sqrt(((c*c)-(b*b))));

    triHt = (float)(Math.sqrt((c*c)-((c/2)*(c/2))));

    for (int i=0; i<topPent.length; i++){
      topPent[i] = new PVector(cos(angle)*radius, sin(angle)*radius, triHt/2.0f);
      angle+=radians(72);
    }
    topPoint = new PVector(0, 0, triHt/2.0f+a);
    angle = 72.0f/2.0f;
    for (int i=0; i<topPent.length; i++){
      bottomPent[i] = new PVector(cos(angle)*radius, sin(angle)*radius, -triHt/2.0f);
      angle+=radians(72);
    }
    bottomPoint = new PVector(0, 0, -(triHt/2.0f+a));
  }

  //draws icosahedron; 
  void create(){   
    for (int i=0; i<topPent.length; i++){
      // icosahedron top
      beginShape();
      if (i<topPent.length-1){
        vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
        vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z);
        vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
      } 
      else {
        vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
        vertex(x+topPoint.x, y+topPoint.y, z+topPoint.z);
        vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z);
      }
      endShape(CLOSE);

      // icosahedron bottom
      beginShape();
      if (i<bottomPent.length-1){
        vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z);
        vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z);
        vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
      } 
      else {
        vertex(x+bottomPent[i].x, y+bottomPent[i].y, z+bottomPent[i].z);
        vertex(x+bottomPoint.x, y+bottomPoint.y, z+bottomPoint.z);
        vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
      }
      endShape(CLOSE);
    }

    // icosahedron body
    for (int i=0; i<topPent.length; i++){
      if (i<topPent.length-2){
        beginShape();
        vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
        vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
        vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z);
        endShape(CLOSE);

        beginShape();
        vertex(x+bottomPent[i+2].x, y+bottomPent[i+2].y, z+bottomPent[i+2].z);
        vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
        vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
        endShape(CLOSE);
      } 
      else if (i==topPent.length-2){
        beginShape();
        vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
        vertex(x+bottomPent[i+1].x, y+bottomPent[i+1].y, z+bottomPent[i+1].z);
        vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
        endShape(CLOSE);

        beginShape();
        vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
        vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
        vertex(x+topPent[i+1].x, y+topPent[i+1].y, z+topPent[i+1].z);
        endShape(CLOSE);
      }
      else if (i==topPent.length-1){
        beginShape();
        vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
        vertex(x+bottomPent[0].x, y+bottomPent[0].y, z+bottomPent[0].z);
        vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z);
        endShape(CLOSE);

        beginShape();
        vertex(x+bottomPent[1].x, y+bottomPent[1].y, z+bottomPent[1].z);
        vertex(x+topPent[i].x, y+topPent[i].y, z+topPent[i].z);
        vertex(x+topPent[0].x, y+topPent[0].y, z+topPent[0].z);
        endShape(CLOSE);
      }
    }
  }

  // overrided methods fom Shape3D
  void rotZ(float theta){    
    float tx=0, ty=0, tz=0;
    // top point
    tx = cos(theta)*topPoint.x+sin(theta)*topPoint.y;
    ty = sin(theta)*topPoint.x-cos(theta)*topPoint.y;
    topPoint.x = tx;
    topPoint.y = ty;

    // bottom point
    tx = cos(theta)*bottomPoint.x+sin(theta)*bottomPoint.y;
    ty = sin(theta)*bottomPoint.x-cos(theta)*bottomPoint.y;
    bottomPoint.x = tx;
    bottomPoint.y = ty;

    // top and bottom pentagons
    for (int i=0; i<topPent.length; i++){
      tx = cos(theta)*topPent[i].x+sin(theta)*topPent[i].y;
      ty = sin(theta)*topPent[i].x-cos(theta)*topPent[i].y;
      topPent[i].x = tx;
      topPent[i].y = ty;

      tx = cos(theta)*bottomPent[i].x+sin(theta)*bottomPent[i].y;
      ty = sin(theta)*bottomPent[i].x-cos(theta)*bottomPent[i].y;
      bottomPent[i].x = tx;
      bottomPent[i].y = ty;
    }
  }

  void rotX(float theta){ 
  }

  void rotY(float theta){  
  }
}
Tagged:

Answers

Sign In or Register to comment.