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:   RecursivSierpinsky00aCleanUp.pde
   JAVA Download:   RecursivSierpinsky00aCleanUp.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;
Pts     facePts;
 
Obj     obj;
 
Param   div;
Param   zero;
 
Sliders mySlider;
 
int     nIteration = 0;
 
void setup(){
    size(800,400,OPENGL);
  Anar.init(this);
 
  Scene.autoSeek = false;
 
  initForm();
}
 
void initForm(){
  // definition of shape parameters
  div = new Param(2,2,10);
  zero = new Param(0);
 
  a = Anar.Pt( -60, -30);
  b = Anar.Pt(60, -30);
  c = Anar.Pt(0,60);
 
  reset();
}
 
void reset(){
  // construction of shape
  obj = new Obj();
 
  // add base triangle
  Face f = new Face();
  f.add(a);
  f.add(b);
  f.add(c);
  obj.add(f);
 
  // define sliders for shape
  mySlider = new Sliders(obj);
 
  nIteration = 0;
  addFourth = false;
}
 
void sierpinskyIteration(){
 
  nIteration++;
  println(nIteration);
 
  // define z translation
  float z = 10f;
 
  float param;
  if(positive)
    param = z/ (nIteration*nIteration);
  else
    param = -z/ (nIteration*nIteration);
  Translate t = new Translate(Anar.Pt(zero,zero,new Param(param)));
 
  // prepare container to store new faces
  ArrayList newFaces = new ArrayList();
 
  // go through each current face
  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);
 
    // get the middle points (by default div = 2)
    Pts AB = new PtsMid(aa,bb,div);
    Pts BC = new PtsMid(bb,cc,div);
    Pts AC = new PtsMid(cc,aa,div);
 
    // get the first in the sequence of middle points
    Pt ab = Anar.Pt(AB.pt(1),t);
    Pt bc = Anar.Pt(BC.pt(1),t);
    Pt ac = Anar.Pt(AC.pt(1),t);
 
    // add first subdivision
    Face addFace = new Face();
    addFace.add(aa);
    addFace.add(ab);
    addFace.add(ac);
    newFaces.add(addFace);
 
    // add second subdivision
    addFace = new Face();
    addFace.add(ab);
    addFace.add(bb);
    addFace.add(bc);
    newFaces.add(addFace);
 
    // add third subdivision
    addFace = new Face();
    addFace.add(ac);
    addFace.add(bc);
    addFace.add(cc);
    newFaces.add(addFace);
 
    if(addFourth){
      // add middle subdivisions with anchor
 
      // use point of gravity of original point as anchor
      Pt pp = new PtBary(f);
 
      // add faces with pp
      addFace = new Face();
      addFace.add(ab);
      addFace.add(bc);
      addFace.add(pp);
      newFaces.add(addFace);
 
      addFace = new Face();
      addFace.add(pp);
      addFace.add(bc);
      addFace.add(ac);
      newFaces.add(addFace);
 
      addFace = new Face();
      addFace.add(ab);
      addFace.add(pp);
      addFace.add(ac);
      newFaces.add(addFace);
    }
 
  }
 
  obj = new Obj();
 
  obj.addAllFaces(newFaces);
 
  Anar.camTarget(obj);
  mySlider = new Sliders(obj);
}
 
 
void draw(){
  background(153);
 
  obj.draw();
  mySlider.draw();
}
 
 
 
// interactivity related stuff
 
boolean addFourth = false;
boolean positive  = false;
 
void keyPressed(){
 
  switch(key){
    case 'q':
      sierpinskyIteration();
    break;
    case 'w':
      addFourth = !addFourth;
    break;
    case 'e':
      reset();
    break;
    case 'r':
      positive = !positive;
      ;
    break;
 
    case 'a':
      Autolisp.export(obj,this);
    break;
 
  }
 
}
 
 



screenshots