You are on page 1of 17

How to make a hut with line Statement

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
void main (void)
{i n t g d , g m ;
gd=DETECT;
i n i tg r aph (&g d ,&g m, "C: \ \ t c\ \ bg i ") ;
line(140,80,480,80); //top horizontal
line(140,80,72,180); //left point diagonal
line(480,80,412,180); // right point diagonal
-1
line(480,80,548,180); // right point diagonal
-2
line(72,180,548,180); //mid
Hut horizontal
line(72,180,72,360); //mid Hut horizontal
to vertical down
line(412,180,412,360);//second vertical
line(548,180,548,360); //third vertical
line(72,360,548,360); // Bottom Line
horizontal
line(450,250,510,250); //door of theHUT
line(450,250,450,360);
line(510,250,510,360);
line(462,120,495,120);//window
line(462,120,462,150);
line(495,120,495,150);
line(462,150,495,150); //complete HUT
getch();}

Output:
Figure 1.5: How to make a Hut through Line
statement on C Graphics mode

LINE,ARC,PI
ESLICE &

Circle to draw

some shapes.
#include<conio.h>
#include<graphics.h>
#include<stdio.h>v o i d m a i n ( v o i d ) {
clrscr();
intgd=DETECT,gm;i n i t g r a p h ( & g d , & g m , " C : \ \ t c \ \ b g i
");
arc(250,180,90,270,105);//

m o o n arc(220,180,90,270,100); / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / line(250,140,210,210); //Star
line(250,140,290,210);
line(210,210,290,160); //left line diagonal
line(290,160,210,160); //Horizontal
line(210,160,290,210); //right line
diagonal / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / /
line(380,140,350,40);
line(380,140,410,40);
arc(380,65,40,140,40);
arc(380,70,40,138,38);
arc(380,75,40,136,34);
pieslice(380,140,310,230,30);
circle(380,160,20);circle(380,160,30); / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / /
line(320,0,320,480);line(0,300,640,300); / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / setcolor(RED+GREEN);
circle(60,380,50);o u t t e x t x y ( 4 0 , 3 8 0 , " C I R C L E " ) ; / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / /
setcolor(BLUE+WHITE+YELLOW);
arc(160,380,0,135,30);o u t t e x t x y ( 1 6 0 , 3 8 0 , " A R C " ) ; /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / /

setcolor(YELLOW+RED+BLACK);
pieslice(200,390,215,350,40);
outtextxy(200,390,"PIESLICE"); / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /

/ / / / / / / / / / / / / / / / / / setcolor(GREEN);outtex
txy(340,320,"Syed Salman Mehdi");
setcolor(GREEN+BLUE);
outtextxy(340,340,"06IT29 QUEST Nawabsh

TO MAKE A FISH
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
void main()
{
int gd = DETECT,gm;
initgraph(&gd,&gm ,"");
ellipse(200,200,0,360,50,30);
line(250,200,280,170);
line(280,170,280,230);
line(280,230,250,200);
circle(160,190,3);
getch();
closegraph();
}
CIRCLE CHANGING COLOUR AND DESIGN
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
void main()
{

int gd=DETECT,gm;
int x,y,r,c,mx,my;
initgraph(&gd,&gm," ");
cout<<"enter x, y , r,c";
cin>>x>>y>>r>>c;
mx=getmaxx();
my=getmaxy();
while(!kbhit())
{
if((x>=mx)||(y>=my))
{
while((x>0)||(y>0))
{
cleardevice(); W3Professors.Com Hartej Singh Page No. 2 W3Professors.Com
Hartej Singh

setcolor(c);
circle(x,y,r);
setfillstyle(rand()%11,rand()%16);
floodfill(x,y,c);
x=x-rand()%10;
y=y-rand()%10;
}
}
else
{
while((x<=mx)||(y<=my))
{
cleardevice();
setcolor(c);
circle(x,y,r);
setfillstyle(rand()%11,rand()%16);
floodfill(x,y,c);
x=x+rand()%10;
y=y+rand()%10;
}
}
delay(10); W3Professors.Com Hartej Singh Page No. 3 W3Professors.Com Hartej
Singh

}
getch();
closegraph();
}

ROAD ANIMATION
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int gd=DETECT, gm, c, d, e, f, g;
clrscr();
initgraph(&gd, &gm, " ");
cout<<"enter 5 colours";
cin>>c>>d>>e>>f>>g;
setcolor(c);
rectangle(100,100,300,150);
setfillstyle(SOLID_FILL,d);
floodfill(120,120,c);
rectangle(100,150,300,200);
setfillstyle(SOLID_FILL,e);
floodfill(120,160,c);
rectangle(100,200,300,250);

line(100,250,100,475);
setfillstyle(SOLID_FILL,f);
floodfill(120,220,c);
circle(200,175,20);
setcolor(g);W3Professors.Com
line(200,160,200,190);
line(180,175,220,175);
line(190,167,210,183);
line(190,183,210,167);
getch();
closegraph();
}

W3Professors.Com
SCALING TRANSFORMATION
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{

int gd=DETECT,gm;
initgraph(&gd,&gm,"");
int x1,y1,x2,y2,sx,sy,x3,y3,x4,y4,x5,y5,x6,y6;
cout<<"x1,y1,x2,y2";
cin>>x1>>y1>>x2>>y2;
rectangle(x1,y1,x2,y2);
cout<<"sx,sy";
cin>>sx>>sy;
x3=x1*sx;
y3=y1*sy;
x4=x2*sx;
y4=y2*sy;
rectangle(x3,y3,x4,y4);
cout<<"-sx,-sy";
cin>>sx>>sy;
x5=x1/sx;
y5=y1/sy;
x6=x2/sx;W3Professors.Com
y6=y2/sy;
rectangle(x5,y5,x6,y6);
getch();
closegraph();

}
W3Professors.Com
TO MOVE PERSON HAVING BALLOON
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
#include<DOS.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
int x,y,xm;
cout<<"enter x,y";
cin>>x>>y;
xm=getmaxx();
circle(x,y,50);
ellipse(x-25,y-15,0,360,3,2);
ellipse(x+25,y-15,0,360,3,2);
line(x,y-10,x,y+10);
arc(x,y+15,180,360,15);

line(x,y+50,x,y+130);
line(x,y+130,x-30,y+180);
line(x-30,y+180,x-50,y+170);
line(x,y+130,x+30,y+180);
line(x+30,y+180,x+50,y+170);
line(x,y+75,x+75,y+75);W3Professors.Com
line(x+75,y+75,x+170,y-10);
ellipse(x+170,y-50,0,360,28,40);
while(!kbhit())
{
if(x<=xm)
{
cleardevice();
x=x+20;
circle(x,y,50);
ellipse(x-25,y-15,0,360,3,2);
ellipse(x+25,y-15,0,360,3,2);
line(x,y-10,x,y+10);
arc(x,y+15,180,360,15);
line(x,y+50,x,y+130);
line(x,y+130,x-30,y+180);
line(x-30,y+180,x-50,y+170);

line(x,y+130,x+30,y+180);
line(x+30,y+180,x+50,y+170);
line(x,y+75,x+75,y+75);
line(x+75,y+75,x+170,y-10);
ellipse(x+170,y-50,0,360,28,40);
delay(100);
}
else
{
doW3Professors.Com
{
cleardevice();
x=x-20;
circle(x,y,50);
ellipse(x-25,y-15,0,360,3,2);
ellipse(x+25,y-15,0,360,3,2);
line(x,y-10,x,y+10);
arc(x,y+15,180,360,15);
line(x,y+50,x,y+130);
line(x,y+130,x-30,y+180);
line(x-30,y+180,x-50,y+170);
line(x,y+130,x+30,y+180);

line(x+30,y+180,x+50,y+170);
line(x,y+75,x+75,y+75);
line(x+75,y+75,x+170,y-10);
ellipse(x+170,y-50,0,360,28,40);
delay(100);
}while(x!=0);
}
}
getch();
closegraph();
}
TO MAKE A KITE
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
void main()
{
int a,b,gd=DETECT,gm,i;
initgraph(&gd,&gm," ");
line(100,100,50,180);
line(100,100,150,180);
line(50,180,100,250);

line(150,180,100,250);
line(100,100,100,250);
line(50,180,150,180);
line(100,250,70,300);
line(100,250,130,300);
line(70,300,130,300);
line(100,300,120,320);
line(120,320,80,340);
line(80,340,120,360);
line(120,360,80,380);W3Professors.Com Hartej Singh
W3Professors.Com Hartej Singh
setcolor(4);
getch();
closegraph();
}
W3Professors.Com
POLAR ELLIPSE
#include<graphics.h>
#include<conio.h>
#include<iostream.h>
#include<math.h>
#include<stdlib.h>

Page No. 2

#include<DOS.h>
void ep(float x,float y,float xc,float yc)
{
putpixel(x+xc,y+yc,RED);
putpixel(-x+xc,y+yc,RED);
putpixel(-x+xc,-y+yc,RED);
putpixel(x+xc,-y+yc,RED);
delay(100);
}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
cleardevice();
int x, y,xc,yc,xr,yr,theta,theta_end;
cout<<"enter values for xc,yc,xr,yr";W3Professors.Com
cin>>xc>>yc>>xr>>yr;
theta=0;
theta_end=90;
while (theta<=theta_end)
{
x=xr*cos (theta) + xc;

y=yr*sin (theta) + yc;


ep(x, y, xc, yc);
theta=theta+1;
}
getch();
closegraph();
}

You might also like