Skip to main content
added 416 characters in body
Source Link
Pimgd
  • 22.3k
  • 5
  • 66
  • 144
public boolean inCircle(int mouseX, int mouseY) {
    if (distanceFromCenterOfCircle(mouseX, mouseY) <= CIRCLE_RADIUS) {
        return true;
    }

    return false;
}

Can be

public boolean inCircle(int mouseX, int mouseY) {
    return distanceFromCenterOfCircle(mouseX, mouseY) <= CIRCLE_RADIUS;
}

(int)(Math.random() * (getWidth() - CIRCLE_RADIUS * 2));

g.setColor(new Color((int)(Math.random() * 256), (int)(Math.random() * 256), (int)(Math.random() * 256)));

Looks like you could benefit from a function that takes an integer as maximum value... and then returns an integer between 0 and max minus 1.

Which does exist - you'd simply create a new instance of Random and then call randomInstance.nextInt(maxValue).


Lastly, I think you would be better off by renaming the currentCircle variable to amountOfCirclesDisplayed because that's what it really is. currentCircle seems to point to the idea that somewhere, you have a list of circles, and right now, you're working on 1 specific circle. But that's not true, because you HAVE no list of circles and all that really matters is how many you've displayed so far.

public boolean inCircle(int mouseX, int mouseY) {
    if (distanceFromCenterOfCircle(mouseX, mouseY) <= CIRCLE_RADIUS) {
        return true;
    }

    return false;
}

Can be

public boolean inCircle(int mouseX, int mouseY) {
    return distanceFromCenterOfCircle(mouseX, mouseY) <= CIRCLE_RADIUS;
}

(int)(Math.random() * (getWidth() - CIRCLE_RADIUS * 2));

g.setColor(new Color((int)(Math.random() * 256), (int)(Math.random() * 256), (int)(Math.random() * 256)));

Looks like you could benefit from a function that takes an integer as maximum value... and then returns an integer between 0 and max minus 1.

Which does exist - you'd simply create a new instance of Random and then call randomInstance.nextInt(maxValue).

public boolean inCircle(int mouseX, int mouseY) {
    if (distanceFromCenterOfCircle(mouseX, mouseY) <= CIRCLE_RADIUS) {
        return true;
    }

    return false;
}

Can be

public boolean inCircle(int mouseX, int mouseY) {
    return distanceFromCenterOfCircle(mouseX, mouseY) <= CIRCLE_RADIUS;
}

(int)(Math.random() * (getWidth() - CIRCLE_RADIUS * 2));

g.setColor(new Color((int)(Math.random() * 256), (int)(Math.random() * 256), (int)(Math.random() * 256)));

Looks like you could benefit from a function that takes an integer as maximum value... and then returns an integer between 0 and max minus 1.

Which does exist - you'd simply create a new instance of Random and then call randomInstance.nextInt(maxValue).


Lastly, I think you would be better off by renaming the currentCircle variable to amountOfCirclesDisplayed because that's what it really is. currentCircle seems to point to the idea that somewhere, you have a list of circles, and right now, you're working on 1 specific circle. But that's not true, because you HAVE no list of circles and all that really matters is how many you've displayed so far.

Source Link
Pimgd
  • 22.3k
  • 5
  • 66
  • 144

public boolean inCircle(int mouseX, int mouseY) {
    if (distanceFromCenterOfCircle(mouseX, mouseY) <= CIRCLE_RADIUS) {
        return true;
    }

    return false;
}

Can be

public boolean inCircle(int mouseX, int mouseY) {
    return distanceFromCenterOfCircle(mouseX, mouseY) <= CIRCLE_RADIUS;
}

(int)(Math.random() * (getWidth() - CIRCLE_RADIUS * 2));

g.setColor(new Color((int)(Math.random() * 256), (int)(Math.random() * 256), (int)(Math.random() * 256)));

Looks like you could benefit from a function that takes an integer as maximum value... and then returns an integer between 0 and max minus 1.

Which does exist - you'd simply create a new instance of Random and then call randomInstance.nextInt(maxValue).