33import java .awt .*;
44import java .awt .image .BufferedImage ;
55import java .io .File ;
6+ import java .util .Random ;
67import java .util .function .ToDoubleFunction ;
78
89public class ImagePainter {
@@ -16,6 +17,12 @@ public ImagePainter(int width, int height) {
1617 graphics .fillRect (0 , 0 , width , width );
1718 }
1819
20+ public ImagePainter (BufferedImage image ) {
21+ img = new BufferedImage (image .getWidth (), image .getHeight (), BufferedImage .TYPE_INT_ARGB );
22+ graphics = img .createGraphics ();
23+ graphics .drawImage (image , 0 , 0 , null );
24+ }
25+
1926 public void drawGrayscale (int x , int y , double value ) {
2027 int grayscaleValue = (int ) (value * 255 );
2128 int rgb = 0xff << 24 | grayscaleValue << 16 | grayscaleValue << 8 | grayscaleValue ;
@@ -96,4 +103,19 @@ public static ImagePainter[] visualizeNetworks(ImageNetwork network,
96103 return painters ;
97104 }
98105
106+ public void drawGrids (ZRect [][] gridLocations ) {
107+ Color [] colors = { new Color (1 , 0 , 0 , 0.6f ), new Color (0 , 1 , 0 , 0.6f ), new Color (0 , 0 , 1 , 0.6f ),
108+ new Color (1 , 1 , 0 , 0.6f ), new Color (1 , 0 , 1 , 0.6f ), new Color (0 , 1 , 1 , 0.6f )};
109+ for (int y = 0 ; y < gridLocations .length ; y ++) {
110+ for (int x = 0 ; x < gridLocations [y ].length ; x ++) {
111+ ZRect rect = gridLocations [y ][x ];
112+ if (rect == null ) {
113+ continue ;
114+ }
115+ Color color = colors [(y * 2 + x ) % colors .length ];
116+ graphics .setColor (color );
117+ graphics .fillRect (rect .left , rect .top , rect .width (), rect .height ());
118+ }
119+ }
120+ }
99121}
0 commit comments