package p5;
import anar.*;




import processing.core.PApplet;

public class Test03fFoldingDisasterC extends PApplet {

  /*
   * Example for Anar library by Guillaume LaBelle + Julien Nembrini
   * http://anar.ch
   */


  Obj myObj = new Obj();


  public void setup(){
    size(800,400,OPENGL);
    frameRate(200);

    Anar.init(this);
    Anar.drawAxis(true);

    initForm();
  }


  void initForm(){


    // CREATE TWO CONTAINERS TO STORE THE POINTS
    // TWO LINES PARRALELS WITH POINTS
    Pts ptsA = new Pts();
    Pts ptsB = new Pts();


    // SET TWO TRANSFORMATIONS FOR REUSE
    Translate sideWidth = new Translate(0,30,0);
    Translate sideHeight = new Translate(10,10,10);


    // CREATE A FIRST POINT
    // ASECOND FOR THE NEXT LINE
    Pt oriA = Anar.Pt(10,20,0);
    Pt oriB = Anar.Pt(oriA,sideWidth);


    // CREATE ALL POINTS FROM sideHeight at EACH STEPS
    for (int i = 0; i<20; i++){
      Pt tmpA = Anar.Pt(oriA,sideHeight);
      Pt tmpB = Anar.Pt(oriB,sideHeight);

      ptsA.add(tmpA);
      ptsB.add(tmpB);

      // Swap oriA and oriB
      oriA = tmpA;
      oriB = tmpB;
    }


    RotateY r = new RotateY((float)Math.PI/16);


    // I HAVE THEN TWO PARRALLEL LINES
    // I'LL CREATE FACES FROM EACH PAIRS
    for (int i = 0; i<ptsA.numOfPts()-1; i++){

      // FIRST TRIANGLE ADJ
      Face triangleA = new Face();
      triangleA.add(ptsA.pt(i));
      triangleA.add(ptsA.pt(i+1));
      triangleA.add(ptsB.pt(i+1));
      triangleA.add(ptsB.pt(i));

      Transform relativeRotation = new Transform(ptsA.pt(i),ptsA.pt(i+1),r);

      triangleA.apply(relativeRotation);

      myObj.add(triangleA);


      // //FIRST TRIANGLE OPPOSITE
      // Face triangleB = new Face();
      // triangleB.add(ptsB.pt(i));
      // triangleB.add(ptsB.pt(i+1));
      // triangleB.add(ptsA.pt(i+1));
      //      
      // myObj.add(triangleB);

    }


    // myObj.add(ptsA);
    // myObj.add(ptsB);


    // //For each pair of faces (expt. the last)
    // for(int i=0; i<1; i++)
    // {
    // Face face1 = myObj.face(i);
    // Face face2 = myObj.face(i+1);
    //
    // Transform relativeRotation = new Transform(face1.pt(0),face1.pt(1),r);
    //
    //      
    // face2.apply(relativeRotation);
    // }

    myObj.fill(255,255,0);

    Anar.camTarget(myObj);
    Anar.sliders(myObj);
  }


  public void draw(){
    background(155);

    myObj.draw();
  }


  public static void main(String[] args){
    PApplet.main(new String[]{Test03fFoldingDisasterC.class.getName()});
  }
}
