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, 16 May 2012

Exporting A Generative Design Sketch in Processing 2.0 to povray

Previously, I had demonstrated the export to povray of a processing generativedesign sketch to povray using my povwriter library designed to work with processing-1.5.1 here. This is my first exploration with my povwriter2 library (requires processing version 2.0a6 or greater). Here is the sketch code see previous post to see what a running sketch looks like.
   1 import povexport2.*;
   2 import povexport2.gui.*;
   3 import povexport2.povwriter.*;
   4 
   5 /**
   6  * part of the example files of the generativedesign library.
   7  *
   8  * shows how to use the Mesh class.
   9  */
  10 
  11 
  12 // imports
  13 import generativedesign.*;
  14 
  15 PovExporter export; 
  16 
  17 void setup() {
  18   size(800, 800, P3D);
  19   export = new PovExporter(this);
  20   export.chooseTemplate();
  21   export.setPovrayPath("/usr/local/bin/povray"); //use this once to set povray path
  22   // Quality PREVIEW, MEDIUM, HIGH, HIGHEST, GRAYSCALE
  23   export.createIniFile(dataPath("screw.ini"), Quality.HIGH);
  24   export.addDeclareOption("ScaleP5", "0.5"); 
  25   export.addDeclareOption("TransYP5", "60"); // custom declare,translates Y axis in PovRAY
  26   export.addDeclareOption("TransP5", "-40"); // custom declare,translates X axis in PovRAY
  27 }
  28 
  29 void draw(){
  30   if (export.traced()) { // display traced image
  31     display();
  32   }
  33   else{
  34   // setup lights
  35   background(255);
  36     noStroke();
  37   fill(0);
  38   lightSpecular(230, 230, 230); 
  39   directionalLight(200, 200, 200, 0.5, 0.5, -1); 
  40   specular(color(220)); 
  41   shininess(5.0); 
  42   export.beginRaw(dataPath("screw.pov")); 
  43   // setup view
  44   translate(width*0.5, height*0.5);
  45   rotateX(-0.2); 
  46   rotateY(-0.5); 
  47   scale(100);
  48   // setup Mesh, set colors and draw  
  49   Mesh myMesh = new Mesh(this, Mesh.STEINBACHSCREW, 200, 200, -3.0, 3.0, -PI, PI);
  50   myMesh.setColorRange(200, 200, 50, 50, 40, 40, 100);
  51   myMesh.draw();
  52 
  53   export.endRaw();  //end tracing
  54   }
  55 }
  56 
  57 /**
  58  * Display ray traced image in sketch window
  59  */
  60 void display() {
  61   background(loadImage(dataPath("screw.png")));
  62 }
  63 
  64 

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