BenTilbert an amusing variant on a 3D Hilbert

Previously, several of us were riffing on Sierpinski variants, this dragged me to OpenProcessing and set me on task to update some of my older contributions. Also @neilcsmith set me thinking about poor old Ben Tilbert, and it was about time he saw the light of day again.

My LSystem library is still available on github, but I never got on with Prisoner Johns template so it needs a manual install, here’s the sketch code:-


/**
 * A 3D LSystem example with a SimpleGrammar 
 * This LSystem library is available at Github
 * https://github.com/monkstone/LSystems
 */
 
 /* 
 * Copyright (c) 2011-20 Martin Prout
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.text.CharacterIterator;
import lsystem.Grammar;
import lsystem.SimpleGrammar;
import lsystem.turtle.RodTurtle;
import lsystem.util.ArcBall;
import lsystem.util.LUT;
import peasy.PeasyCam;
float HALF = PI/360; // half a degree error
String axiom = "A";
String production;
float THETA = HALF_PI + HALF;
float PHI = HALF_PI - HALF;
PeasyCam cam;
Grammar grammar;
 
void setup()
{
  size(600, 600, P3D);
  cam = new PeasyCam(this, -70,70,-70,250);
  cam.rotateX(PI/5);
  cam.rotateY(PI/5);
  noStroke();
  grammar = new SimpleGrammar(this, axiom);
  grammar.addRule('A', "B>F<CFC<F>D+F-D>F<1+CFC<F<B1^");
  grammar.addRule('B', "A+F-CFB-F-D1->F>D-1>F-B1>FC-F-A1^");
  grammar.addRule('C', "1>D-1>F-B>F<C-F-A1+FA+F-C<F<B-F-D1^");
  grammar.addRule('D', "1>CFB>F<B1>FA+F-A1+FB>F<B1>FC1^");
  grammar.generateGrammar(3);
}
  
public void draw()
{
  int repeats = 1;
  int col = color(0, 225, 0);
  lights();
  directionalLight(128, 128, 128, 0, 0, 1);
  background(0);
  CharacterIterator it = grammar.getIterator();
  for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
    switch (ch) {
    case 'F':
      fill(col);
      float len = 20;
      translate(0, 0, -len / 2);
      box(3, 3, len - 1.6);     
      translate(0, 0, -len / 2);
      box(3, 3, 3);
      break;
    case '+':
      rotateX(THETA * repeats);
      repeats = 1;
      break;
    case '-':
      rotateX(-THETA * repeats);
      repeats = 1;
      break; 
    case '>':
      rotateY(THETA * repeats);
      repeats = 1;
      break;
    case '<':
      rotateY(-THETA * repeats);
      repeats = 1;
      break;
    case '^':
      rotateZ(PHI * repeats);
      repeats = 1;
      break;
    case '1':
      repeats += 1; 
    case 'A':
    case 'B':
    case 'C':
    case 'D':
      break;
    default:
      System.err.println("character " + ch + " not in grammar"); 
    }
  }
}

The character iterator is no longer needed with recent java since we can now switch on a String.

4 Likes

Would be nice to have already build jars. :grin:

True I will look into it, in the meantime if you use the mvnw or mvnw.cmd you don’t need to install maven or anything.

Not easily. As adm I wrote path + mvnw.cmd clean install
It complained not found. Then after setting JAVA_HOME variable it complained wrong version,
There is where I stopped.

Here a link to zip file for moment whilst I’m working on updating junit dependency.

2 Likes

I couldn’t download, are the permissions given for the zip file?

I have changed permissions, funny I thought I had already granted viewers permission?

1 Like

Really nice! I’m trying to get a grip on the lib.
Why don’t you publish it?

2 Likes

now it works.

Thanks a ton!

Chrisir

2 Likes

It filled a slot at time, it was on project kenai when I created it, but since that closed down I’ve lost interest. I’ve got enough on my plate developing the ruby-processing projects (coding in ruby is so much nicer, and the people are nice too). It might suit me as an exercise to update it for processing4 java 11+, but I’d he happy to transfer ownership.

2 Likes