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


Click on anar+ terms to get the documentation.

import processing.opengl.*;
import anar.*;
 
 
 
import java.util.*;
 
import voronoi.*;
 
 
/*
 * Example for Anar library by Guillaume LaBelle + Julien Nembrini
 * http://anar.ch
 */
 
 
Anar      myScene;
Obj       myObj;
 
ArrayList megaContainer;
 
void setup(){
    size(800,400,OPENGL);
  Anar.init(this);
  Anar.drawAxis();
 
  initForm();
}
 
void initForm(){
  myObj = new Obj();
 
 
  // RANDOMS POINTS
  Obj inPts = new Obj();
  for (int i = 0; i<200; i++)
    inPts.add(Anar.PtRnd(400,400));
 
 
  // INIT THE TRIANGULATION
  int sz = 1000000;
 
  Simplex firstTriangle = new Simplex(new Pnt[]{new Pnt( -sz, -sz), new Pnt(sz, -sz), new Pnt(0,sz)});
  DelaunayTriangulation dt = new DelaunayTriangulation(firstTriangle);
 
  // ADD THE POINTS
  for (int i = 0; i<inPts.numOfPts(); i++)
    dt.delaunayPlace(new Pnt(inPts.pt(i).x(),inPts.pt(i).y()));
 
 
  // int ii = 0;
 
  // RETURN EDGES
  megaContainer = new ArrayList();
 
  ArrayList simplexComparator = new ArrayList();
 
  for (Iterator it = dt.iterator(); it.hasNext();){
    Simplex triangle = (Simplex)it.next();
    for (Iterator otherIt = dt.neighbors(triangle).iterator(); otherIt.hasNext();){
 
      Simplex other = (Simplex)otherIt.next();
 
      Simplex[] ss = new Simplex[2];
      ss[0] = triangle;
      ss[1] = other;
 
      if( !isInList(simplexComparator,ss)){
        simplexComparator.add(ss);
 
        Simplex[] ss2 = new Simplex[2];
        ss2[0] = other;
        ss2[1] = triangle;
        simplexComparator.add(ss2);
 
 
        // println(simplexComparator.size());
 
 
        Pnt p = Pnt.circumcenter((Pnt[])triangle.toArray(new Pnt[0]));
        Pnt q = Pnt.circumcenter((Pnt[])other.toArray(new Pnt[0]));
        // readColor(voronoiColor,0);
        // draw(p,q);
        float v[] = new float[4];
 
        v[0] = (float)p.coord(0);
        v[1] = (float)p.coord(1);
        v[2] = (float)q.coord(0);
        v[3] = (float)q.coord(1);
 
        // println(ii++);
 
        megaContainer.add(v);
      }
      // else
      // println("-");
 
 
    }
  }
 
 
  println(megaContainer.size());
 
 
  myObj.add(inPts);
 
}
 
 
boolean isInList(ArrayList arr, Simplex[] ss){
  boolean out = false;
 
  for (int i = 0; i<arr.size(); i++){
    Simplex[] sss = (Simplex[])arr.get(i);
    if(sss[0]==ss[0]&&sss[1]==ss[1]){
      out = true;
      // println("+");
    }
  }
  return out;
}
 
 
Pt filterPts(ArrayList pts, float[] v){
  return filterPts(pts,v[0],v[1]);
}
 
 
Pt filterPts(ArrayList pts, float x, float y){
  Pt out = Anar.Pt(x,y);
 
  for (int i = 0; i<pts.size(); i++){
    Pt q = (Pt)pts.get(i);
 
    if(Math.abs(q.x()-x)<0.0001&&Math.abs(q.y()-y)<0.0001)
      out = q;
  }
 
  return out;
}
 
 
void draw(){
  background(255);
  myObj.draw();
 
  stroke(255,0,0);
  for (int i = 0; i<megaContainer.size(); i++){
    float v[] = (float[])megaContainer.get(i);
    // if(i%2==0)
    line(v[0],v[1],v[2],v[3]);
  }
}
 
void keyPressed(){
  if(key==' ')
    initForm();
}
 
 



screenshots