Page 108 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 108
Lab on Computer Graphics
Notes closegraph();
return;
}
void floodfill4 (int x, int y, int oldclr, int newclr)
{
struct Node* first, *last, *tmp;
first = (struct Node*) malloc (sizeof (struct Node));
if (first == NULL)
{
closegraph();
fprintf (stderr, “floodfill4: Out of memory.\n”);
exit (2);
}
if (oldclr == newclr)
{
free (first);
return;
}
first->x = x;
first->y = y;
first->next = NULL;
last = first;
while (first != NULL)
{
putpixel (x, y, newclr);
if (getpixel (x, y–1) == oldclr)
{
putpixel (x, y–1, newclr);
insert (x, y–1, &last);
}
if (getpixel (x, y+1) == oldclr)
{
putpixel (x, y+1, newclr);
insert (x, y+1, &last);
}
if (getpixel (x–1, y) == oldclr)
{
putpixel (x–1, y, newclr);
insert (x–1, y, &last);
}
if (getpixel (x+1, y) == oldclr)
{
102 LOVELY PROFESSIONAL UNIVERSITY