This sketch has two ellipses; one (myBlue) that moves around the screen & another (myBlue2) that is controlled by the mouse. When they are touching, a new green circle will appear over the moving ellipse (myBlue). I would like the green ellipse's width/height to be determined by the ellipse controlled by the mouse. So, depending on the position of the mouse, the green ellipse will be wider or taller. I would like to have the two Blue ellipses inside the green ellipse at all times.
However, asking the green ellipse to get data from the x & y postion has been proving difficult since it will only grab a number & the size will not be relative to the actual positon of the two ellipses. For example, if the mouse controlled ellipse (myBlue2) is at x position 20, the green ellipse will be 20 pixels wide.
Maybe I've been staring at this too long but how do I determine my desired effect?
Should I be using a different function (beginShape?) or create another class?
My friend & I were working through this code but we're stumped.
We're trying to get 2 ellipses to become one. We know that it's easy to 'fake' it (say, two ellipses collide then create a new bigger ellipse) but we'd like to figure out how to actually make them join. Eventually we'd like to have an array of various sized ellipses that when they collide will stick together for a certain amount of time then break apart. It's sticking two objects together into one that has us stumped (lines 52-54). We're working it through with basic code now, & we have pseudocode at the part that's stumping us. Any help would be appreciated!
Ellipse myBob;
Ellipse myStan;
void setup() {
size(400, 400);
smooth();
myBob = new Ellipse(50, 50, 25);
myStan = new Ellipse(random(width), random(height), 50);
}
void draw() {
background(255);
myBob.display();
myBob.move();
myStan.display();
if(myBob.intersect(myStan)) {
myStan.highlight();
myBob.highlight();
}else {
myStan.display();
}
}
class Ellipse {
float r;
float x;
float y;
color c;
Ellipse(float tempX, float tempY, float tempR) {
r = tempR;
x = tempX;
y = tempY;
c = color(124, 0, 55);
}
void move() {
x = mouseX;
y = mouseY;
x = constrain(x,0,width);
y = constrain(y,0,height);
}
void highlight() {
c = color(0, 100, 100);
ellipse(x, y, r*4, r*2);
}
void appear() {
// make timer start;
//ellipse(leftmost side of bob, y, rightmost side of stan, y*r2);