Created
February 22, 2017 09:30
-
-
Save ymmtmdk/f9d18dc4851bc4202b4b1050ce9c6794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define WIDTH 6 | |
#define HEIGHT 4 | |
extern int bitmap[]; | |
void _fill(int x, int y, int from, int to){ | |
if (x < 0 || x >= WIDTH || y < 0 || y >= HEIGHT){//範囲外なら戻る | |
return; | |
} | |
if (bitmap[WIDTH*y+x] != from){//指し示した色じゃなければ戻る | |
return; | |
} | |
if (from == to){//塗る必要なし | |
return; | |
} | |
bitmap[WIDTH*y+x] = to; | |
_fill(x,y-1,from,to);//上 | |
_fill(x+1,y,from,to);//右 | |
_fill(x,y+1,from,to);//下 | |
_fill(x-1,y,from,to);//左 | |
} | |
void fill(int x, int y, int color){ | |
_fill(x, y, bitmap[WIDTH*y+x], color); | |
} | |
int bitmap[WIDTH*HEIGHT] = { | |
0,1,1,2,2,2, | |
0,1,1,1,1,1, | |
1,1,2,1,1,2, | |
0,1,2,1,1,2, | |
}; | |
void put_bitmap(){ | |
for (int y = 0; y < HEIGHT; y++){ | |
for (int x = 0 ;x < WIDTH; x++){ | |
printf("%d", bitmap[WIDTH*y+x]); | |
} | |
puts(""); | |
} | |
puts(""); | |
} | |
int main(){ | |
put_bitmap(); | |
fill(1,0,3);//x=1,y=0の色(1)を3に塗り変える | |
put_bitmap(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment