Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void GUI()
- {
- JFrame frame = new JFrame();
- frame.setLayout(new MigLayout());
- try
- {
- mapImg = ImageIO.read(new File("Res/Zipzone map of the US.png"));
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- g = mapImg.createGraphics();
- for(int i = 311; i < 1001; i++)
- {
- Random rand = new Random();
- String count = "";
- int red = rand.nextInt(220) + 25;
- int green = rand.nextInt(220) + 25;
- int blue = rand.nextInt(220) + 25;
- if(i < 100)
- {
- count = "0" + i;
- }
- else
- {
- count = i + "";
- }
- if(i <= 512)
- {
- ApplyColor(count, new Color(red, blue, green));
- }
- else if( i > 909)
- {
- ApplyColor3(count, new Color(red, blue, green));
- }
- else
- {
- ApplyColor2(count, new Color(red, blue, green));
- }
- }
- frame.add(new JLabel("", new ImageIcon(GetScaledImage(new ImageIcon(mapImg).getImage(), 1400, 875)), JLabel.CENTER), "GROW, PUSH");
- frame.setTitle("US Map");
- frame.setSize(1500,900);
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- }
- private void ApplyColor(String zip, Color color)
- {
- int x;
- int y;
- if(zip.equals("010"))
- {
- try
- {
- x = 3339;
- y = 672;
- FloodFill(x, y, new Color(mapImg.getRGB(x, y)), color);
- x = 3361;
- y = 681;
- FloodFill(x, y, new Color(mapImg.getRGB(x, y)), color);
- }
- catch(AWTException e)
- {
- e.printStackTrace();
- }
- }
- }
- public void FloodFill(int x, int y, Color targetColor, Color replacementColor) throws AWTException
- {
- if(new Color(mapImg.getRGB(x, y)).equals(replacementColor))
- {
- return;
- }
- g.setColor(replacementColor);
- g.fillRect(x, y, 1, 1);
- if(new Color(mapImg.getRGB(x-1, y)).equals(targetColor))
- {
- FloodFill(x-1, y, targetColor, replacementColor);
- }
- if(new Color(mapImg.getRGB(x+1, y)).equals(targetColor))
- {
- FloodFill(x+1, y, targetColor, replacementColor);
- }
- if(new Color(mapImg.getRGB(x, y-1)).equals(targetColor))
- {
- FloodFill(x, y-1, targetColor, replacementColor);
- }
- if(new Color(mapImg.getRGB(x, y+1)).equals(targetColor))
- {
- FloodFill(x, y+1, targetColor, replacementColor);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement