Sem 4‎ > ‎CG LAB‎ > ‎

P1: WAP using 10 graphics functions.

posted Dec 18, 2011, 6:04 AM by Neil Mathew   [ updated Dec 21, 2011, 9:31 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
/*Functions Used:
            
1  getmaxx()
2  getmaxy()
3  Line()
4  Rectangle()
5  Drawpoly()
6  Circle()
7  Arc()
8  Pieslice()
9  Setcolor()
10 Setbkcolor()
11 Setfillstyle()
 
*/
 
 
#include <graphics.h>
#include <iostream.h>
#include <conio.h>
 
int main()
{    
 
int gdriver = DETECT, gmode;     
initgraph(&gdriver, &gmode, "C:/TC/BGI/");
 
setbkcolor(0);
setcolor(8);
//Asteroid Backgroumd
int i,j;
for(i=0; i<getmaxx(); i+=40)
{
         for(j=0; j<=getmaxy(); j+=60)
         {                  circle(i,j,1);         }
}
 
setcolor(15);
//Polygons : Triangles
int points_up[]={getmaxx()*0.90, getmaxy()*0.85-60, 
                 getmaxx()*0.90-20,getmaxy()*0.85-30,
                 getmaxx()*0.90+20, getmaxy()*0.85-30, 
                 getmaxx()*0.90, getmaxy()*0.85-60
                 };
                 
int points_down[]={getmaxx()*0.90, getmaxy()*0.85+60, 
                 getmaxx()*0.90-20,getmaxy()*0.85+30,
                 getmaxx()*0.90+20, getmaxy()*0.85+30, 
                 getmaxx()*0.90, getmaxy()*0.85+60
                 };
                 
int points_left[]={getmaxx()*0.90-20-10, getmaxy()*0.85+20, 
                 getmaxx()*0.90-20-10,getmaxy()*0.85-20,
                 getmaxx()*0.90-20-40, getmaxy()*0.85, 
                 getmaxx()*0.90-20-10, getmaxy()*0.85+20
                 };
 
int points_right[]={getmaxx()*0.90+20+10, getmaxy()*0.85+20, 
                 getmaxx()*0.90+20+10,getmaxy()*0.85-20,
                 getmaxx()*0.90+20+40, getmaxy()*0.85, 
                 getmaxx()*0.90+20+10, getmaxy()*0.85+20
                 };
                 
drawpoly(4,points_up);
drawpoly(4,points_down);
drawpoly(4,points_left);
drawpoly(4,points_right);
 
//Square
rectangle(getmaxx()*0.90-20, getmaxy()*0.85-20, 
                            getmaxx()*0.90+20, getmaxy()*0.85+20);
 
setfillstyle(SOLID_FILL ,6);
setcolor(0); 
//Pieslices (Pacmans)
pieslice(getmaxx()*0.25,getmaxy()*0.25, 30, 360-30, 30);
pieslice(getmaxx()*0.09,getmaxy()*0.85, 30, 360-30, 30);
pieslice(getmaxx()-10,getmaxy()*0.35, 30, 360-30, 30);
pieslice(getmaxx()*0.5-20,getmaxy()*0.5+35, 30, 360-30, 30);
 
setcolor(2); 
//Borderline Rectangle
rectangle(0,0,getmaxx(),getmaxy());
 
//Outer Horizontal Lines
line(0, getmaxy()*0.5,getmaxx()*0.5-40, getmaxy()*0.5);
line(getmaxx()*0.5+40, getmaxy()*0.5, getmaxx(), getmaxy()*0.5 );
 
//Outer Vertical Lines
line(getmaxx()*0.5,0,getmaxx()*0.5, getmaxy()*0.5-40);
line(getmaxx()*0.5, getmaxy()*0.5+40,getmaxx()*0.5,getmaxy());
 
//Arcs    
arc(getmaxx()*0.5,getmaxy()*0.5, 180-30, 180+30, 40);    
arc(getmaxx()*0.5,getmaxy()*0.5, 90-30, 90+30, 40);    
arc(getmaxx()*0.5,getmaxy()*0.5, 0-30, 0+30, 40);    
arc(getmaxx()*0.5,getmaxy()*0.5, 270-30, 270+30, 40);        
    
setcolor(4);  
//Innermost Circle
circle(getmaxx()*0.5,getmaxy()*0.5,20);   
circle(getmaxx()*0.5,getmaxy()*0.5,21);  
 
//Inner Plus
line(getmaxx()*0.5-20, getmaxy()*0.5,
                       getmaxx()*0.5+20, getmaxy()*0.5);
line(getmaxx()*0.5, getmaxy()*0.5-20,
                       getmaxx()*0.5, getmaxy()*0.5+20);
 
getch();    
closegraph();        
   
return 1;
}
 


OUTPUT: