We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
p5sunflow iteration (Read 402 times)
p5sunflow iteration
Jul 8th, 2008, 3:07am
 
well, I'm trying to render the code of a tree i've found. No problem with p3d, but when switch to sunflow it just renders the first code iteration, so instead of getting a tree, I get a lonely cylinder for each frame.
the same was happening with pdf export, and I solve it with beginRaw, I'd like to do so now, but I don't know if beginRecord can be used with sunflow.
any idea?

import hipstersinc.sunflow.*;
import hipstersinc.sunflow.shader.*;
import hipstersinc.*;

// samuel bravo silva, santiago, chile. 2008. terreno.wordpress.com
// this code is the addition of superkrut's "processing tree" (http://blog.superkrut.se/?p=5) and
// "Vertices" by Simon Greenwold on processing.org/learning/3d/vertices.html
String movName = "img/tallo"; //where to render images
boolean useSunflow = true; //set to false for fast OPENGL render
float numFrames = 800;//length of animation
int nr=0;
BodyPart root;

float rootAngleX=1500;
float rootAngleY=0;
float px, py;

void setup() {
 if (useSunflow){
 size(720, 480, "hipstersinc.P5Sunflow");
 }
 else{
   size(200,200,P3D);
 }
 root = new BodyPart(0, 0);
}
void guarda(){
 if (frameCount <= numFrames) {
    saveFrame(movName + "-####.png");

 }
   else{
   exit();
 }
}
void draw() {
//background(245);  

 translate(width/2, height, -30);
 rotateX(rootAngleX/1000);
 rotateZ(rootAngleY/1000);
 root.grow();
 root._angPosX = 0;
setupCamera();

}
 
// Tweak our camera parameters.  Make sure to call this from `draw`
void setupCamera() {
 // Get the P5Sunflow PGraphics
 P5Sunflow sunflow = (P5Sunflow) g;
 // Set our camera to "pinhole"
 sunflow.camera.setType(SunflowCamera.PINHOLE);
}
class BodyPart {

 BodyPart[] children = new BodyPart[3];
 private int child_nr=0;
 private float _width = 0;
 private float _height = 0;
 private float _widthspeed;
 private float _heightspeed;
 private float _angleX;
 private float _angleY;
 public float _angPosX;
 private float newangle;
 private float nextchild;
 public BodyPart(float angleX, float angleY){
   _angleX = angleX;
   _angleY = angleY;
   _angPosX = 0;
   _widthspeed=.04;
   _heightspeed=3;//.8
   nextchild = 2;
 }
 public void grow(){
   _height+=_heightspeed;
   _width+=_widthspeed;
   //if(child_nr<3 && random(0,_width*10)/((child_nr+1)*(child_nr+1))>15){
   if(_width>nextchild && child_nr<3){      //crecen o no crecen ramas
     nextchild+=child_nr+random(2,6);
     _heightspeed*=.1*_width; // esto nos da una caida no lineal en la punta
     newangle =random(.3,.75);
     children[child_nr++] = new BodyPart(random(-newangle,newangle), random(-newangle,newangle));
   }  
   
 paint();
   for(int i = 0;i<child_nr;i++){
     pushMatrix();
     children[i].grow();  
     popMatrix();
   }
 }
 void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {

   float angle = 0;
   float angleIncrement = TWO_PI / sides;
   noStroke ();
   beginShape(QUAD_STRIP);
   for (int i = 0; i < sides + 1; ++i) {
     vertex(topRadius*cos(angle), 0, topRadius*sin(angle));
     vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle));
     angle += angleIncrement;
   }
   endShape();
   rotateX(-PI/2);
 }
 public void paint(){

   rotateX(_angleX+sin(_angPosX+=.1/_width)/10+PI/2);
   rotateY(_angleY+sin(_angPosX+=.1/_width)/10);
   fill(100,200,_width/.6,70);
   drawCylinder(_width/2+1.4/(_height/2.4+.6), _width/2, _height/1.9, 5+round(_width/3));//lo último hace que las figuras nazcan de 3 caras y cada 5 px de diametro incrementen una.
   translate(0,0,_height/2);
 guarda();
 }
}
Page Index Toggle Pages: 1