编写函数,实现许多图片编辑软件都支持的“填充颜色”功能

来源:互联网 发布:如何做好商务工作 知乎 编辑:程序博客网 时间:2024/06/04 20:01

enum Color
{
Black,White,Red,Yellow,Green
}
boolean paintFill(Color[][] screen,int x,int y,Color ocolor,Color ncolor)
{
if(x<0||x>=screen[0].length||y<0||y>=screen.length)
{
return false;
}
if(screen[y][x]==ocolor)
{
screen[y][x]=ncolor;
paintFill(screen,x-1,y,ocolor,ncolor);//左
paintFill(screen,x+1,y,ocolor,ncolor);//右
paintFill(screen,x,y-1,ocolor,ncolor);//上
paintFill(screen,x,y+1,ocolor,ncolor);//下
}
return true;
}
boolean paintFill(Color [][] screen,int x,int y ,Color ncolor)
{
if(screen[y][x]==ncolor) return false;
return paintFill(screen,x,y,screen[y][x],ncolor);
}


0 0
原创粉丝点击