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 › Storing locations
Pages: 1 2 
Storing locations (Read 2257 times)
Re: Storing locations
Reply #15 - Mar 26th, 2007, 4:43pm
 
If I am storing all 4 locations in an array is it possible to then compare them to see if any of the values are the same?

Thanks
Re: Storing locations
Reply #16 - Mar 26th, 2007, 9:38pm
 
use this type of array instead...
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1174932444

it's more flexible than the standard array, and won't give you the out of bounds issue.... Array.length is not supported in JAVA & Processing.
Re: Storing locations
Reply #17 - Mar 26th, 2007, 9:45pm
 
What are you talking about Array.length not supported?

Code:
int[] foo;
foo=new int[5];

println(foo.length);
foo=append(foo,3);
println(foo.length);
Re: Storing locations
Reply #18 - Mar 26th, 2007, 10:10pm
 
I thought I just took this code:

 for(int i=0;i<mX.length;i++)
{
 println("mX["+i+"]="+mX[i]);
}


And then do some comparing magic - confused! :S
Re: Storing locations
Reply #19 - Mar 26th, 2007, 10:59pm
 
So I need to create an array that stores the X and Y location and then say that if any other X or Y locations come with -5 or +5 of the pervious couple of X and Y locations it does something else. - if that makes sense?
Re: Storing locations
Reply #20 - Mar 27th, 2007, 3:08am
 
Quote:
What are you talking about Array.length not supported?

Code:
int[] foo;
foo=new int[5];

println(foo.length);
foo=append(foo,3);
println(foo.length);


sorry about that... I haven't used processing in a while. I guess they added new array handlers.

and katty_III...
here's an example of  What I think you're talking about.. I'm getting reacquainted with processing and I whipped this up...
I had to use ArrayList instead of Array.. I found a bug with casting issues in a regular array.

Code:

//ArrayList to store positions of points
ArrayList myPoint;

void setup() {
 size(200, 200);
 background(104);
  myPoint = new ArrayList();
 
 //create 5 random points on stage
 for(int i=0; i < 5; i++) {
   myPoint.add( new Point(random(200), random(200)) );
 }
}

void draw() {
 
}

void mousePressed() {
 //add point
  myPoint.add(new Point(mouseX, mouseY) );
  //check the distance of the new point to the other points
  boolean tooClose = false;
  for(int i=0; i < myPoint.size()-1; i++) {
    //get the point that just was added
    Point tempCurrent = (Point) myPoint.get(myPoint.size()-1);
    //get all the points
    Point tempPoint =(Point) myPoint.get(i);
    //check the distance between all the points to the one that was just added
    if( dist(tempCurrent.xpos, tempCurrent.ypos, tempPoint.xpos, tempPoint.ypos) <= 15) {
      tooClose = true;
    } else {
      tooClose = false;
    }
  }
 
 //signal if it's too close or not
 if(tooClose == false) {
   println("cool");
 } else {
   println("WHOA!... too close");
 }
   
}

class Point {
 float xpos, ypos;
 
 Point (float x, float y) {
   xpos = x;  
   ypos = y;
   fill(200);
   ellipseMode(CENTER);
   ellipse(x,y, 5,5);
 }
}

Re: Storing locations
Reply #21 - Mar 27th, 2007, 10:19am
 
Cheers - another quick question is how would I then say if any of these points are the same value then do something else...
Re: Storing locations
Reply #22 - Mar 27th, 2007, 3:30pm
 
Code:

if( dist(tempCurrent.xpos, tempCurrent.ypos, tempPoint.xpos, tempPoint.ypos) <= 15) {
tooClose = true;
} else {
tooClose = false;
}


this is where it check for distance...
you can do another condition to check for distance where the distance is == 0.
Code:

if( dist(tempCurrent.xpos, tempCurrent.ypos, tempPoint.xpos, tempPoint.ypos) == 0) {
println("right on");
}
Pages: 1 2