FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Simulation, Artificial Life
(Moderator: REAS)
   3D roessler problem
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: 3D roessler problem  (Read 447 times)
beachmeat

WWW
3D roessler problem
« on: Oct 1st, 2003, 6:39am »

Hi everyone.
 
Im trying to make a roessler attractor in p5...and I am having a hard time to get it to work.
 
My Problem is, that after I translate the coordinates and draw a spheres in a void loop(), but each and every sphere is simply mapped over each other, so they dont remain in their 3D position but are treated as pixels.
As im new to p5 I hope you can help me.
 
 
Heres the code
 
Code:

 
void setup()
{
  colorMode(RGB);
  framerate(80);
  size(800,800);
  background(0);
  lights();
  noStroke();
  smooth();
  fill(204, 102, 0);
}
 
//roesller parameters
float h= 0.035;
float a= 0.32;
float b= 0.30;
float c = 5.1;
 
// start locations
float x0 = 0.1;
float y0 = 0.1;
float z0 = 0.1;
 
// values for translating
float x;
float y;
float z;
 
//radius
float rad = 5;
 
void loop()
{
    x0 = (x0 + h * (-y0 -z0));
    y0 = (y0 + h * (x0 + a * y0));
    z0 = (z0 + h * (b + z0 * (x0 - c)));
 
    x = x0 * rad + 400;
    y = y0 * rad + 400;
    z = z0 * rad + 400;
 
    translate(x,y,z);
    sphere(2);
}

 
JohnG

WWW
Re: 3D roessler problem
« Reply #1 on: Oct 1st, 2003, 8:47am »

I'm not 100% sure of what you're getting at, butI assume you don't want the "smearing" effect of the current version.
 
If I'm right, the problem is that sphere() doesn't create a new sphere to be drawn every loop, it just draws a sphere, and the ones drawn from the last time around loop() just haven't been cleared.
 
To get each sphere drawn each frame, you'll need to create an array of their locations (x,y,z) and draw each sphere each frame (with a background() call to clear the screen between)
 
However, I think you're going to have a HUGE number of spheres after a very short time, and it will probably get very very slow very quickly, tring to draw a few thousand sphere/frame.
 
beachmeat

WWW
Re: 3D roessler problem
« Reply #2 on: Oct 1st, 2003, 2:34pm »

Well thats right.
 
So pretty much Im asking is:
How do I draw many 3D Shapes, that remain 3D positioned, so that I even could use a camera.
Does P5 offer that possibility?
I coudnt find such information in the reference, neither did I manage to draw multiple translated spheres in a while loop, I think im getting it a liitle mixed up.
 
Could you help me out with a little code, that I could see how to possibly draw the roesller at once?
 
[And sorry for my bad english, its not my native language]
 
Thanks in advance
manuel
 
JohnG

WWW
Re: 3D roessler problem
« Reply #3 on: Oct 1st, 2003, 3:40pm »

Here's a quick attempt at adding the functionality you'd need. I've only been using proce55ing for a week or so now, so I've probably missed something, but it should give you enough to build upon to get to where you want.
 
Code:

ball[] balls;
int numballs=0;
 
void setup()
{
  balls=new ball[200]; // or however many balls.
 
  // Insert other setup stuff here...
 
}
 
void loop()
{
  // Insert maths here...
  background(color(0,0,0));
  ball temp=new ball(x,y,z);
  balls[numballs]=temp;
  numballs++;
 
  for(int i=0;i<numballs;i++)
  {
    balls[i].draw();
  }
}
 
 
class ball
{
  float x,y,z;
  ball(float _x,float _y,float_z)
  {
// store the ball's X Y and Z position.
    x=_x;
    y=_y;
    z=_z;
  }
   
  void draw()
  {
    push(); // think you need this to ensure each ball  
// is in it's own place not affected by the others
 
// draw this ball.
    translate(x,y,z);
    sphere(2);
 
    pop(); // so that we go back to not having this  
// ball's translation
  }
}
 
« Last Edit: Oct 1st, 2003, 3:42pm by JohnG »  
beachmeat

WWW
Re: 3D roessler problem
« Reply #4 on: Oct 3rd, 2003, 2:29am »

Thanks for your help again, I understand push n pop now
 
Pages: 1 

« Previous topic | Next topic »