i have a small ellipse which bounces around in the space and a large ellipse in the center that does not move. how do i make the little ellipse bounce off the big ellipse when it hits it?
Idea ideas;
int size = 60; // Width of the shape
float xpos, ypos; // Starting position of shape
float xspeed = 2.8; // Speed of the shape
float yspeed = 2.2; // Speed of the shape
int xdirection = 1; // Left or Right
int ydirection = 1; // Top to Bottom
void setup() {
size (800, 800);
smooth ();
strokeWeight (2);
xpos = width/2;
ypos = height/2;
}
// ------------------------------------------------------------------------------ Main methods
void draw () {
background (100);
ellipse (width/2, height/2, 400, 400);
xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );
if (xpos > width-size || xpos < 0) {
xdirection *= -1;
}
if (ypos > height-size || ypos < 0) {
ydirection *= -1;
}
ellipse(xpos+size/2, ypos+size/2, size, size);
}
Idea ideas;
int size = 60; // Width of the shape
float xpos, ypos; // Starting position of shape
float xspeed = 2.8; // Speed of the shape
float yspeed = 2.2; // Speed of the shape
int xdirection = 1; // Left or Right
int ydirection = 1; // Top to Bottom
void setup() {
size (800, 800);
smooth ();
strokeWeight (2);
xpos = width/2;
ypos = height/2;
}
// ------------------------------------------------------------------------------ Main methods
void draw () {
background (100);
ellipse (width/2, height/2, 400, 400);
xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );
if (xpos > width-size || xpos < 0) {
xdirection *= -1;
}
if (ypos > height-size || ypos < 0) {
ydirection *= -1;
}
ellipse(xpos+size/2, ypos+size/2, size, size);
}
1