Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- public class SmallSize extends Shape {
- public SmallSize(int x, int y, int diameter){
- super(x, y, diameter);
- }
- void draw(Graphics g) {
- g.setColor(color);
- g.fillOval(x, y, diameter, diameter);
- g.setColor(Color.black);
- g.drawOval(x, y, diameter, diameter);
- }
- boolean containsPoint(int x, int y) {
- // Check whether (x,y) is inside this oval, using the
- // mathematical equation of an ellipse.
- double rx = diameter / 2.0; // horizontal radius of ellipse
- double ry = diameter / 2.0; // vertical radius of ellipse
- double cx = x + rx; // x-coord of center of ellipse
- double cy = y + ry; // y-coord of center of ellipse
- if ((ry * (x - cx)) * (ry * (x - cx)) + (rx * (y - cy)) * (rx * (y - cy)) <= rx * rx * ry * ry)
- return true;
- else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment