Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <graphics.h>
- void startGraphics(){
- int gd=DETECT, gm;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- cleardevice();
- }
- void fFill(int x, int y, int o, int n){
- if(getpixel(x, y)==o){ //fill until pixel's color matches with old color
- putpixel(x, y, n);
- fFill(x+1, y, o, n);
- fFill(x-1, y, o, n);
- fFill(x, y+1, o, n);
- fFill(x, y-1, o, n);
- }
- }
- void bFill(int x, int y, int bg, int fg){
- if(getpixel(x, y)!=bg && getpixel(x, y)!=fg){ //fill until boundary's not reached
- putpixel(x, y, fg);
- bFill(x+1, y, bg, fg);
- bFill(x-1, y, bg, fg);
- bFill(x, y+1, bg, fg);
- bFill(x, y-1, bg, fg);
- }
- }
- void main(){
- startGraphics();
- setcolor(GREEN); //boundary's color will be green
- rectangle(50, 50, 75, 75); //make sure area of rectangle is small; Otherwise stack overflow ho jaayega
- fFill(60, 60, 0, 4); //0=black, 4=red
- getch();
- bFill(60, 60, 2, 9); //2=green, 9=blue
- getch();
- closegraph();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement