Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.69 KB | None | 0 0
  1. private static void drawDog(Graphics2D g) {
  2.         g.setPaint(Color.BLACK);
  3.         g.setStroke(new BasicStroke(1));
  4.  
  5.         AffineTransform previousTransform;
  6.  
  7.         g.transform(new AffineTransform(4f, 0, 0, 4f, 0, 0));
  8.  
  9.         // Задняя часть хвоста
  10.         drawCurvedLine(g, new Point2D.Double(109.5, 22.5), Arrays.asList(
  11.                 new CurvePoints(115.3, 22.6, 120.6, 25.6, 123.3, 30.5),
  12.                 new CurvePoints(126.1, 35.3, 125.9, 41.2, 122.8, 45.9),
  13.                 new CurvePoints(119.7, 50.6, 114.2, 53.3, 108.4, 52.9)));
  14.  
  15.         // Спина, задняя часть ушей и передняя часть хвоста
  16.         drawCurvedLine(g, new Point2D.Double(109.7, 22.6), Arrays.asList(
  17.                 new CurvePoints(118.6, 28.6, 120.5, 38, 114.4, 45.5),
  18.                 new CurvePoints(108.4, 53.1, 95.6, 56.7, 84, 54.4),
  19.                 new CurvePoints(72.2, 52.2, 64, 44.5, 64.2, 35.9)));
  20.  
  21.         // Уши
  22.         drawCurvedLine(g, new Point2D.Double(64.2, 36.7), Arrays.asList(
  23.                 new CurvePoints(64.2, 36.7, 63.8, 31.8, 63.2, 35.6),
  24.                 new CurvePoints(63.2, 35.6, 61.1, 47.8, 59.7, 43.9),
  25.                 new CurvePoints(56.7, 35.2, 58.1, 32.1, 56.7, 35.2),
  26.                 new CurvePoints(55.6, 39.7, 55.6, 40.4, 55.6, 40.4)));
  27.  
  28.         // Передняя часть головы
  29.         drawCurvedLine(g, new Point2D.Double(55.6, 40.4), Collections.singletonList(
  30.                 new CurvePoints(53, 55, 45, 48, 42, 51)));
  31.  
  32.         // Подбородок
  33.         drawCurvedLine(g, new Point2D.Double(42.3, 51.1), Collections.singletonList(
  34.                 new CurvePoints(66.3, 64.7, 70.2, 57.6, 66.3, 64.7)));
  35.  
  36.         // Нос
  37.         previousTransform = g.getTransform();
  38.         g.transform(new AffineTransform(0.93f, 0.37f, -0.16f, 0.99f, 0, 0));
  39.         g.draw(new Ellipse2D.Double(48.7, 30.3, 3.7, 2.7));
  40.         g.setTransform(previousTransform);
  41.  
  42.         // Глаза
  43.         previousTransform = g.getTransform();
  44.         g.transform(new AffineTransform(0.97f, -0.26f, 0.26f, 0.97f, 0, 0));
  45.         g.draw(new Ellipse2D.Double(41.7, 59.6, 0.4, 2.1));
  46.         g.draw(new Ellipse2D.Double(43.4, 59.9, 0.4, 2.4));
  47.         g.setTransform(previousTransform);
  48.  
  49.         // Рот
  50.         drawCurvedLine(g, new Point2D.Double(54.5, 57.1), Collections.singletonList(
  51.                 new CurvePoints(60.7, 55.9, 60.6, 54.5, 60.6, 54.5)));
  52.  
  53.         // Передняя часть ног
  54.         drawStraightLine(g, new Point2D.Double(66.3, 64.7), new Point2D.Double(60.9, 74.4));
  55.  
  56.         // Передние ноги
  57.         drawCurvedLine(g, new Point2D.Double(60.9, 74.4), Collections.singletonList(
  58.                 new CurvePoints(68.9, 69.7, 67.9, 71.6, 70.9, 77.9)));
  59.  
  60.         // Задние ноги
  61.         drawCurvedLine(g, new Point2D.Double(115.7, 77.1), Collections.singletonList(
  62.                 new CurvePoints(108, 67.8, 106.3, 68.1, 109.3, 78.6)));
  63.  
  64.         // Задняя часть ног
  65.         drawStraightLine(g, new Point2D.Double(108.4, 52.8), new Point2D.Double(115.7, 77.1));
  66.  
  67.         // Расстояние между передними ногами и задними ногами
  68.         g.transform(new AffineTransform(0.86f, -0.51f, 0.5f, 0.87f, 0, 0));
  69.         drawCurvedLine(g, new Point2D.Double(22.4, 103.4), Arrays.asList(
  70.                 new CurvePoints(29, 99.2, 37.1, 99.1, 43.8, 103.2),
  71.                 new CurvePoints(50.5, 107.2, 54.9, 114.8, 55.4, 123.2)));
  72.     }
  73.  
  74.     private static class CurvePoints {
  75.         Point2D.Double point1;
  76.         Point2D.Double point2;
  77.         Point2D.Double point3;
  78.  
  79.         CurvePoints(double x1, double y1, double x2, double y2, double x3, double y3) {
  80.             point1 = new Point2D.Double(x1, y1);
  81.             point2 = new Point2D.Double(x2, y2);
  82.             point3 = new Point2D.Double(x3, y3);
  83.         }
  84.     }
  85.  
  86.     private static void drawCurvedLine(Graphics2D g, Point2D.Double startPoint, List<CurvePoints> curvePoints) {
  87.         GeneralPath shape = new GeneralPath();
  88.         shape.moveTo(startPoint.getX(), startPoint.getY());
  89.         curvePoints.forEach(curvePoint -> shape.curveTo(
  90.                 curvePoint.point1.getX(), curvePoint.point1.getY(),
  91.                 curvePoint.point2.getX(), curvePoint.point2.getY(),
  92.                 curvePoint.point3.getX(), curvePoint.point3.getY()));
  93.         g.draw(shape);
  94.     }
  95.  
  96.     private static void drawStraightLine(Graphics2D g, Point2D.Double startPoint, Point2D.Double endPoint) {
  97.         GeneralPath shape = new GeneralPath();
  98.         shape.moveTo(startPoint.getX(), startPoint.getY());
  99.         shape.lineTo(endPoint.getX(), endPoint.getY());
  100.         g.draw(shape);
  101.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement