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

Monday, 11 April 2011

Povwriter Library Now Revised to version 0.54

Library bundle now includes javadocs (somewhat crudely annotated for the most part) and I am offering template files in a separate zip file.  For those that don't know where to place the 'orginal.pov' template, the first time the library is run (or whenever the {HOME}/original.pov file is missing) a dummy output is produced, that includes the path for you system as determined by the absolute path function.
Here is a example of 3D processing sketch just using stroke (noFill(), the processing rendering looks crap). Beefing up the PovRAY line width (to 20 in this case), the image is then rendered as a collection of PovRAY primitives ie cylinders. I would like to implement spheres primitives (StructureSynth does this), but that is a very long way off, if it ever happens.
NB: in the below output I used the PovRAY "Chrome_Metal" texture and "Silver" color for the cylinders (a post edit of the "output.pov"), thanks to Guillaume LaBelle superCAD library for idea to use cylinders for line.

import lsystem.turtle.*;
import lsystem.collection.*;
import lsystem.*;
import povexport.*;
import povexport.povwriter.*;

boolean record = false;
Grammar grammar;
float distance = 30;
int depth = 4;
float THETA = radians(90);
float PHI = radians(90);
float theta = 0;
float phi = 0;
String production = "";

void setup() {
  size(640, 512, P3D);
  setupGrammar();
}

void draw() 
{
  translate(width * 0.6, height * 0.6, -width/3);
  background(0, 0, 26);
  strokeWeight(8);
  stroke(0,  75,  152);
  if(record) {
    noLoop();
    beginRaw(RawPovray.POV, dataPath("output.pov"));
  } 

  render();

  if (record) {
    endRaw();
    record = false;
  }
} 

void keyPressed() {

   switch(key) {
  case 'r':    
    record = true;
    break;
  case 'e': 
    String[] args = {"/home/tux/bin/jedit", dataPath("output.pov")};
    try{    // open(args); just should work on processing but didn't for me
      java.lang.Runtime runtime = java.lang.Runtime.getRuntime();
      runtime.exec(args);      
    }
    catch(IOException e){e.printStackTrace();}
    break;
  }
}

void setupGrammar() {
  grammar = new SimpleGrammar(this,  "X");   
  grammar.addRule('X',  "^<XF^<XFX-F^>>XFX&F+>>XFX-F>X->");
  production = grammar.createGrammar(depth);
}

void render() {  
  CharacterIterator it = grammar.getIterator(production);
  beginShape();
  for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
    switch (ch) {
    case 'F': 
      translate(distance/-2,  0, 0);
      line(-distance/2, 0, 0,  distance/2,  0, 0);
      translate(distance/-2,  0, 0);
      break;
    case '-':
      rotateY(-THETA); // juggle round Y and X to compensate for processing
      break;
    case '+':
      rotateY(THETA);  // oddball coordinate system  
      break;
    case '>':
      rotateX(THETA);
      break;
    case '<':
      rotateX(-THETA);
      break;
    case '&':
      rotateZ(-PHI);
      break;
    case '^':
      rotateZ(PHI);
      break;
    case 'X':
      break;  
    default:
      System.err.println("character " + ch + " not in grammar");
    }
  }
  endShape();
}


A Chrome Hilbert, using povwriter and LSystem processing libraries.

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