/*** 9.7 Implement the "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color. ***/ #include <iostream> using namespace std; void paintfill( int *a, int color, int org, int x, int y, int sz) { if (x < 0 || y < 0 || x > sz-1 || y > sz-1) return ; if (*(a+x*sz+y) != org || *(a+x*sz+y) == color) return ; *(a+x*sz+y) = color; paintfill(a, color, org, x-1, y, sz); paintfill(a, color, org, x+1, y, sz); paintfill(a, color, org, x, y-1, sz); paintfill(a, color, org, x, y+1, sz); } void main() { ...
Comments
Post a Comment