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

Tuesday, 13 March 2012

Exporting generativedesign library sketch to PovRAY

Until I figure out how to do it better, here I use my povwriter version 0.80 library to export a processing sketch using the generativedesign library (http://www.generative-gestaltung.de) to PovRAY. This example is included with the generative design library, however I found I needed to define a constructor with a PApplet argument to get the sketch to run.....
Updated 19 May 2012, revised sketch to work with my latest version of my povwriter library (for processing-1.5.1)
   1 /**
   2  * Part of the example files of the generativedesign library.
   3  * Modified to actually work and to use my povwriter library version 0.80
   4  */
   5 
   6 // imports
   7 import povexport.*;
   8 import povexport.povwriter.*;
   9 import generativedesign.*;
  10 import processing.opengl.*;
  11 
  12 PovExporter exporter;
  13 // mesh
  14 MyOwnMesh myMesh;
  15 
  16 
  17 void setup() {
  18   size(1000, 1000, OPENGL);
  19 
  20   // setup drawing style 
  21   hint(ENABLE_OPENGL_4X_SMOOTH);
  22   colorMode(HSB, 360, 100, 100, 100);
  23   noStroke();
  24 
  25   // initialize mesh. class MyOwnMesh is defined below
  26   myMesh = new MyOwnMesh(this);
  27   exporter = new PovExporter(this);
  28   /** 
  29   * MEDIUM (povray quality 6) is good for preview best to run povray offline 
  30   * for higher quality (povray quality 9 -> 12) for such a sketch
  31   */
  32   exporter.createIniFile(dataPath("meshC.ini"), Quality.MEDIUM);
  33   myMesh.setUCount(100);
  34   myMesh.setVCount(100);
  35   myMesh.setColorRange(193, 193, 30, 30, 85, 85, 100);
  36 }
  37 
  38 
  39 void draw() {
  40   if (exporter.traced()) {
  41     display();
  42   } 
  43   else {
  44     background(255);
  45     // setup lights
  46     colorMode(RGB, 255, 255, 255, 100);
  47     lightSpecular(255, 255, 255); 
  48     directionalLight(255, 255, 255, 1, 1, -1); 
  49     shininess(5.0); 
  50     exporter.beginRaw(dataPath("meshC.pov")); // begin record
  51     render();
  52     exporter.endRaw();                        //end record
  53   }
  54 }
  55 
  56 // define your own class that extends the Mesh class 
  57 class MyOwnMesh extends Mesh {
  58   public MyOwnMesh(PApplet ap) {
  59     super(ap);
  60   }
  61   // just override this function and put your own formulas inside
  62   PVector calculatePoints(float u, float v) {
  63     float A = 2/3.0;
  64     float B = sqrt(2);
  65 
  66     float x = A * (cos(u) * cos(2*v) + B * sin(u) * cos(v)) * cos(u) / (B - sin(2*u) * sin(3*v));
  67     float y = A * (cos(u) * sin(2*v) - B * sin(u) * sin(v)) * cos(u) / (B - sin(2*u) * sin(3*v));
  68     float z = B * cos(u) * cos(u) / (B - sin(2*u) * sin(3*v)); 
  69 
  70     return new PVector(x, y, z);
  71   }
  72 }
  73 
  74 void render() {
  75   // setup view
  76   translate(width*0.5, height*0.5);
  77   scale(180);
  78   rotateX(radians(10)); 
  79   rotateY(radians(-10)); 
  80   // recalculate points and draw mesh
  81   myMesh.setParam(1, float(mouseX)/width);
  82   myMesh.update();
  83   myMesh.draw();
  84 }
  85 
  86 void display() {
  87   PImage img = loadImage(dataPath("meshC.png"));
  88   background(img);
  89 }

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