WAP to draw basic shapes by dividing total screen in equal parts.
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int xf,yf,xs,ys,xt,yt,xr,yr;
int frtop,frleft,frbottom,frright;
int srtop,srleft,srbottom,srright;
int ax,ay,stangl,enangl,rad;
int hcx,hcy,hcstangl,hcenangl,hcrad;
int ex,ey,estangl,eenangl,radx,rady;
int cx,cy,crad;
int btop,bbottom,bleft,bright;
int px,py,pstangl,penangl,prad;
int tx1,ty1,tx2,ty2,tx3,ty3;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
setcolor(getmaxcolor());
xf = getmaxx()/3;
yf = getmaxy();
xs=xf+getmaxx()/3;
ys=yf;
xt=getmaxx();
yt=getmaxy()/3;
xr=xt;
yr=yt+getmaxy()/3;
/* frame */
line(xf, 0, xf, yf);
line(xs,0,xs,ys);
line(0,yt,xt,yt);
line(0,yr,xr,yr);
//first Rectangle!
frtop=50;
frbottom=yt-50;
frleft=50;
frright=xf-50;
setcolor(6);
rectangle(frleft,frtop,frright,frbottom);
//Arc
ax=(xf+xs)/2;
ay=(yt-5);
stangl=60;
enangl=120;
rad=100;
setcolor(2);
arc(ax,ay,stangl,enangl,rad);
//Circle
cx=(xs+getmaxx())/2;
cy=yt/2;
crad=50;
setcolor(11);
circle(cx,cy,crad);
//Bar
bleft=50;
btop=yt+50;
bright=xf-50;
bbottom=yr-50;
setfillstyle(3,getmaxcolor());
bar(bleft,btop,bright,bbottom);
//Second rectangle
srtop=yt+20;
srbottom=yr-20;
srleft=xf+20;
srright=xs-20;
setcolor(10);
rectangle(srleft,srtop,srright,srbottom);
//Ellipse
ex=(xs+getmaxx())/2;
ey=(yt+yr)/2;
estangl=0;
eenangl=360;
radx=75;
rady=40;
setcolor(6);
ellipse(ex,ey,estangl,eenangl,radx,rady);
//Pieslice
px=xf/2;
py=(yr+getmaxy())/2;
pstangl=90;
penangl=180;
prad=75;
setfillstyle(2,getmaxcolor());
setcolor(5);
pieslice(px,py,pstangl,penangl,prad);
//halfcircle
hcx=(xf+xs)/2;
hcy=(yr+getmaxy())/2;
hcstangl=0;
hcenangl=180;
hcrad=70;
setcolor(3);
arc(hcx,hcy,hcstangl,hcenangl,hcrad);
// triangle
tx1=(xs+getmaxx())/2;
ty1=yr+20;
tx2=tx1-50;
ty2=getmaxy()-50;
tx3=tx1+50;
ty3=getmaxy()-50;
setcolor(14);
line(tx1,ty1,tx2,ty2);
line(tx2,ty2,tx3,ty3);
line(tx1,ty1,tx3,ty3);
/* clean up */
getch();
closegraph();
return 0;
}
Comments
Post a Comment