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)
   Phyllotaxis
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Phyllotaxis  (Read 436 times)
Fractal_Mike
Guest
Email
Phyllotaxis
« on: Oct 3rd, 2003, 4:05pm »

edit: adding URL: http://stud3.tuwien.ac.at/~e0225885/programmieren2.html
 
 
This is a simple simulation of a (sun)flower head, where you should be able to change the value "del" (which denotes the difference from the Fibonacci-angle) with moving the mouse.
 
Unfortunately the only values I get are 0.0 and -1.0 (on the left border), and I have no clue why.
del should go smoothly from -1 to 1 if you move the mouse from left to right, as is mouseX, but it doesn't.  
 
Please help; thank you!
 
 
Code:

void setup(){
  size(300,300);
  background(#FFFFD2);
  ellipseMode(CENTER_DIAMETER);  
  smooth();  
  }
  
float del=0;
  
void loop(){
  framerate(8);
  background(#FFFFD2);
  float ang=0;
  fill(#8B6914);
  for (int n=8; n<500; n=n+1){
    ellipse(int(150+sin(ang)*0.28*n),
            int(150+cos(ang)*0.28*n),5,5);
    ang+=radians(137.507764+del);
  }
  print("del:"+del);  //for testing
  println("   mouseX:"+mouseX);  //for testing
}
 
void mouseMoved(){
  del=(mouseX-150)/150;
}
« Last Edit: Nov 8th, 2003, 10:52am by Fractal_Mike »  
JohnG

WWW
Re: Phyllotaxis
« Reply #1 on: Oct 3rd, 2003, 5:17pm »

You need to cast mouseX to a float before doing the division, or it'll do an integer division which can only have the vaules -1, 0 or 1...
 
so you want:
 
Code:

del=(int)(((float)(mouseX-150))/150.0);

 
I think.
 
It might be better to change 150 to (width/2) in case you ever want to have a different sized verson.
 
Fractal_Mike
Guest
Email
Re: Phyllotaxis
« Reply #2 on: Oct 4th, 2003, 3:05pm »

Thanks much!
I just changed it to
Code:

   del=((float)(mouseX-width/2))/(width/2);

That was enough, since del should be a float.
 
Pages: 1 

« Previous topic | Next topic »