Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<graphics.h>
- void boundaryFill(int x, int y, int fillColor, int boundColor) {
- int currentColor = getpixel(x,y);
- if((currentColor != fillColor) && (currentColor != boundColor)) {
- putpixel(x, y, fillColor);
- // delay(1); // <3
- boundaryFill(x+1, y, fillColor, boundColor);
- boundaryFill(x-1, y, fillColor, boundColor);
- boundaryFill(x, y+1, fillColor, boundColor);
- boundaryFill(x, y-1, fillColor, boundColor);
- }
- }
- void floodFill(int x, int y, int fillColor, int oldColor) {
- int currentColor = getpixel(x,y);
- if((currentColor == oldColor)) {
- putpixel(x, y, fillColor);
- // delay(1); // <3
- floodFill(x+1, y, fillColor, oldColor);
- floodFill(x-1, y, fillColor, oldColor);
- floodFill(x, y+1, fillColor, oldColor);
- floodFill(x, y-1, fillColor, oldColor);
- }
- }
- void main() {
- int gd = DETECT, gm;
- initgraph(&gd, &gm, "C:\\TC\\BGI");
- setcolor(WHITE);
- circle(200, 200, 40);
- boundaryFill(200, 200, RED, WHITE);
- setcolor(YELLOW);
- line(400, 400, 450, 300);
- setcolor(GREEN);
- line(450, 300, 500, 400);
- setcolor(RED);
- line(400, 400, 500, 400);
- floodFill(450, 375, BLUE, BLACK);
- getch();
- closegraph();
- }
Add Comment
Please, Sign In to add comment