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 & HelpSyntax Questions › return value for position
Page Index Toggle Pages: 1
return value for position (Read 925 times)
return value for position
Nov 9th, 2009, 10:39am
 
hi,
i am new in processing (and i am sorry for my rather bad english)
i am going to create an artificial self developing infratructure. for this i am searching for an "return value" wich returns the position of an point.

thanking you in anticipation
Re: return value for position
Reply #1 - Nov 9th, 2009, 10:46am
 
could you be a bit more specific on what you want to do?
What kind of point are you talking about?

getting the coordinates of a point doesnt make sense as you need to calculate or define the position first anyway, you its already stored in a variable...  if you could make an example this would be helpful.

just in case. you are not talking about this. do you?
http://processing.org/reference/return.html
Re: return value for position
Reply #2 - Nov 9th, 2009, 11:01am
 
okay
i try to explain: there are three circles placed somewhere on my sketch.
each circle has a max. and a min. distance in relation to the two other circles. my aim is, when the first circle moves the other circle should follow the to the position of the first according to the distance mentioned before. an so on.
actually i am so far that the distance is calculated but the movment is randomly.
here is my code( i am a beginner)

color weiss = color(255, 255, 255, 80);
color hintergrund = color(95, 95, 95);
float circleX;
float circleY;
float circleG;
float circleH;
float circleN;
float circleM;
float circleRadius = 3;
float circleSize = circleRadius * 2;
float v = random(-5, 5);
float v1 = random(-5, 5);
float v2 = random(-5, 5);
float v3 = random(-5, 5);
float v4 = random(-5, 5);
float v5 = random(-5, 5);


void setup() {
 background(hintergrund);
 size(1024, 768);
 smooth();
 noFill();

 circleX = random(width);
 circleY = random(height);
 circleG = random(width);
 circleH = random(height);
 circleN = random(width);
 circleM = random(height);


}

void draw() {
background(hintergrund);
stroke(weiss);
 
  // kreise

 ellipse(circleX, circleY, circleSize, circleSize);

 ellipse(circleG, circleH, circleSize, circleSize);

 ellipse(circleN, circleM, circleSize, circleSize);

 // verbindung zwischen den kreisen

 stroke(weiss);
 line(circleG, circleH, circleN, circleM);


 stroke(weiss);
 line(circleG, circleH, circleX, circleY);


 stroke(weiss);
 line(circleN, circleM, circleX, circleY);


 circleX = circleX + v;
 circleY = circleY + v1;

 if(circleX >= width) {
   v = -v;
 }

 if(circleX <= 0) {
   v = -v;
 }

 if(circleY >= height) {
   v1 = -v1;
 }

 if(circleY <= 0) {
   v1 = -v1;
 }

 if(dist(circleX, circleY, circleG, circleH) >= 300) {
   v = -v;
 }

 if(dist(circleX, circleY, circleG, circleH) >= 300) {
   v1 = -v1;
 }

 if(dist(circleX, circleY, circleN, circleM) >= 400) {
   v = -v;
 }

 if(dist(circleX, circleY, circleN, circleM) >= 400) {
   v1 = -v1;
 }
 
  if(dist(circleX, circleY, circleG, circleH) <= 150) {
   v = -v;
 }

 if(dist(circleX, circleY, circleG, circleH) <= 150) {
   v1 = -v1;
 }

 if(dist(circleX, circleY, circleN, circleM) <= 110) {
   v = -v;
 }

 if(dist(circleX, circleY, circleN, circleM) <= 110) {
   v1 = -v1;
 }


 circleG = circleG + v2;
 circleH = circleH + v3;

 if(circleG >= width) {
   v2 = -v2;
 }

 if(circleG <= 0) {
   v2 = -v2;
 }
 if(circleH >= height) {
   v3 = -v3;
 }

 if(circleH <= 0) {
   v3 = -v3;
 }

 if(dist(circleG, circleH, circleX, circleY) >= 300) {
   v2 = -v2;
 }

 if(dist(circleG, circleH, circleX, circleY) >= 300) {
   v3 = -v3;
 }

 if(dist(circleG, circleH, circleN, circleM) >= 250) {
   v2 = -v2;
 }

 if(dist(circleG, circleH, circleN, circleM) >= 250) {
   v3 = -v3;
 }
 
   if(dist(circleX, circleY, circleG, circleH) <= 150) {
   v2 = -v2;
 }

 if(dist(circleX, circleY, circleG, circleH) <= 150) {
   v3 = -v3;
 }

 if(dist(circleX, circleY, circleN, circleM) <= 200) {
   v2 = -v2;
 }

 if(dist(circleX, circleY, circleN, circleM) <= 200) {
   v3 = -v3;
 }




 circleN = circleN + v4;
 circleM = circleM + v5;

 if(circleN >= width) {
   v4 = -v4;
 }

 if(circleN <= 0) {
   v4 = -v4;
 }
 if(circleM >= height) {
   v5 = -v5;
 }

 if(circleM <= 0) {
   v5 = -v5;
 }

 if(dist(circleN, circleM, circleG, circleH) >= 250) {
   v4 = -v4;
 }

 if(dist(circleN, circleM, circleG, circleH) >= 250) {
   v5 = -v5;
 }

 if(dist(circleN, circleM, circleX, circleY) >= 400) {
   v4 = -v4;
 }

 if(dist(circleN, circleM, circleX, circleY) >= 400) {
   v5 = -v5;
 }
 
   if(dist(circleX, circleY, circleG, circleH) <= 150) {
   v4 = -v4;
 }

 if(dist(circleX, circleY, circleG, circleH) <= 150) {
   v5 = -v5;
 }

 if(dist(circleX, circleY, circleN, circleM) <= 110) {
   v4 = -v4;
 }

 if(dist(circleX, circleY, circleN, circleM) <= 110) {
   v5 = -v5;
 }







}





