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.
IndexProgramming Questions & HelpPrograms › Confusing Variables - motion
Page Index Toggle Pages: 1
Confusing Variables - motion (Read 565 times)
Confusing Variables - motion
Mar 17th, 2010, 8:31am
 
I am pretty new to processing and this problem is driving me crazy.

What I want is to have 5 circles moving from the top of the screen to the bottom at different places. When you move over one of the circles it changes into some text at the bottom. Each circle corresponds to a different word in a sentence. I figured out that part using a boolean , but the problem is how to make 5 moving circles without rewriting so much code.
I set up the function (circle) to control the different variables. And it looks like it works when I run it, but the circleX1, and circleY1 stay at 0,0! (just in spirit. It moves normally)
So the boolean only turns true when it's on 0, 0, rather than on the moving circle.

Am I making any sense?

Here is the code showing how I set up the variables
(without the boolean because then there's a ton of other code I would need to add)

How can I fix this?

float beginx ;
float beginy;
float endx;
float endy;
float distx;
float disty;
float step;
float pct =0.0;

float circleX1 = 0;
float circleY1 =0;
float circleRadius1 =30;


float circleX2 =0;
float circleY2 =0;
float circleRadius2 =20;



void setup(){
 size(480, 320);
 smooth();
 noStroke();
}

void draw(){
 background(0);

 circle(circleX1,circleY1,circleRadius1,0,0,100,100,0.0004);
 circle(circleX2,circleY2,circleRadius2,0,0,200,100,0.002);
 
}

void circle(float x,float y,float r, float bx,float by, float ex,float ey,float s){



beginx =bx;
beginy =by;
endx = ex;
endy =ey;
step = s;


distx =endx-beginx;
disty = endy-beginy;

 pct+=step;
 if (pct <1.0){
   x = beginx +(pct*distx);
   y = beginy +(pct*disty);
 }

 if (pct>=1){
   pct=0;
 }
 
 ellipse(x,y,r,r); ////////I think this is where the issue is....but I don't know why
 }
Re: Confusing Variables - motion
Reply #1 - Mar 17th, 2010, 12:07pm
 
you can do that with less code using these animation libraries: motionlib, ani, shapetween. if you want to use penners easing equations then either motionlib or ani is best. you can find motionlib at ekeneijeoma.com/processing/motionlib/ or http://processing.org/discourse/yabb2/num_1261940382.html and ani at http://processing.org/discourse/yabb2/num_1268569670.html
Re: Confusing Variables - motion
Reply #2 - Mar 18th, 2010, 5:22am
 
I am not quite sure I understood your question.
Your sketch shows two spheres "sliding down" but you want to "click" on them, right?
And what you are saying is, that you can only "click" on them "top left" and not on their moved position, right?

Your code doesn't show this check, but I'd guess you are checking against the variables circleX1/circleY1 for the first circle with the mouseX/mouseY coordinates? If so, that would be the mistake, because your function never changes these variables, it only derives different "drawing" coordinates from them.

If you want to create a lot of "similar" objects (spheres) without re-copying tons of codes (which one never does), you really want to learn object-oriented-programming where you define "objects" (which have both properties=variables and actions=functions) and then can create as many of those as you wish.
I'd guess, you shoul check out the according tutorial (top of this homepage Learning-Link then "objects" by Daniel Shiffman)
Page Index Toggle Pages: 1