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:   Sierpinsky00a.pde
   JAVA Download:   Sierpinsky00a.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;
 
Sliders mySliders;
 
int     nIteration = 0;
 
 
void setup(){
    size(800,400,OPENGL);
  Anar.init(this);
 
  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);
 
  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);
  mySliders = new Sliders(obj);
  mySliders = new Sliders(obj);
}
 
void sierpinskySubdiv(){
 
  nIteration++;
  println(nIteration);
 
  final float z = 20;
 
  ArrayList newFaces = new ArrayList();
 
 
  for (int i = 0; i<obj.numOfFaces(); i++){
    Face f = obj.face(i);
 
    // 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(random((float)z/ (nIteration*nIteration)),random((float)z/ (nIteration*nIteration)),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);
      newFaces.add(f4);
    }
    newFaces.add(f1);
    newFaces.add(f2);
    newFaces.add(f3);
 
    // newFaces.add(f);
  }
 
  obj = new Obj();
 
  for (int i = 0; i<newFaces.size(); i++)
    obj.add((Face)newFaces.get(i));
 
  Anar.camTarget(obj);
  mySliders = new Sliders(obj);
}
 
 
void draw(){
  background(153);
 
  // ParametricValue v = parameters.get(0);
  // v.set(v.get()+ random(10)-5);
 
  obj.draw();
  mySliders.draw();
}
 
 
 
boolean addFourth = false;
 
 
void keyPressed(){
 
  switch(key){
    case 'q':
      sierpinskySubdiv();
    break;
    case 'w':
      addFourth = !addFourth;
    break;
    case 'e':
      reset();
    break;
 
 
  }
 
 
}
 
 



screenshots