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, 22 December 2010

Ben Tilbert rendered in povray from processing

The coloring of the povray rendered image bears no resemblance to the original processing sketch, though theoretically possible, I'm not sure there is any real advantage. The relationship between the processing sketch and the ray traced image vary in other ways. Just like the three processing/sunflow interface, the camera position bears from processing bears little resemblance to the pov file settings. StructureSynth in contrast actually manages a pretty good job with its sunflow template, but not the povray template.

import supercad.povwriter.*; // Latest edition of my customised supercad library
import supercad.*;

import lsystem.*;      // contributed libraries
import peasy.*;        //

float HALF = PI/360;   // introduce half a degree error
String axiom = "A";
String production;
float THETA = HALF_PI + HALF;
float PHI = HALF_PI - HALF;
PeasyCam cam;
Grammar grammar;
String cadSoftware, ext;
boolean record = false;

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^");
  production = grammar.createGrammar(3);
}

void draw()
{  
  if(record) {
    noLoop();
    beginRaw("supercad."+cadSoftware, "output."+ext);
  }
  render();
  if (record) {
    endRaw();
    record = false;
    loop();
  }
}

void render() {
  int repeats = 1;
  int col = color(0, 225, 0);
  lights();
  directionalLight(128, 128, 128, 0, 0, 1);
  background(0);
  CharacterIterator it = grammar.getIterator(production);
  for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
    switch (ch) {
    case 'F':
      fill(col);
      float len = 30;
      translate(0, 0, -len / 2);
      box(5, 5, len - 1.6);     
      translate(0, 0, -len / 2);
      box(5, 5, 5);
      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");
    }
  }
}

void keyPressed() {

  switch(key) {
  case 'r': 
    cadSoftware = "Rhino"; 
    ext = "rvb"; 
    break;
  case 's': 
    cadSoftware = "SketchUP"; 
    ext = "rb";
    break;
  case 'a': 
    cadSoftware = "AutoLISP"; 
    ext = "lsp";
    break;
  case 'p': 
    cadSoftware = "PovRAY"; 
    ext = "pov";
    break;
  case 'm': 
    cadSoftware = "Maya"; 
    ext = "mel";
    break; 
  case 'o': 
    cadSoftware = "ObjFile"; 
    ext = "obj";
    break;       
  case 'c': 
    cadSoftware = "ArchiCAD"; 
    ext = "gdl";
    break;
  }  
  record = true;  
}

No comments:

Post a 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