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

Saturday, 13 October 2012

More Experiments with my Joons-Fork

Here I test the pushMatrix and popMatrix fuctionality albeit with only one level (my revised libary should support nested Matrices unlike the original). Further some unecessary cruft is now hidden in the library (ie rendered, boolean followed by code to display the rendered image).
   1 /**
   2  * Rotate Push Pop. 
   3  * 
   4  * The push() and pop() functions allow for more control over transformations.
   5  * The push function saves the current coordinate system to the stack 
   6  * and pop() restores the prior coordinate system. 
   7  */
   8 
   9 import joons.JoonsRenderer;
  10 
  11 
  12 JoonsRenderer jr;
  13 
  14 float eyeX = 0;
  15 float eyeY = 115;
  16 float eyeZ = 40;
  17 float centerX = 0;
  18 float centerY = 0;
  19 float centerZ = 40;
  20 float upX = 0;
  21 float upY = 0;
  22 float upZ = -1;
  23 float fov = PI / 4; 
  24 float aspect = 1.0;  
  25 float zNear = 5;
  26 float zFar = 10000;
  27 float a;                          // Angle of rotation
  28 float offset = PI/24.0;             // Angle offset between boxes
  29 int num = 12;                     // Number of boxes
  30 color[] colors = new color[num];  // Colors of each box
  31 color safecolor;
  32 
  33 boolean pink = true;
  34 
  35 void setup() 
  36 { 
  37   size(600, 600, P3D);
  38   jr = new JoonsRenderer(this, width, height);
  39   jr.setRenderSpeed(1);  
  40   noStroke();  
  41   for (int i=0; i<num; i++) {
  42     colors[i] = color(255 * (i+1)/num);
  43   }  
  44 } 
  45 
  46 
  47 void draw() 
  48 { 
  49   if (jr.displaySketch()) {  
  50     background(200);
  51     lights();
  52     beginRecord("joons.OBJWriter", "");// just call like this. Leave the second parameter as "".
  53     perspective(fov, aspect, zNear, zFar);// use perspective() before camera()!!
  54     camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  55     a += 0.01;   
  56     translate(0, 0, 25);  // Z is up in sunflow
  57     for (int i = 0; i < num; i++) {
  58       pushMatrix();
  59       fill(colors[i]);
  60       rotateY(a + offset*i);
  61       rotateX(a/2 + offset*i);
  62       box(50);
  63       popMatrix();
  64     }
  65     endRecord();
  66   }
  67 }
  68 
  69 void keyPressed() {
  70   if (key == 'r' || key == 'R' && jr.displaySketch()) {
  71     saveFrame("capture.png");
  72     jr.setShader("object0", "Blue");  // shape is recognized as one object 
  73     jr.setSC(dataPath("ambient.sc"));
  74     jr.render("bucket");
  75   }
  76 }
Sunflow rendered
Sketch capture

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