Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.image.BufferedImage;
- import java.util.PriorityQueue;
- public class FloodFill {
- Canvas cnvs = Canvas.getInstance();
- public void AlgFloodFill(int x, int y, int CenterColour, int newColor, BufferedImage b) {
- if (CenterColour == newColor) {
- return;
- }
- if (b.getRGB(x, y) != CenterColour) {
- return;
- }
- PriorityQueue q = new PriorityQueue();
- if ((x >= 0) && (y >= 0) && ( x < cnvs.getlength()) && (y < cnvs.getheight())) {
- b.setRGB(x, y, newColor);
- }
- System.out.println("DCCCMMM NU MERGEEE");
- q.add(x);
- q.add(y);
- while (!q.isEmpty()) {
- int nx = (int) q.poll();
- int ny = (int) q.poll();
- if ((nx -1 >= 0) && (ny >= 0) && ( nx - 1 < cnvs.getlength()) && (ny < cnvs.getheight())) {
- if (b.getRGB(nx - 1, ny) == CenterColour) {
- b.setRGB(nx - 1, ny, newColor);
- q.add(nx - 1);
- q.add(ny);
- }
- }
- if ((nx + 1 >= 0) && (ny >= 0) && ( nx + 1 < cnvs.getlength()) && (ny < cnvs.getheight())){
- if (b.getRGB(nx + 1, ny) == CenterColour) {
- b.setRGB(nx + 1, ny, newColor);
- q.add(nx + 1);
- q.add(ny);
- }
- }
- if ((nx >= 0) && (ny - 1 >= 0) && ( nx < cnvs.getlength()) && (ny - 1 < cnvs.getheight())) {
- if (b.getRGB(nx, ny - 1) == CenterColour){
- b.setRGB(nx, ny - 1, newColor);
- q.add(nx);
- q.add(ny - 1);
- }
- }
- if ((nx >= 0) && (ny + 1 >= 0) && ( nx < cnvs.getlength()) && (ny + 1 < cnvs.getheight())){
- if (b.getRGB(nx, ny + 1) == CenterColour) {
- b.setRGB(nx, ny + 1, newColor);
- q.add(nx);
- q.add(ny + 1);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement