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:   Sierpinsky00cVerticesFreakMagic.pde
   JAVA Download:   Sierpinsky00cVerticesFreakMagic.java


Click on anar+ terms to get the documentation.

import processing.opengl.*;
import anar.*;
 
 
import java.util.ArrayList;
 
 
 
/*
 * Example for Anar library by Guillaume LaBelle + Julien Nembrini
 * http://anar.ch
 */
 
 
Sliders parameters;
 
Pt      a, b, c;
 
Obj     obj;
 
int     nIteration = 0;
 
void setup(){
    size(800,400,OPENGL);
  Anar.init(this);
 
  Scene.autoSeek = false;
 
  obj = new Obj();
 
  initForm();
 
  Pts.globalRender = new RenderPtsAll();
  // Face.globalRender = new RenderFaceMagicPower();
  Face.globalRender = new RenderFaceCurve(new AColor(255,30),new AColor(0));
  Obj.globalRender = new RenderObjFaceDefault();
 
}
 
 
void reset(){
  obj.faces.clear();
  obj.pts.ptList.clear();
 
  Pts facePts = new Pts();
  facePts.add(a);
  facePts.add(b);
  facePts.add(c);
  Face f = new Face(facePts);
 
  obj.add(f);
 
  nIteration = 0;
 
  addFourth = false;
}
 
void initForm(){
 
  a = Anar.Pt( -60, -30);
  b = Anar.Pt(60, -30);
  c = Anar.Pt(0,60);
 
  // obj.add(AB);
  // obj.add(BC);
  // obj.add(AC);
 
 
  Pts facePts = new Pts();
  facePts.add(a);
  facePts.add(b);
  facePts.add(c);
  Face f = new Face(facePts);
 
  obj.add(f);
 
  parameters = new Sliders(a);
  // println(parameters);
 
}
 
void sierpinskyIteration(){
 
  nIteration++;
  println(nIteration);
 
  final float z = 20;
 
  ArrayList addFaces = new ArrayList();
  ArrayList removeFaces = new ArrayList();
 
  for (int k = 0; k<obj.numOfFaces(); k++){
    Face f = obj.face(k);
 
 
    // get the vertices of the triangle
    Pt aa = f.pt(0);
    Pt bb = f.pt(1);
    Pt cc = f.pt(2);
 
    if( (aa.length(a)<20)|| (bb.length(b)<20)|| (cc.length(c)<20)){
 
      // get the middle points
      Pts AB = new PtsMid(aa,bb,2);
      Pts BC = new PtsMid(bb,cc,2);
      Pts AC = new PtsMid(aa,cc,2);
 
      Pt ab = Anar.Pt(AB.pt(1));
      float param = z/ (nIteration*nIteration);
      float mult = .5f;
 
      ab.translate(mult* (random((float)param)-param/2),mult* (random((float)param)-param/2),param);
      // ab.translate(0, 0, z/(nIteration*nIteration));
 
      Pt bc = Anar.Pt(BC.pt(1));
      bc.translate(mult* (random((float)param)-param/2),mult* (random((float)param)-param/2),param);
      // bc.translate(0, 0, z/(nIteration*nIteration));
 
      Pt ac = Anar.Pt(AC.pt(1));
      ac.translate(mult* (random((float)param)-param/2),mult* (random((float)param)-param/2),param);
      // ac.translate(0, 0, z/(nIteration*nIteration));
 
      // add first subdivision
      Face f1 = new Face();
      f1.add(aa);
      f1.add(ab);
      f1.add(ac);
      // Face f1 = new Face(f1Pts);
 
      // add second subdivision
      Face f2 = new Face();
      f2.add(ab);
      f2.add(bb);
      f2.add(bc);
      // Face f2 = new Face(f2Pts);
 
      // add third subdivision
      Face f3 = new Face();
      f3.add(ac);
      f3.add(bc);
      f3.add(cc);
      // Face f3 = new Face(f3Pts);
 
      if(addFourth){
        // add fourth subdivision
        Face f4 = new Face();
        f4.add(ab);
        f4.add(bc);
        f4.add(ac);
        // Face f4 = new Face(f4Pts);
        addFaces.add(f4);
      }
      addFaces.add(f1);
      addFaces.add(f2);
      addFaces.add(f3);
 
 
      removeFaces.add(f);
    }
  }
 
  // remove previous iteration faces
  for (int k = 0; k<removeFaces.size(); k++)
    obj.removeFace((Face)removeFaces.get(k));
 
 
  // add new iteration faces
  for (int k = 0; k<addFaces.size(); k++)
    obj.add((Face)addFaces.get(k));
 
  // ////////////////////
  // Small Tweak Here (gll)
  Obj newFaces = new Obj();
  newFaces.addAllFaces(obj.faces);
 
  obj = new Obj();
 
  for (int i = 0; i<newFaces.numOfFaces(); i++)
    obj.add(newFaces.face(i));
 
  Anar.camTarget(obj);
 
  println(obj.parentList( -1));
  // println(obj.primitiveToString());
 
}
 
 
void draw(){
  background(153);
 
  // ParametricValue v = parameters.get(0);
  // v.set(v.get()+ random(10)-5);
 
  obj.draw();
}
 
 
 
boolean addFourth = false;
 
 
void keyPressed(){
 
  switch(key){
    case 'q':
      sierpinskyIteration();
    break;
    case 'w':
      addFourth = !addFourth;
    break;
    case 'e':
      reset();
    break;
    case 'a':
      Autolisp.export(obj,this);
    break;
 
 
  }
 
 
}
 
 



screenshots