Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void drawDog(Graphics2D g) {
- g.setPaint(Color.BLACK);
- g.setStroke(new BasicStroke(1));
- AffineTransform previousTransform;
- g.transform(new AffineTransform(4f, 0, 0, 4f, 0, 0));
- // Задняя часть хвоста
- drawCurvedLine(g, new Point2D.Double(109.5, 22.5), Arrays.asList(
- new CurvePoints(115.3, 22.6, 120.6, 25.6, 123.3, 30.5),
- new CurvePoints(126.1, 35.3, 125.9, 41.2, 122.8, 45.9),
- new CurvePoints(119.7, 50.6, 114.2, 53.3, 108.4, 52.9)));
- // Спина, задняя часть ушей и передняя часть хвоста
- drawCurvedLine(g, new Point2D.Double(109.7, 22.6), Arrays.asList(
- new CurvePoints(118.6, 28.6, 120.5, 38, 114.4, 45.5),
- new CurvePoints(108.4, 53.1, 95.6, 56.7, 84, 54.4),
- new CurvePoints(72.2, 52.2, 64, 44.5, 64.2, 35.9)));
- // Уши
- drawCurvedLine(g, new Point2D.Double(64.2, 36.7), Arrays.asList(
- new CurvePoints(64.2, 36.7, 63.8, 31.8, 63.2, 35.6),
- new CurvePoints(63.2, 35.6, 61.1, 47.8, 59.7, 43.9),
- new CurvePoints(56.7, 35.2, 58.1, 32.1, 56.7, 35.2),
- new CurvePoints(55.6, 39.7, 55.6, 40.4, 55.6, 40.4)));
- // Передняя часть головы
- drawCurvedLine(g, new Point2D.Double(55.6, 40.4), Collections.singletonList(
- new CurvePoints(53, 55, 45, 48, 42, 51)));
- // Подбородок
- drawCurvedLine(g, new Point2D.Double(42.3, 51.1), Collections.singletonList(
- new CurvePoints(66.3, 64.7, 70.2, 57.6, 66.3, 64.7)));
- // Нос
- previousTransform = g.getTransform();
- g.transform(new AffineTransform(0.93f, 0.37f, -0.16f, 0.99f, 0, 0));
- g.draw(new Ellipse2D.Double(48.7, 30.3, 3.7, 2.7));
- g.setTransform(previousTransform);
- // Глаза
- previousTransform = g.getTransform();
- g.transform(new AffineTransform(0.97f, -0.26f, 0.26f, 0.97f, 0, 0));
- g.draw(new Ellipse2D.Double(41.7, 59.6, 0.4, 2.1));
- g.draw(new Ellipse2D.Double(43.4, 59.9, 0.4, 2.4));
- g.setTransform(previousTransform);
- // Рот
- drawCurvedLine(g, new Point2D.Double(54.5, 57.1), Collections.singletonList(
- new CurvePoints(60.7, 55.9, 60.6, 54.5, 60.6, 54.5)));
- // Передняя часть ног
- drawStraightLine(g, new Point2D.Double(66.3, 64.7), new Point2D.Double(60.9, 74.4));
- // Передние ноги
- drawCurvedLine(g, new Point2D.Double(60.9, 74.4), Collections.singletonList(
- new CurvePoints(68.9, 69.7, 67.9, 71.6, 70.9, 77.9)));
- // Задние ноги
- drawCurvedLine(g, new Point2D.Double(115.7, 77.1), Collections.singletonList(
- new CurvePoints(108, 67.8, 106.3, 68.1, 109.3, 78.6)));
- // Задняя часть ног
- drawStraightLine(g, new Point2D.Double(108.4, 52.8), new Point2D.Double(115.7, 77.1));
- // Расстояние между передними ногами и задними ногами
- g.transform(new AffineTransform(0.86f, -0.51f, 0.5f, 0.87f, 0, 0));
- drawCurvedLine(g, new Point2D.Double(22.4, 103.4), Arrays.asList(
- new CurvePoints(29, 99.2, 37.1, 99.1, 43.8, 103.2),
- new CurvePoints(50.5, 107.2, 54.9, 114.8, 55.4, 123.2)));
- }
- private static class CurvePoints {
- Point2D.Double point1;
- Point2D.Double point2;
- Point2D.Double point3;
- CurvePoints(double x1, double y1, double x2, double y2, double x3, double y3) {
- point1 = new Point2D.Double(x1, y1);
- point2 = new Point2D.Double(x2, y2);
- point3 = new Point2D.Double(x3, y3);
- }
- }
- private static void drawCurvedLine(Graphics2D g, Point2D.Double startPoint, List<CurvePoints> curvePoints) {
- GeneralPath shape = new GeneralPath();
- shape.moveTo(startPoint.getX(), startPoint.getY());
- curvePoints.forEach(curvePoint -> shape.curveTo(
- curvePoint.point1.getX(), curvePoint.point1.getY(),
- curvePoint.point2.getX(), curvePoint.point2.getY(),
- curvePoint.point3.getX(), curvePoint.point3.getY()));
- g.draw(shape);
- }
- private static void drawStraightLine(Graphics2D g, Point2D.Double startPoint, Point2D.Double endPoint) {
- GeneralPath shape = new GeneralPath();
- shape.moveTo(startPoint.getX(), startPoint.getY());
- shape.lineTo(endPoint.getX(), endPoint.getY());
- g.draw(shape);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement