How do I make my ellipse stop moving if my mouse is pressed?

Guys, this is my code:

int xPosition, yPosition;
int xAdder = 3;
int yAdder = 7;
int r, g, b;
boolean rIncreasing = true;

void setup() {

  size(displayWidth/2, displayHeight); 
  xPosition = 200;
}

void draw() {

  background(255, 0, 255);

  fill(r, g, b);

  ellipse(xPosition, yPosition, 100, 100);

  xPosition = xPosition + xAdder;
  yPosition = yPosition + yAdder;

  if (xPosition > displayWidth/2) {
    xAdder = -3;
  }
  if (yPosition > displayHeight) {
   yAdder = -7; 
  }

  if (xPosition < 0) {

    xAdder = 3;
  }

  if (yPosition < 0) {

    yAdder = 7;
  }

  if (rIncreasing) {
    r = r + 1;
  } 
  else {
    r = r - 1;
  }

  if (r > 255) {
    rIncreasing = false;
  } 
  else if (r < 0) {
    rIncreasing = true;
  }
}

Can you guys modify the code making the ball stop moving when the mouse is pressed?

Answers

Sign In or Register to comment.