Darano

Untitled

Oct 14th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3.  
  4. public class SmallSize extends Shape {
  5.     public SmallSize(int x, int y, int diameter){
  6.         super(x, y, diameter);
  7.     }
  8.     void draw(Graphics g) {
  9.         g.setColor(color);
  10.         g.fillOval(x, y, diameter, diameter);
  11.         g.setColor(Color.black);
  12.         g.drawOval(x, y, diameter, diameter);
  13.     }
  14.  
  15.     boolean containsPoint(int x, int y) {
  16.         // Check whether (x,y) is inside this oval, using the
  17.         // mathematical equation of an ellipse.
  18.         double rx = diameter / 2.0;   // horizontal radius of ellipse
  19.         double ry = diameter / 2.0;  // vertical radius of ellipse
  20.         double cx = x + rx;   // x-coord of center of ellipse
  21.         double cy = y + ry;    // y-coord of center of ellipse
  22.         if ((ry * (x - cx)) * (ry * (x - cx)) + (rx * (y - cy)) * (rx * (y - cy)) <= rx * rx * ry * ry)
  23.             return true;
  24.         else
  25.             return false;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment