hi, i'm new to processing and i have been messing with the MouseFunction example from the website where a circle is created and you can mouse press it and drag it to a different position.
I used some example code i got elsewhere to create the array of circles and have them bounce around the screen, each having different colours.
What the code does is it combines both of the examples and for the MouseFunction example, when i hover the mouse cursor over the circle it changes to different colours but on mouse press it changes to one solid colour, and it can be dragged around the screen:
Code:
float bx;
float by;
int bs = 20;
boolean bover = false;
boolean locked = false;
float bdifx = 0.0;
float bdify = 0.0;
ani_Circle[] circles = new ani_Circle[15];
void setup()
{
size(500, 500);
bx = width/2.0;
by = height/2.0;
noStroke();
ellipseMode(RADIUS);
for(int i=0; i <15; i++)
{
circles[i] = new ani_Circle (random(0),random(0), random(7), random(7), random(255),random(255),random(255));
}
}
void draw()
{
background(0);
for(int i=0; i<15; i++)
{
circles[i].update();
}
if (mouseX > bx-bs && mouseX < bx+bs &&
mouseY > by-bs && mouseY < by+bs) {
bover = true;
if(!locked) {
stroke(255);
fill(random(255),random(255),random(255));
}
}
else {
stroke(153);
fill(153);
bover = false;
}
ellipse(bx, by, bs, bs);
}
void mousePressed() {
if(bover) {
locked = true;
fill(random(255), random(255), random(255));
} else {
locked = false;
}
bdifx = mouseX-bx;
bdify = mouseY-by;
}
void mouseDragged() {
if(locked) {
bx = mouseX-bdifx;
by = mouseY-bdify;
}
}
void mouseReleased() {
locked = false;
}
class ani_Circle
{
float x,y,r,g,b;
float xMove,yMove;
public ani_Circle(float newx, float newy, float newxMove, float newyMove, float r1, float g1,float b1)
{ // constructor
x = newx;
y = newy;
xMove = newxMove;
yMove = newyMove;
r = r1;
g = g1;
b = b1;
}
void update()
{
fill(r,g,b);
noStroke();
ellipse(x, y, 20,20);
x+= xMove;
y+= yMove;
if(x<0)
{
xMove = -xMove;
}
if(y<0) {yMove = -yMove;}
if(x>width) {xMove = -xMove;}
if(y>height){yMove = -yMove;}
}
}
I was wondering if is it possible to mouse press on any of those bouncing circles, have it change to many different colours and have it appear in a different colour when mouse press is false (it would carry on moving when there is no mouse activity).
Thanks for any feedback or suggestions =)