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


Click on anar+ terms to get the documentation.

import processing.opengl.*;
import anar.*;
 
 
import java.util.*;
 
import lsys.Grammar;
 
 
 
/*
 * Example for Anar library by Guillaume LaBelle + Julien Nembrini
 * http://anar.ch
 */
 
 
Pts       ptsA = new Pts();
 
 
Pts       pts;
Param     param;
 
Grammar   grammar;
 
Obj       faces;
Obj       lines;
 
Transform T;
 
Translate t;
Transform r;
Scale     s;
 
Sliders   mySlider;
 
 
void setup(){
    size(800,400,OPENGL);
  Anar.init(this);
  initGrammar();
  initForm();
  interpretGrammar();
}
 
void initGrammar(){
  grammar = new Grammar("fg");
  // here define the rules
  // * means any kind of symbol
  // the example rules below are therefore non contextual
  grammar.addRule("*f*","fg[gf][hfh]");
  grammar.addRule("*g*","gg[hif]");
  grammar.addRule("*h*","ghjh");
  grammar.addRule("*j*","[gih]");
  // this one makes it context dependant
  grammar.addRule("igh","[ghfg]");
 
  println(grammar);
 
}
 
void initForm(){
  faces = new Obj();
 
  t = new Translate(0,0,10);
 
  param = new Param(10);
  mySlider = new Sliders(faces);
 
}
 
 
void interpretGrammar(){
 
  faces = new Obj();
  lines = new Obj();
 
  Pt p = Anar.Pt( -30,0,0);
  Pt q = Anar.Pt(30,0,0);
 
 
  Pts seedSeg = new PtsMid(p,q,param);
  Pts currentFace = seedSeg;
 
  Pts stackA = new Pts();
  int indexA = 0;
  Pt turtleA = seedSeg.pt(indexA);
 
  ArrayList stackPtsA = new ArrayList();
  Pts ptsCollectorA = new Pts();
  ptsCollectorA.add(turtleA);
 
 
  Iterator it = grammar.getSentence().iterator();
  while (it.hasNext()){
    String str = (String)it.next();
 
    switch(str.charAt(0)){
      case 'f':
        // create translated copy from current face
        Pts pts = new PtsMid(Anar.Pt(currentFace.pt(0),t),Anar.Pt(currentFace.pt(currentFace.size()-1),t),param);
        // pts = new Pts();
        // Iterator<Pt> itFace = currentFace.iterator();
        // while (itFace.hasNext()) {
        // pts.add(Anar.Pt(itFace.next(), t));
        // }
        // TODO (1) add size() method to Face
        // TODO (1) transform the face (missing methods)
        faces.add(pts);
 
        // move the turtle to the next face
        currentFace = pts;
        indexA %= currentFace.numOfPts();
        turtleA = currentFace.pt(indexA);
 
      case 'g':
        indexA = (indexA+1)%currentFace.numOfPts();
        turtleA = currentFace.pt(indexA);
 
      break;
      case 'h':
        indexA = (indexA+currentFace.numOfPts()-1)%currentFace.numOfPts();
        turtleA = currentFace.pt(indexA);
 
      break;
      case 'i':
        indexA = (indexA+2)%currentFace.numOfPts();
        turtleA = currentFace.pt(indexA);
 
      break;
      case 'j':
        indexA = (indexA+currentFace.numOfPts()-2)%currentFace.numOfPts();
        turtleA = currentFace.pt(indexA);
 
      break;
      case '[':
        stackA.add(turtleA);
        stackPtsA.add(ptsCollectorA);
        ptsCollectorA = new Pts();
        ptsCollectorA.add(turtleA);
 
      break;
      case ']':
        ptsCollectorA.add(turtleA);
        turtleA = stackA.remove(stackA.size()-1);
        lines.add(ptsCollectorA);
        ptsCollectorA = (Pts)stackPtsA.remove(stackPtsA.size()-1);
 
      break;
      default:
      break;
    }
  }
  lines.pts.render = new RenderPtsLine(new AColor(128));
 
  Anar.camTarget(faces);
  mySlider = new Sliders(lines);
 
}
 
void draw(){
  if(frameCount%2==0)
    background(155);
  else
    background(153);
 
  faces.draw();
  lines.draw();
  mySlider.draw();
 
}
 
 
void keyPressed(){
  if(key=='a'){
    grammar.step();
    println(grammar);
    interpretGrammar();
  }
  if(key=='s'){
    grammar.reset();
    println(grammar);
    interpretGrammar();
 
  }
}
 
 
 
 



screenshots