Je veux implémenter l'algorthm de remplissage d'inondation ... de sorte que quand j'obtiens les coordonnées x et y d'un point ... il devrait commencer à inonder de ce point et remplir jusqu'à ce qu'il trouve une limite mais il ne remplit pas la région ... dire un pentagone c'est le code que je utiliseAlgorithme de remplissage d'inondation
void setpixel(struct fill fillcolor,int x,int y)
{
glColor3f(fillcolor.r,fillcolor.g,fillcolor.b);
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
glFlush();
}
struct fill getpixcol(int x,int y)
{
struct fill gotpixel;
glReadPixels(x,y,1,1,GL_RGB,GL_UNSIGNED_BYTE,pick_col);
gotpixel.r =(float) pick_col[0]/255.0;
gotpixel.g =(float) pick_col[1]/255.0;
gotpixel.b =(float) pick_col[2]/255.0;
return(gotpixel);
}
void floodFill(int x, int y,struct fill fillcolor,struct fill boundarycolor)
{
struct fill tmp;
// if ((x < 0) || (x >= 500)) return;
// if ((y < 0) || (y >= 500)) return;
tmp=getpixcol(x,y);
while (tmp.r!=boundarycolor.r && tmp.g!=boundarycolor.g && tmp.b!=boundarycolor.b)
{
setpixel(fillcolor,x,y);
setpixel(fillcolor,x+1,y);
setpixel(fillcolor,x,y+1);
setpixel(fillcolor,x,y-1);
setpixel(fillcolor,x-1,y);
floodFill(x-1,y+1,fillcolor,boundarycolor);
floodFill(x-1,y,fillcolor,boundarycolor);
floodFill(x-1,y-1,fillcolor,boundarycolor);
floodFill(x,y+1,fillcolor,boundarycolor);
floodFill(x,y-1,fillcolor,boundarycolor);
floodFill(x+1,y+1,fillcolor,boundarycolor);
floodFill(x+1,y,fillcolor,boundarycolor);
floodFill(x+1,y-1,fillcolor,boundarycolor);
}
}
Vous devez formater ce code. C'est illisible de cette façon. Sélectionnez simplement le texte du code et appuyez sur ctrl + k. – petersohn