We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I am new to programming and this is my first result after some hours with processing, using some tutorials. My target was to creat a random fluent movment in x-direction. I think I succeded. Can't believe how easy processing is for beginners! I completely failed with actions script flash for example.
If you run the script, it should get quite obviuos what I did. The upper elements are influencing the elements under them.
So my questen is: How could I create 50 of these "legs" automatically?
float pos_x=100;
float pos_x_2=100;
float pos_x_3=100;
float pos_x_4=100;
int last=0;
float x;
float x_2;
float x_3;
float x_4;
float targetX=0;
float targetX_2=0;
float targetX_3=0;
float targetX_4=0;
//closing in speed
float easing=0.03;
float easing2=0.1;
void setup()
{
size(1000,1000);
background(#FFFFFF);
rectMode(CENTER);
frameRate(25);
}
void draw()
{
noStroke();
background(#ffffff); //HG weiß
fill(#000000,255); //black
rect(pos_x,400,50,50); //place black rectangle
fill(#E38D02); //orange
rect(pos_x_2,400,50,50); //place orange rectangle
float targetX = pos_x;
x += (targetX - x) * easing; //////value for moving towards black rectangle for circle 1
fill(#EA3424,255); //rot
ellipse(x, 500, 12, 12); //// placing circle 1 - is chasing black rectangle
float targetX_2 = pos_x_2;
x_2 += (targetX_2 - x_2) * easing; ///value for moving towards orange rectangle for circle 2
ellipse(x_2, 500, 12, 12); //// placing circle 2 - is chasing orange rectangle
pos_x_3=x; //"chasing points" for green rectangles
pos_x_4=x_2;
float targetX_3 = pos_x_3;
x_3 += (targetX_3 - x_3) * easing2; ///Closing in towars red circles
fill(#02E31A);
rectMode(CENTER);
rect(x_3,600,20,20); //green cetangle1
float targetX_4 = pos_x_4;
x_4 += (targetX_4 - x_4) * easing2; ///Closing in towars red circles
rect(x_4,600,20,20); //green cetangle2
//connecting lines
strokeWeight(5);
stroke(#02E31A);
line(pos_x,400,x, 500);
line(pos_x_2,400,x_2, 500);
line(x_3,600,x, 500);
line(x_4,600,x_2, 500);
//end connecting lines
//the initial rectangles-replacing them one time a second
if(millis() > last+1000) // once a second
{
last = millis(); //
pos_x=int(random(1000));
pos_x_2=int(random(1000));
}
}
Answers
well, in the end, I will only use the coordinates of the green squares, to control other objects and make everything else invisible. just inserted the lines to illustrate better what I did - because the script could be a little bit messed up.
oh "rot" is actually "red". "rot" is german for red, has nothing to do with rotation.
I believe these articles' gonna lead you smoothly to what you wanna do: :ar!
http://wiki.processing.org/w/From_several_variables_to_arrays
http://wiki.processing.org/w/From_several_arrays_to_classes
An online example using Array for many copies:
http://studio.processingtogether.com/sp/pad/export/ro.9ZKbYJpM0CfPR/latest
And 1 using classes:
http://studio.processingtogether.com/sp/pad/export/ro.9FqnMDLUZqQCV/latest
Looks exactly like what I am looking for!!! Thank you very much! (*) independent moving balloons.