Trying to get the ball to stop following the mouse
in
Programming Questions
•
2 years ago
I want this code to have the ball stop following the mouse. I also want to click and another ball appears. I have set up an array with 12 spaces but i can't remember what to do next.
here is the code so far:
float ball[];
float mx;
float my;
int radius = 0;
int edge = 56;
int inner = edge + radius;
//Background colour variables
float a = 0;
float b = 0;
float c = 0;
float d = 102;
float e = 204;
float f = 255;
void setup() {
size(750, 750);
noStroke();
smooth();
ellipseMode(RADIUS);
rectMode(CORNERS);
ball = new float[12];
for(int i = 0;i<12; i = i+1) {
ball [i] = 1;
}
}
void background1()
{
background(color(d+a,e+b,f+c));
//Change the background colours
a = (random(-1,1)) + a;
b = (random(-1,1)) + b;
c = (random(-1,1)) + c;
}
void draw() {
background1();
mx = mouseX;
my = mouseY;
mx = constrain(mx, inner+24, width - inner-24);
my = constrain(my, inner+24, height - inner-24);
noFill();
stroke(0);
strokeWeight(2);
rect(edge, edge, width-edge, height-edge);
fill(255);
if(mouseButton == LEFT)
{
noFill();
if(radius<24) {
radius=radius+3;
}
ellipse(mx, my, radius, radius);
}
}
1