This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

anar+

by   LaBelle + Nembrini
©2008

built with ( )
   examples index
Rotate: middle click or key[1]
Zoom in|out: wheel button or key[2]
AutoRotate: key[5]
(First Click inside the applet to enable keys)

This applet use OpenGL, you might have to install extra jogl libraries once to view this applet. You may have a look at image capture and video at the bottom of this page. You might accept security security permenently to remove the security prompts on each pages.



sourcecode


   PDE Download:   Test02tTower.pde
   JAVA Download:   Test02tTower.java


Click on anar+ terms to get the documentation.

import processing.opengl.*;
import processing.opengl.*;
import anar.*;
 
 
 
 
/*
 * Example for Anar library by Guillaume LaBelle + Julien Nembrini
 * http://anar.ch
 */
 
 
Obj     towerCore         = new Obj();
Obj     contourLines      = new Obj();
Obj     verticalLines     = new Obj();
Obj     windows           = new Obj();
Obj     structure         = new Obj();
 
Obj     allObjects        = new Obj();
 
Sliders mySliders;
 
boolean calculateWindows  = false;
boolean calculateVertical = false;
 
 
void setup(){
    size(800,400,OPENGL);
  Anar.init(this);
 
  // Setup DEFAULT rendering of our scene
  Pts.globalRender = new RenderPtsLine();
  Anar.drawAxis(true);
  // Scene.lights = false;
 
  // anar.defaultScene = false;
 
  initForm();
}
 
 
void initForm(){
 
  // //////////////////////////////////////////
  // //////////////////////////////////////////
  // Initial SHAPE
 
  // Here, we create an arbitrary shape
  Face iShape;
  iShape = new Star(100,50,5);
 
 
  // //////////////////////////////////////////
  // //////////////////////////////////////////
  // LEVEL
 
  // The initial shape is duplicated Applying always the same predefined
  // Transformation
 
  Param numOfSubDivisionsOnEachSides = new Param(5);
 
  Transform combo = new Transform();
  combo.translate(0,0,5);
  combo.scale(0.95f,0.985f,1.02f);
  combo.rotateZ(.06f);
 
  for (int i = 0; i<40; i++){
    Face floorShape = new Face(iShape,combo);
    towerCore.add(floorShape);
    iShape = floorShape;
  }
 
  // //////////////////////////////////////////
  // //////////////////////////////////////////
  // VERTICALES
 
  if(calculateVertical){
    for (int i = 0; i<40; i++){
      Face shape = towerCore.face(i);
 
      Pts contour;
      Pts tmpPtList = new Pts();
 
      for (int j = 0; j<shape.size(); j++){
        int jj = (j+1)%shape.size();
        contour = new PtsMid(shape.pt(j),shape.pt(jj),numOfSubDivisionsOnEachSides);
        contour.remove(contour.size()-1); // Remove the last one from the set
        tmpPtList.addPointsFrom(contour);
      }
 
      contourLines.add(tmpPtList);
    }
 
 
    int nodesPerLevel = contourLines.line(0).size();
 
    for (int j = 0; j<nodesPerLevel; j++){
      if(j%3!=0){
        Pts tmpPtList = new Pts();
        for (int i = 0; i<contourLines.numOfLines(); i++){
          Pts a = contourLines.getLine(i);
          tmpPtList.add(a.pt( (j+1*i)%nodesPerLevel));
        }
        verticalLines.add(tmpPtList);
      }
    }
  }
 
  // //////////////////////////////////////////
  // //////////////////////////////////////////
  // WINDOWS
 
  Param offset1 = new Param(.05f);
  Param offset2 = new Param(.5f);
  Param ratioI = new Param(8);
 
  if(calculateWindows)
    for (int i = 1; i<verticalLines.numOfLines(); i += 2){
      Pts a = verticalLines.line(i);
      Pts b = verticalLines.line( (i+1)%verticalLines.numOfLines());
 
      for (int j = 0; j<a.size()-1; j++){
        Pts k = new PtsMid(a.pt(j),a.pt(j+1),ratioI);
        Pts l = new PtsMid(b.pt(j),b.pt(j+1),ratioI);
 
        Pt aa = k.pt(1);
        Pt bb = a.pt(j+1);
        Pt cc = b.pt(j+1);
        Pt dd = l.pt(1);
 
        PtNormal nn = new PtNormal(aa,bb,cc,offset1);
        PtNormal kk = new PtNormal(bb,cc,dd,offset2);
        PtNormal mm = new PtNormal(cc,dd,aa,offset2);
        PtNormal ll = new PtNormal(dd,aa,bb,offset1);
 
        Pts c;
 
        c = new Pts();
        c.add(bb);
        c.add(nn);
        windows.add(c);
 
        c = new Pts();
        c.add(dd);
        c.add(mm);
        windows.add(c);
 
        Face f = new Face();
        f.add(nn);
        f.add(kk);
        f.add(mm);
        f.add(ll);
        windows.add(f);
      }
    }
 
 
  // //////////////////////////////////////////
  // //////////////////////////////////////////
  // STRUCTURE
 
  Obj pointsOnFloors = new Obj();
 
  for (int i = 0; i<towerCore.numOfFaces(); i++){
    Pts structurePts = new Pts();
    Face shape = towerCore.face(i);
    // structurePts.add(p);
 
    for (int j = 0; j<shape.numOfPts(); j++){
      float[] w;
      PtBary q;
 
      w = new float[shape.size()];
      w[j] = 3.5f;
      w[ (j+1)%shape.numOfPts()] = .2f;
      q = new PtBary(shape,w);
      q.normalizeWeight();
      structurePts.add(q);
 
      w = new float[shape.size()];
      w[j] = 3.5f;
      w[ (j-1+shape.numOfPts())%shape.numOfPts()] = .2f;
      q = new PtBary(shape,w);
      q.normalizeWeight();
      structurePts.add(q);
 
      w = new float[shape.size()];
      w[j] = 2.3f;
      w[ (j-1+shape.numOfPts())%shape.numOfPts()] = .15f;
      q = new PtBary(shape,w);
      q.normalizeWeight();
      structurePts.add(q);
 
      w = new float[shape.size()];
      w[j] = 2.3f;
      w[ (j+1)%shape.numOfPts()] = .15f;
      q = new PtBary(shape,w);
      q.normalizeWeight();
      structurePts.add(q);
    }
 
    pointsOnFloors.add(structurePts);
  }
 
 
  for (int i = 0; i<pointsOnFloors.numOfLines()-1; i++){
    Pts q = pointsOnFloors.line(i);
    Pts r = pointsOnFloors.line(i+1);
    for (int j = 0; j<q.size(); j += 4){
      Face p;
 
      for (int k = 0; k<4; k++){
        p = new Face();
        p.add(q.pt(j+k));
        p.add(r.pt(j+k));
        p.add(r.pt( (j+ (k+1)%4)));
        p.add(q.pt( (j+ (k+1)%4)));
        structure.add(p);
      }
    }
  }
 
 
  // //////////////////////////////////////////
  // HIRARCHY
 
  Anar.camTarget(towerCore);
  mySliders = new Sliders(structure);
 
  // Store All objects in one group
  allObjects.add(towerCore);
  allObjects.add(verticalLines);
  allObjects.add(windows);
  allObjects.add(structure);
 
 
}
 
 
void draw(){
  background(200);
 
  towerCore.draw();
  // verticales.draw();
  // contourLines.draw();
  // windows.draw();
  structure.draw();
 
  mySliders.draw();
 
  // //////////////////////////
  // AUTO THUMBNAILER
  // if(Anar.scene.drawAxis)
  // anar.scene.drawAxis();
    // // hint(ENABLE_OPENGL_2X_SMOOTH);
  // anar.scene.actualView.head(5);
  // if(frameCount>20&&frameCount%5==0){
  // saveFrame("myFrame"+nf(((frameCount-25)/5),2)+".tga");
  // Scene.autoRotateZ = 0.05f;
  // Scene.autoRotateX = -0.02f;
  // anar.scene.actualView.head(-60);
  // }
  // if(frameCount>99){
  // this.stop();
  // this.exit();
  // }
  // //////////////////////////
 
}
 
 
void keyPressed(){
 
  switch(key){
    case 'a':
      Autolisp.export(allObjects,this);
    break;
    case 'r':
      RhinoScript.export(allObjects,this);
    break;
    case 's':
      SketchUpRuby.export(allObjects,this);
    break;
    case 'm':
      // PovRay.export(allObjects,this);
    break;
  }
}
 
 
 
 



screenshots