Re: return value for position
Reply #3 - Nov 9th, 2009, 11:36am
 
please, somebody help me!
Re: return value for position
Reply #4 - Nov 9th, 2009, 12:04pm
 
should the rectangle always looks the same? just move and turn? i am still trying to understand
Re: return value for position
Reply #5 - Nov 9th, 2009, 12:17pm
 
no. the aim is that each point(small circles in this case) "wants" (like a necessity) to be next to two other points within the limits of of an minValue and an max Value. And this applys to the two other points. the result should be that if the "first" "point" moves the other two should recognize an move in the direction of the fist one. in my opinion the result is a circulation, except if there is a optimal position of all three points.

thanks for your help
Re: return value for position
Reply #6 - Nov 9th, 2009, 12:21pm
 
addition:
the start position of all three points is "random"
Re: return value for position
Reply #7 - Nov 9th, 2009, 12:34pm
 
TBH I'd change the approach somewhat.  Rather than all those conditions why not check if the distance between two circles is above the threshold and then use the extent of this difference to affect the circle's velocity.  It would probably help if you worked out the distance using the old-fashioned way instead of dist()...

Code:
int limit;
float dx = circleN - circleG;
flot dy = circleM - circleH;
float distance = sqrt(dx*dx + dy*dy);

if(distance > limit) {
 // For example you could then use the values of dx and dy to affect the circle's velocities...
}


You would probably also find it useful to look up some code on springing...  Actually although it's written for ActionScript I can recommend Keith Peters' book 'Actionscript Animation' and it just so happens the sample chapter is the one on springing Cheesy

Read that and you should get some ideas.  In your case you'd want to add a random amount to the velocities to get some kind of continuous motion...

Re: return value for position
Reply #8 - Nov 9th, 2009, 12:52pm
 
thank you
Re: return value for position
Reply #9 - Nov 9th, 2009, 1:22pm
 
Now as i know what you wanna do. Like blindfish suggested you can use springs and particles to do that.
I recommend traerphysic as it is easy to use and you dont have to care about most if the stuff it does. just create 3 particles, connect them, define the min length of the springs

http://www.cs.princeton.edu/~traer/physics/

Re: return value for position
Reply #10 - Nov 9th, 2009, 1:29pm
 
exactly, thats it...thank you very much
Page Index Toggle Pages: 1