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, 21 December 2011

Example Processing Sketch PovRAY rendered

Here is one the example sketches included with my povwriter library, rendered with a quality setting of 2, which is the lowest setting which gives you any idea how the sketch might actually look when PovRAY rendered. However if you only need to see where objects get rendered a setting of 1 (or even 0) can be used. In practice a setting of two will render so quickly you will not need a lower setting. The flat_scene.pov template was used here, so no background shadows, except on the sketch objects (and the only visible with higher quality setting 11).

   1  import povexport.*;
   2 import povexport.povwriter.*;
   3 
   4 /**
   5  * This sketch is adapted from the DXF export processing library example
   6  */
   7 Process povray;
   8 boolean record = false;
   9 PovExporter export;
  10 int[] DATA = {
  11   -1, 0, 1
  12 };
  13 
  14 void setup() {
  15   size(400, 400, P3D);
  16   export = new PovExporter(this);
  17   export.chooseTemplate(); // launch custom template file chooser
  18   export.setPovrayPath("/usr/local/bin/povray"); // set once only
  19   export.storeSettings(); // NB: call storeSettings() after changes
  20   // Quality 1 ...7... 11 (low ... medium ... high)
  21   export.createIniFile(dataPath("balls.ini"), 2); 
  22   export.writeIniFile();
  23   noStroke();
  24 }
  25 
  26 void draw()
  27 { 
  28   lights();        // this needs to be outside the record loop
  29   if (record) {    
  30     noLights();    // let PovRAY do the lighting
  31     noLoop();      // don't loop while recording sketch
  32     beginRaw(PovExporter.POV, dataPath("balls.pov"));
  33   }
  34   try {  
  35     if (povray != null && povray.waitFor() == 0) {      
  36       display();
  37     }
  38     else
  39       render();
  40   }
  41   catch(InterruptedException e) {
  42     e.printStackTrace();
  43   }
  44   if (record) {
  45     endRaw();
  46     record = false;
  47     loop();
  48   }
  49 }
  50 
  51 
  52 void display() {
  53   PImage img = loadImage(dataPath("balls.png"), "png");
  54   background(img);
  55 }
  56 
  57 void render() {  
  58   background(0);
  59   translate(width*0.5, height*0.7, width/20);
  60   for (int y : DATA) {
  61     for (int x : DATA) {
  62       for (int z : DATA) {
  63         pushMatrix();
  64         translate(120*x, 120*y, 120*z);
  65         fill(random(255), random(255), random(255)); // a nice test for my colorFactory class
  66         export.sphere(30);
  67         popMatrix();
  68       }
  69     }
  70   }
  71 }
  72 
  73 void keyPressed() {
  74   switch(key) {
  75   case 'r':  // create balls.pov file 
  76   case 'R':  
  77     record = true;
  78        
  79     break;
  80   case 't':  // run PovRAY calling balls.ini
  81   case 'T':  
  82     povray = export.rayTrace(); 
  83     break;
  84   case 'e':
  85   case 'E':
  86     if (this.record == false) {
  87       String[] args = {
  88         export.getJEditPath(), dataPath("sphere.pov")
  89       };
  90       exec(args); // open sphere.pov with jEdit
  91     }
  92     break;
  93   }
  94 }
  95 



Quality 1Quality 11

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