Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Wednesday, 6 June 2012

Ben Tilbert-Steel (updated for processing-2.0a6)

My povwriter2 library is now working well with processing-2.0a6, and includes a built in ArcBall and mouse wheel zoom (requires use of ArcBall), to record the sketch press the record button or ('r' key especially when button is hidden). Selecting a particular Hue eg Hue.STEEL, auto-selects the Finish.STEEL. Edit the generated ini file to do offline ray tracing at higher quality settings.

   1 /** 
   2  * Copyright (c) 2012 Martin Prout
   3  * 
   4  * This demo & library is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU Lesser General Public
   6  * License as published by the Free Software Foundation; either
   7  * version 2.1 of the License, or (at your option) any later version.
   8  * 
   9  * http://creativecommons.org/licenses/LGPL/2.1/
  10  * 
  11  * This library is distributed in the hope that it will be useful,
  12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14  * Lesser General Public License for more details.
  15  * 
  16  * You should have received a copy of the GNU Lesser General Public
  17  * License along with this library; if not, write to the Free Software
  18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  19  */
  20 
  21 import povexport2.ui.arcball.*;
  22 import povexport2.ui.*;
  23 import povexport2.*;
  24 import povexport2.povwriter.*;
  25 import lsystem.Grammar;
  26 import lsystem.SimpleGrammar;              
  27 
  28 
  29 /**
  30  * A 3D LSystem example with a SimpleGrammar (if you want to do a tree use StochasticGrammar)
  31  * Relies on the processing primitive box, and thereafter it makes sense to use Processing
  32  * translate and rotate (cf my 2D eamples where I use trignometry rather than these tools)
  33  * Uses 'conventional 3D grammar'. Features PeasyCam to allow easy manipulation of the object.
  34  * To create "Ben Tilbert" set theta to 90.5 deg and phi to 89.5
  35  */
  36 
  37 ArcBall arcball;
  38 Grammar grammar;
  39 PovExporter export;
  40 float distance = 200;
  41 int depth = 4;
  42 float theta = radians(89.5);
  43 float phi = radians(90.5);
  44 String production = "";
  45 
  46 void setup() {
  47   size(1280, 1024, P3D); 
  48   export = new PovExporter(this);
  49   export.chooseTemplate();  
  50   arcball = new ArcBall(this);
  51   export.showGui("false");   // hide record button (setting is saved)
  52   export.createIniFile(dataPath("hilbert.ini"), Quality.MEDIUM);
  53   setupGrammar();
  54   noStroke();
  55 }
  56 
  57 void setupGrammar() {
  58   grammar = new SimpleGrammar(this, "X");   // this only required to allow applet to call dispose()
  59   grammar.addRule('X', "^<XF^<XFX-F^>>XFX&F+>>XFX-F>X->");
  60   production = grammar.createGrammar(depth);
  61   distance *= pow(0.5, depth);
  62 }
  63 
  64 void draw() {
  65   if (export.traced()) { // begin tracing
  66     display();
  67   } 
  68   else {
  69     background(0);
  70     lights();
  71     export.beginRaw(dataPath("hilbert.pov"));
  72     translate(width / 2, height / 2, -width / 5);
  73     arcball.update();
  74     render();
  75     export.endRaw();
  76   }
  77 }
  78 
  79 void 
  80 render() {
  81   translate(-distance*3.5, distance*3.5, -distance*3.5);  // center the hilbert 
  82   export.setHue(Hue.STEEL); 
  83   lightSpecular(204, 204, 204); 
  84   specular(255, 255, 255); 
  85   shininess(1.0); 
  86   CharacterIterator it = grammar.getIterator(production);
  87   for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
  88     switch (ch) {
  89     case 'F': 
  90       translate(0, distance/-2, 0);
  91       box(distance/9, distance, distance/9);
  92       translate(0, distance/-2, 0);
  93       break;
  94     case '-':
  95       rotateX(theta);
  96       break;
  97     case '+':
  98       rotateX(-theta);
  99       break;
 100     case '>':
 101       rotateY(theta);
 102       break;
 103     case '<':
 104       rotateY(-theta);
 105       break;
 106     case '&':
 107       rotateZ(-phi);
 108       break;
 109     case '^':
 110       rotateZ(phi);
 111       break;
 112     case 'X':
 113       break;  
 114     default:
 115       System.err.println("character " + ch + " not in grammar");
 116     }
 117   }
 118 }
 119 
 120 void display() {
 121   background(loadImage(dataPath("hilbert.png")));
 122 }
 123 

1 comment:

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2