Sem 4‎ > ‎CG LAB‎ > ‎

P3: WAP to draw a scenery using 20 graphic functions.

posted Dec 21, 2011, 9:34 AM by Neil Mathew   [ updated Dec 29, 2011, 6:45 AM ]

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Functions Used:
01 getmaxx()
02 getmaxy()
03 outtextxy()
 
04 setbkcolor()
05 setcolor()
06 settextstyle()
07 setlinestyle()
08 setfillstyle()
09 floodfill()
 
10 putpixel
11 line
12 rectangle
13 bar
14 circle
15 sector
16 arc
17 pieslice
18 ellipse
19 fillellipse
20 fillpoly
*/
 
#include<graphics.h>
#include<conio.h>
 
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver, &gmode, "C:/TC/BGI");
 
setbkcolor(WHITE);
 
setcolor(WHITE);
 
//LINE BTW SKY AND GRASS
line(0,getmaxy()*0.75, getmaxx(),getmaxy()*0.75);
 
//GRASS
setfillstyle(SOLID_FILL,GREEN);
floodfill(getmaxx(),getmaxy(),WHITE);
 
//SKY
setfillstyle(SOLID_FILL,LIGHTCYAN);
floodfill(0,0,WHITE);
 
//SUN
setcolor(RED);
setfillstyle(SOLID_FILL,YELLOW);
circle(getmaxx()*0.90,getmaxy()*0.15,40);
floodfill(getmaxx()*0.90,getmaxy()*0.15,RED);
 
 
//RAINBOW
for(int i=1, j=0; i<=6, j<=getmaxx()*0.04; i++,j++)
{            //i for colour, j for width of each arc
setcolor(i);
arc(getmaxx()*0.5,getmaxy()*0.75,0,180,getmaxx()*0.40+j);
}
 
 
 
//RAIN
 
setlinestyle(3,0,2);
setcolor(BLUE);
line(getmaxx()*0.25+60,getmaxy()*0.25,
                      getmaxx()*0.25+60,getmaxy()*0.75);
line(getmaxx()*0.25+50,getmaxy()*0.25,
                      getmaxx()*0.25+50,getmaxy()*0.75);
line(getmaxx()*0.25+40,getmaxy()*0.25,
                      getmaxx()*0.25+40,getmaxy()*0.75);
line(getmaxx()*0.25+30,getmaxy()*0.25,
                      getmaxx()*0.25+30,getmaxy()*0.75);
line(getmaxx()*0.25+20,getmaxy()*0.25,
                      getmaxx()*0.25+20,getmaxy()*0.75);
 
 
 
//CLOUD
setcolor(WHITE);
setfillstyle(HATCH_FILL,WHITE);
sector(getmaxx()*0.25,getmaxy()*0.25,0,360,30,30);
sector(getmaxx()*0.25+20,getmaxy()*0.25,0,360,30,30);
sector(getmaxx()*0.25+30,getmaxy()*0.25-30,0,360,30,30);
sector(getmaxx()*0.25+40,getmaxy()*0.25-10,0,360,30,30);
sector(getmaxx()*0.25+60,getmaxy()*0.25-20,0,360,30,30);
sector(getmaxx()*0.25+50,getmaxy()*0.25+10,0,360,30,30);
 
 
setlinestyle(0,0,1); //rectangles affected by this too.
 
//TEXT
setcolor(DARKGRAY);
settextstyle(9,HORIZ_DIR,3);
outtextxy(getmaxx()*0.75-30, getmaxy()*0.75+20, "Paradise?");
 
//POND
setfillstyle(SOLID_FILL,BLUE);
pieslice(getmaxx()*0.10,getmaxy()*0.75+1,180,360,getmaxx()*0.10);
 
//POND > LEAF
setfillstyle(SLASH_FILL,GREEN);
fillellipse(getmaxx()*0.11,getmaxy()*0.75+35,10,5);
 
//HOUSE > WALL
setcolor(WHITE);
setfillstyle(SOLID_FILL,BROWN);
bar(getmaxx()*0.5-50, getmaxy()*0.75-1,
                      getmaxx()*0.5+50, getmaxy()*0.75-100);
 
//HOUSE > DOOR
rectangle(getmaxx()*0.5-15, getmaxy()*0.75-1,
                        getmaxx()*0.5+15, getmaxy()*0.75-50);
putpixel(getmaxx()*0.5+10,getmaxy()*0.75-25,15);
 
//HOUSE > ROOF
int points[]={ getmaxx()*0.5+50, getmaxy()*0.75-100,
               getmaxx()*0.5, getmaxy()*0.75-150,
               getmaxx()*0.5-50, getmaxy()*0.75-100,
               getmaxx()*0.5+50, getmaxy()*0.75-100
             };
 
fillpoly(4,points);
 
//HOUSE > ROOF > WINDOW
setcolor(WHITE);
ellipse(getmaxx()*0.5, getmaxy()*0.75-120,0,360, 7,5);
 
getch();
closegraph();
}



OUTPUT:





Comments