We are about to switch to a new forum software. Until then we have removed the registration on this forum.
int np=20; // numero pendoli - number of pendula
int cc; // contatore - counter
int [] l = new int[np]; // lunghezze filo - thread's lenght
float xF=500, yF=20; // coordinate del punto "fisso" - fixed point coordinates
float r=50; // raggio della sfera - radius of the sphere
float alfa=0.2467; // angolo iniziale in radianti - starting angle in radiants
int [] k = new int[np]; // numero delle suddivisioni - number of divisions
float beta; // angolo variabile - variable angle
float xP,yP; // centro del pendolo - center of the shere
float step;
int [] h = new int[np]; // contatore - counter
int [] s = new int[np]; // contatore - counter
int [] w = new int[np]; // contatore - counter
int [] cl = new int[np]; // colori - colors
float temp;
void setup(){
size(1000,700);
background(255);
for (cc=0;cc<np;cc++) {l[cc]=250+cc*int(r/5);h[cc]=-1;s[cc]=1;w[cc]=-1;cl[cc]=7*cc+40;}
frameRate(200);
}
void draw () {
background(255);
for (cc=0;cc<np;cc++){
k[cc]=int(5.7*sqrt(l[cc]));
step=2*alfa/k[cc];
w[cc]=w[cc]+1; if (w[cc]>k[cc]){w[cc]=1; s[cc]=-1*s[cc];}
h[cc]=h[cc]+s[cc];
temp=alfa-h[cc]*step;
if (temp>=0)
{beta=temp; xP=xF-l[cc]*sin(beta); yP=yF+l[cc]*cos(beta);}
else
{beta=-1*temp; xP=xF+l[cc]*sin(beta); yP=yF+l[cc]*cos(beta);}
line (xF,yF,xP,yP);
fill (cl[cc]);
ellipse (xP,yP,r,r);
}
}
Comments
I try to simulate the experiment shown in It's an attempt, I know the code needs to be improved. Any suggestion? This is my second sketch, so ... be patient.
Pendula
great!
Hey! I've made a remixed version using class in place of multiple arrays. Read about it below:
http://wiki.processing.org/w/From_several_arrays_to_classes
You can view it in action online below:
http://studio.processingtogether.com/sp/pad/export/ro.9yPdCEFDrKsJH/latest
And here's the refactored code itself:
Thank a lot GoToLoop, I'll study your code. I have a lot to learn.