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 & HelpIntegration › Newbie needs help: Ellipse Recognition
Page Index Toggle Pages: 1
Newbie needs help: Ellipse Recognition (Read 660 times)
Newbie needs help: Ellipse Recognition
Oct 13th, 2006, 5:26pm
 
Hey everyone,

I'm fairly new to Processing and must admit that I am not that great of a programmer. I am working on a project right now that integrates Java with Processing.

Here is the jist of my problem; I have an ellipse that can be dragged and dropped as well as stationary ellipses that are randomly placed on screen. I want to be able to move the draggable ellipse so that it can be placed behind a number of the stationary ellipses. I am trying to figure out what I must do in order for the program to return to me how many and which of the stationary ellipses have the draggable ellipse placed behind it.

I hope that makes sense. I've modified the "MouseFunctions" example from Processing to give you an example of what I mean (keep in mind that the stationary ellipses are not randomly placed in this example).

/**
* Mouse Functions.
* Click on the box and drag it across the screen.
*/

float bx;
float by;
int bs = 30;
boolean bover = false;
boolean locked = false;
float bdifx = 0.0;
float bdify = 0.0;


void setup()
{
 size(200, 200);
 bx = width/2.0;
 by = height/2.0;
 ellipseMode(CENTER_RADIUS);  
}

void draw()
{
 background(0);
 // Test if the cursor is over the ellipse
 if (mouseX > bx-bs && mouseX < bx+bs &&
     mouseY > by-bs && mouseY < by+bs) {
   bover = true;  
   if(!locked) {
     fill(153);
   }
 } else {
   fill(153);
   bover = false;
 }
 
 // Draw the center ellipse
 smooth();
 ellipse(bx, by, bs, bs);
 
 // Draw the stationary ellipses
 ellipse(80, 30, 5, 5);
 ellipse(30, 30, 5, 5);
 ellipse(40, 60, 5, 5);
 ellipse(40, 30, 5, 5);
 ellipse(30, 75, 5, 5);
 ellipse(60, 10, 5, 5);
 ellipse(40, 100, 5, 5);
 ellipse(150, 150, 5, 5);
 ellipse(130, 160, 5, 5);
}

void mousePressed() {
 if(bover) {
   locked = true;
   fill(255, 255, 255);
 } else {
   locked = false;
 }
 bdifx = mouseX-bx;
 bdify = mouseY-by;

}

void mouseDragged() {
 if(locked) {
   bx = mouseX-bdifx;
   by = mouseY-bdify;
 }
}

void mouseReleased() {
 locked = false;
}

Like I said, I am new to this stuff so please be kind =) If anyone has any ideas or advice, I would greatly appreciate it. Thanks to anyone who took the time to read this!
Page Index Toggle Pages: 1