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:   Sierpinsky00bRandom.pde
   JAVA Download:   Sierpinsky00bRandom.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();
 
}
 
 
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;
 
  // Obj addFaces = new Obj();
  // Obj removeFaces = new Obj();
  ArrayList addFaces = new ArrayList();
  ArrayList removeFaces = new ArrayList();
 
 
  for (int k = 0; k<obj.numOfFaces(); k++){
    Face f = obj.face(k);
 
    if(random(1)>0.2f){
 
      // get the vertices of the triangle
      Pt aa = f.pt(0);
      Pt bb = f.pt(1);
      Pt cc = f.pt(2);
 
      // 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));
      ab.translate(0,0,z/ (nIteration*nIteration));
 
      Pt bc = Anar.Pt(BC.pt(1));
      bc.translate(0,0,z/ (nIteration*nIteration));
 
      Pt ac = Anar.Pt(AC.pt(1));
      ac.translate(0,0,z/ (nIteration*nIteration));
 
      // add first subdivision
      Pts f1Pts = new Pts();
      f1Pts.add(aa);
      f1Pts.add(ab);
      f1Pts.add(ac);
      Face f1 = new Face(f1Pts);
 
      // add second subdivision
      Pts f2Pts = new Pts();
      f2Pts.add(ab);
      f2Pts.add(bb);
      f2Pts.add(bc);
      Face f2 = new Face(f2Pts);
 
      // add third subdivision
      Pts f3Pts = new Pts();
      f3Pts.add(ac);
      f3Pts.add(bc);
      f3Pts.add(cc);
      Face f3 = new Face(f3Pts);
 
      if(addFourth){
        // add fourth subdivision
        Pts f4Pts = new Pts();
        f4Pts.add(ab);
        f4Pts.add(bc);
        f4Pts.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 i = 0; i<removeFaces.size(); i++){
    Face f = (Face)removeFaces.get(i);
    obj.removeFace(f);
  }
 
  // add new iteration faces
  for (int i = 0; i<addFaces.size(); i++){
    Face f = (Face)addFaces.get(i);
    obj.faces.add(f);
  }
 
  // ////////////////////
  // Small Tweak Here (gll)
  Obj newFaces = obj;
 
  obj = new Obj();
 
  for (int i = 0; i<newFaces.numOfFaces(); i++)
    obj.add(newFaces.face(i));
 
  Anar.camTarget(obj);
 
 
}
 
 
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;
 
 
  }
 
 
}
 
 



screenshots