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


Click on anar+ terms to get the documentation.

import processing.opengl.*;
import anar.*;
 
 
 
import lsys.Grammar;
 
 
 
/*
 * Example for Anar library by Guillaume LaBelle + Julien Nembrini
 * http://anar.ch
 */
 
 
Obj       myObject;
 
Grammar   grammar;
 
Obj       box;
 
Transform T;
Translate initT;
 
Translate t;
RotateZ   r;
Scale     s;
 
 
void setup(){
    size(1000,500,OPENGL);
  Anar.init(this);
 
  Anar.drawAxis();
  initGrammar();
  interpretInit();
}
 
void initGrammar(){
  grammar = new Grammar("bt");
  // here define the rules
  // * means any kind of symbol
  // the example rules below are therefore non contextual
  grammar.addRule("*b*","brb");
  grammar.addRule("*t*","rssb");
  grammar.addRule("*r*","rs");
  grammar.addRule("*s*","s");
  // this one makes it context dependant
  // grammar.addRule("sss", "ss");
 
  println(grammar);
}
 
 
void interpretInit(){
  // base element
  box = new Box(10,10,50);
 
  // initial position
  initT = new Translate(0,50,0);
 
  // base transformations
  t = new Translate(Anar.Pt(0,10, -.001f));
  r = new RotateZ(.5f);
  s = new Scale(Anar.Pt(.99f,.99f,.99f));
 
  interpretGrammar();
}
 
void interpretGrammar(){
  myObject = new Obj();
  T = new Transform(initT);
 
  for (int i = 0; i<grammar.numOfSymbols(); i++){
 
    switch(grammar.symbol(i).charAt(0)){
      case 'b':
        Obj myCopy = new Obj(box,T);
        myObject.add(myCopy);
        T = new Transform(T);
      break;
      case 't':
        T.apply(t);
      break;
      case 'r':
        T.apply(r);
      break;
      case 's':
        T.apply(s);
      break;
      default:
      break;
 
    }
  }
  Anar.camTarget(myObject);
}
 
void draw(){
  background(153);
  myObject.draw();
}
 
 
void keyPressed(){
  if(key==' '){
    grammar.step();
    interpretGrammar();
    println(grammar);
  }
  if(key=='r'){
    grammar.reset();
    interpretInit();
    interpretGrammar();
    println(grammar);
 
  }
}
 
 
 
 



screenshots