Advertisement
Miketo_prog

Corazao

Apr 27th, 2021
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. public void corazon(int x, int y, int size, Color color, boolean relleno, boolean flecha, Graphics g){
  2.       Graphics2D g2D = (Graphics2D) g;
  3.       int d = size/2;
  4.       int r = d/2;
  5.       int h = x+r;
  6.       int k = y+r;
  7.       double m = 4.0/3;
  8.       double x1 = ( (h+r)*m*m - 3.0*r*m + h) / (m*m+1);
  9.       double y1 = (int)(m*(x1-h-r)+k+3*r);
  10.       double x2 = (int)(x+2*r+(h-x1+r));
  11.       double y2 = y1;
  12.       double x3 = (int)(h+r);
  13.       double y3 = (int)(k+3.0*r);
  14.       int ang = (int)Math.toDegrees(Math.atan(1/m))+180;
  15.       //(puntoIzq, puntoDer, puntoV)
  16.       int[] xP = {(int)x1, (int)x2, (int)x3};
  17.       int[] yP = {(int)y1, (int)y2, (int)y3};
  18.      
  19.       if( relleno ){
  20.          g.setColor(color);
  21.          g.fillRect(h, k, d, r);
  22.          g.fillPolygon(xP, yP, xP.length);
  23.          
  24.          if( flecha ){
  25.             g2D.setStroke( new BasicStroke( 6 ) );
  26.             g.setColor(Color.black);
  27.             g.drawLine(x, y+2*d, x+2*d+26, y-26);
  28.             int xF[] = {x+2*d+26+15, x+2*d+26-10, x+2*d+26+10};
  29.             int yF[] = {y-26-15, y-26-10, y-26+10};
  30.             g.fillPolygon(xF, yF, xF.length);
  31.             g.setColor(color);
  32.          }
  33.          
  34.          g.fillOval(x, y, d, d);
  35.          g.fillOval(x+d, y, d, d);
  36.       }
  37.      
  38.       g2D.setStroke( new BasicStroke( 2 ) );
  39.       g.setColor(Color.black);
  40.       g.drawArc(x, y, d, d, 0, ang);
  41.       g.drawArc(x+d, y, d, d, 3*180-ang, ang);
  42.       //La V
  43.       g.drawLine((int)x3, (int)y3, (int)x1, (int)y1);
  44.       g.drawLine((int)x3, (int)y3, (int)x2, (int)y2);
  45.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement