1- package ru .mifi .practice .voln .maze .implementation ;
1+ package ru .mifi .practice .voln .mazes .implementation ;
22
33import lombok .SneakyThrows ;
4- import ru .mifi .practice .voln .maze .Maze ;
4+ import ru .mifi .practice .voln .mazes .Maze ;
55
66import javax .imageio .ImageIO ;
77import java .awt .BasicStroke ;
@@ -97,6 +97,29 @@ private BufferedImage createImage(Maze.Grid maze, Maze.Point[] path) {
9797 return result ;
9898 }
9999
100+ private BufferedImage createSnapshot (Maze .Grid maze , Maze .Point [] points , Color color ) {
101+ BufferedImage result = new BufferedImage (maze .cols () * width + width , maze .rows () * width + width , BufferedImage .TYPE_INT_ARGB );
102+ Graphics2D g = result .createGraphics ();
103+ g .setRenderingHint (RenderingHints .KEY_ANTIALIASING , RenderingHints .VALUE_ANTIALIAS_ON );
104+ g .setRenderingHint (RenderingHints .KEY_COLOR_RENDERING , RenderingHints .VALUE_COLOR_RENDER_QUALITY );
105+ g .setRenderingHint (RenderingHints .KEY_RENDERING , RenderingHints .VALUE_RENDER_QUALITY );
106+ g .setRenderingHint (RenderingHints .KEY_TEXT_ANTIALIASING , RenderingHints .VALUE_TEXT_ANTIALIAS_ON );
107+ drawMaze (g , maze , lineColor , width , thickness );
108+ final Stroke lastStroke = g .getStroke ();
109+ g .setStroke (new BasicStroke (thickness ));
110+ final Color lastColor = g .getColor ();
111+ g .setColor (color );
112+ for (Maze .Point p : points ) {
113+ int halfWidth = width / 2 ;
114+ int xCenter = (p .x () * width ) + halfWidth ;
115+ int yCenter = (p .y () * width ) + halfWidth ;
116+ drawCenteredCircle (g , xCenter , yCenter , thickness );
117+ }
118+ g .setStroke (lastStroke );
119+ g .setColor (lastColor );
120+ return result ;
121+ }
122+
100123 @ SneakyThrows
101124 @ Override
102125 public void representation (String name , Maze .Grid grid , Maze .Point [] path ) {
@@ -105,4 +128,11 @@ public void representation(String name, Maze.Grid grid, Maze.Point[] path) {
105128 ImageIO .write (image , "PNG" , output );
106129 }
107130
131+ @ SneakyThrows
132+ @ Override
133+ public void snapshot (int index , Maze .Grid grid , Maze .Point [] points , Color color ) {
134+ BufferedImage image = createSnapshot (grid , points , color );
135+ File output = new File (String .format ("%03dx%03d-snapshot-%04d.png" , grid .rows (), grid .cols (), index ));
136+ ImageIO .write (image , "PNG" , output );
137+ }
108138}
0 commit comments