SHARE
TWEET

Untitled

a guest Dec 14th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.geom.*;
  6. import java.util.*;
  7. import java.util.List;
  8.  
  9. /**
  10.  * This class has been automatically generated using
  11.  * <a href="http://ebourg.github.io/flamingo-svg-transcoder/">Flamingo SVG transcoder</a>.
  12.  */
  13. public class Main {
  14.  
  15.     public static void main(String[] args) {
  16.         JFrame frame = buildFrame();
  17.  
  18.         JPanel pane = new JPanel() {
  19.             @Override
  20.             protected void paintComponent(Graphics g) {
  21.                 super.paintComponent(g);
  22.                 drawPlantInPot((Graphics2D) g);
  23.             }
  24.         };
  25.  
  26.  
  27.         frame.add(pane);
  28.     }
  29.  
  30.     private static JFrame buildFrame() {
  31.         JFrame frame = new JFrame();
  32.         frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  33.         frame.setSize(200, 200);
  34.         frame.setVisible(true);
  35.         return frame;
  36.     }
  37.  
  38.     public static void paintTeddy(Graphics2D g) {
  39.         g.transform(new AffineTransform(3, 0, 0, 3, 0, 0));
  40.         // Ноги
  41.         drawEllipse(g,71, 155, 33, 17);
  42.         drawEllipse(g,113, 155, 33, 17);
  43.         // Тело
  44.         drawEllipse(g,77, 106, 65, 59);
  45.         // Голова
  46.         drawEllipse(g,83, 67, 52, 47);
  47.         // Уши
  48.         drawEllipse(g,80, 60, 17, 15);
  49.         drawEllipse(g,120, 60, 17, 15);
  50.         // Глаза
  51.         drawEllipse(g,98, 79, 5, 5);
  52.         drawEllipse(g,113, 79, 5, 5);
  53.         // Нос
  54.         drawEllipse(g,100, 88, 16, 14);
  55.         drawEllipse(g,106, 91, 4, 4);
  56.         // Руки
  57.         drawEllipse(g,65, 110, 28, 25);
  58.         drawEllipse(g,125, 110, 28, 25);
  59.     }
  60.  
  61.     public static void drawPlantInPot(Graphics2D g) {
  62.         Deque<AffineTransform> transformations = new LinkedList<>();
  63.         transformations.push(g.getTransform());
  64.         g.transform(new AffineTransform(3f, 0, 0, 3, 0, 0));
  65.         drawLine(g, new Point2D.Double(86, 165), new ArrayList<Point2D.Double>() {{
  66.             add(new Point2D.Double(122, 165));
  67.             add(new Point2D.Double(114, 192));
  68.             add(new Point2D.Double(94, 192));
  69.         }});
  70.         transformations.push(g.getTransform());
  71.         g.transform(new AffineTransform(1, 0, 0, 1, -6.047619f, 11.339286f));
  72.  
  73.         GeneralPath curve = new GeneralPath();
  74.         curve.moveTo(108.47917, 153.74702);
  75.         curve.curveTo(116.20165, 145.97331, 119.71869, 134.24982, 117.55059, 123.508934);
  76.         curve.curveTo(116.209, 116.86263, 112.79286, 110.6505, 107.89893, 105.95769);
  77.         curve.curveTo(103.00499, 101.26487, 96.65505, 98.11227, 89.958336, 97.0506);
  78.  
  79.         g.setPaint(Color.BLACK);
  80.         g.setStroke(new BasicStroke(1));
  81.         g.draw(curve);
  82.  
  83.         // Листки
  84.         affineTransform(transformations, g,0.88202477f, -0.47120312f, 0.5293596f, 0.84839755f, 0, 0);
  85.         drawEllipse(g, 16.53533172607422, 181.1499786376953, 22.840898513793945, 5.799976825714111);
  86.         affineTransform(transformations, g,0.9568766f, 0.29049474f, -0.22559392f, 0.9742214f, 0, 0);
  87.         drawEllipse(g, 118.76726531982422, 106.97824096679688, 22.840898513793945, 5.799976825714111);
  88.  
  89.         // Лепестки
  90.         affineTransform(transformations, g,1, 0, 0, 1, 0, 0);
  91.         drawEllipse(g, 82, 77, 7, 29);
  92.         affineTransform(transformations, g,0.7, -0.713, 0.7, 0.713, 0, 0);
  93.         drawEllipse(g, -19, 137, 6, 27);
  94.         affineTransform(transformations, g,0.713, 0.7, -0.713, 0.7, 0, 0);
  95.         drawEllipse(g, 133, 19, 6, 27);
  96.         affineTransform(transformations, g,0.713, 0.7, -0.713, 0.7, 0, 0);
  97.         drawEllipse(g, 134, -9, 6, 27);
  98.         affineTransform(transformations, g, 0.7, -0.7, 0.7, 0.72, 0, 0);
  99.         drawEllipse(g, -18, 107, 6, 27);
  100.         g.setTransform(transformations.pop());
  101.         g.setTransform(transformations.pop());
  102.     }
  103.  
  104.     private static void drawLine(Graphics2D g, Point2D.Double start, List<Point2D.Double> coords) {
  105.         GeneralPath line = new GeneralPath();
  106.         line.moveTo(start.getX(), start.getY());
  107.         coords.forEach(point -> line.lineTo(point.getX(), point.getY()));
  108.         line.closePath();
  109.         g.setPaint(Color.WHITE);
  110.         g.fill(line);
  111.         g.setPaint(Color.BLACK);
  112.         g.setStroke(new BasicStroke(1));
  113.         g.draw(line);
  114.     }
  115.  
  116.     private static void drawEllipse(Graphics2D g, double x, double y, double width, double height) {
  117.         Shape shape = new Ellipse2D.Double(x, y, width, height);
  118.         g.setPaint(Color.WHITE);
  119.         g.fill(shape);
  120.         g.setPaint(Color.BLACK);
  121.         g.setStroke(new BasicStroke(1));
  122.         g.draw(shape);
  123.     }
  124.  
  125.     private static void affineTransform(Deque<AffineTransform> transforms, Graphics2D g,
  126.                                         double scaleX, double shearY,
  127.                                         double shearX, double scaleY,
  128.                                         double translateX, double translateY) {
  129.         g.setTransform(transforms.pop());
  130.         transforms.push(g.getTransform());
  131.         g.transform(new AffineTransform(scaleX, shearY, shearX, scaleY, translateX, translateY));
  132.     }
  133. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top