Sem 4‎ > ‎CG LAB‎ > ‎

P8: WAP... MY ALL IN ONE CLIPPING.

posted Feb 23, 2012, 8:21 AM by Neil Mathew
Note:
  • Using the floodfill() graphics function, I realized, just like the bucket tool in Paint, I could wipe out everything that was outside the clipping window. 

  • The floodfill() works by replacing everything with the setfillstyle color until it comes across the 'boundary color' which I've used as the colour of my clipping window.

  • Drawbacks:
    The background, shapes to be clipped and the clipping window must be of different colours.


SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
 
 
int n=11; //no of points;
 
int P[]={
        200, 50,
        150, 150,
        20,  200,
        150, 250,
        100, 400,
        200, 350,
        300, 400,
        250, 250,
        380, 200,
        250, 150,
        200, 50
        };
 
//Clipping Window
int Xmin=100;
int Ymin=100;
int Xmax=300;
int Ymax=300;
 
void ShowUP()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:/TC/BGI");
 
//DEFAULT COLOR SETTINGS:
setbkcolor(BLACK);
setfillstyle(SOLID_FILL,WHITE);
setcolor(WHITE);
 
//DRAW UNCLIPPED:
fillpoly(11,P);
setcolor(CYAN);
rectangle(Xmin,Ymin,Xmax,Ymax);
 
cout<<"\n Press Enter to start Clipping... ";
getch();
 
//FILL EVERYTHIHNG BUT CYAN BORDERS BLACK
setfillstyle(SOLID_FILL,BLACK);
floodfill(0,0,CYAN);
 
cout<<"\n Press Enter to Exit... ";
getch();
closegraph();
}
 
void main()
{
ShowUP();
}
 
 


OUTPUT:





Comments