#include<graphics.h>
#include<conio.h>
int main()
int gd = DETECT,gm;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
line(200,200,300,300);
getch();
closegraph();
return 0;
#include<conio.h>
#include<graphics.h>
void main()
clrscr();
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:turboc3\\BGI");
circle(20,15,30);
getch();
closegraph();
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
int main()
int gd = DETECT,gm;
int x ,y;
x = getmaxx()/2;
y = getmaxy()/2;
getch();
closegraph();
return 0;
#include <graphics.h>
#include <conio.h>
main()
int gd=DETECT,gm,points[]={320,150,420,300,250,300,320,150};
drawpoly(4, points);
getch();
closegraph();
return 0;
#include<graphics.h>
#include<conio.h>
int main()
settextstyle(BOLD_FONT,HORIZ_DIR,2);
outtextxy(220,10,"PIE CHART");
x = getmaxx()/2;
y = getmaxy()/2;
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1);
setfillstyle(SOLID_FILL, RED);
setfillstyle(SOLID_FILL, YELLOW);
setfillstyle(SOLID_FILL, BROWN);
getch();
closegraph();
return 0;
#include<graphics.h>
#include<conio.h>
int main()
int gd = DETECT,gm;
/* Draw Hut */
setcolor(WHITE);
rectangle(150,180,250,300);
rectangle(250,180,420,300);
rectangle(180,250,220,300);
line(200,100,150,180);
line(200,100,250,180);
line(200,100,370,100);
/* Fill colours */
setfillstyle(SOLID_FILL, BROWN);
setfillstyle(SLASH_FILL, BLUE);
setfillstyle(HATCH_FILL, GREEN);
getch();
closegraph();
return 0;
7.sin wave
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include <dos.h>
int main()
int angle = 0;
double x, y;
y = 50*sin(angle*3.141/180);
y = getmaxy()/2 - y;
putpixel(x, y, 15);
delay(100);
/* increment angle */
angle+=5;
getch();
closegraph();
return 0;
#include <conio.h>
#include <math.h>
#include <graphics.h>
#include <dos.h>
int main()
int angle = 0;
double x, y;
y = 50*tan(angle*3.141/180);
y = getmaxy()/2 - y;
putpixel(x, y, 15);
delay(50);
/* increment angle */
angle+=2;
getch();
closegraph();
return 0;
9.Moving fish
#include <conio.h>
#include <graphics.h>
#include <dos.h>
int main()
int errcode, i;
errcode = graphresult();
if (errcode != grOk)
/* error occurred */
getch();
printf("Error in graphics!!\n");
return 0;
delay(30);
/* drawing tail */
setcolor(DARKGRAY);
setfillstyle(SLASH_FILL, DARKGRAY);
setcolor(LIGHTGRAY);
setfillstyle(SOLID_FILL, LIGHTGRAY);
setcolor(DARKGRAY);
setfillstyle(SLASH_FILL, DARKGRAY);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
setcolor(BLACK);
delay(120);
cleardevice();
setcolor(DARKGRAY);
setfillstyle(SLASH_FILL, DARKGRAY);
setcolor(LIGHTGRAY);
setfillstyle(SOLID_FILL, LIGHTGRAY);
setcolor(DARKGRAY);
setfillstyle(SLASH_FILL, DARKGRAY);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
setcolor(BLACK);
cleardevice();
setcolor(DARKGRAY);
setfillstyle(SLASH_FILL, DARKGRAY);
setcolor(LIGHTGRAY);
setfillstyle(SOLID_FILL, LIGHTGRAY);
setcolor(DARKGRAY);
setfillstyle(SLASH_FILL, DARKGRAY);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
setcolor(BLACK);
cleardevice();
closegraph();
return 0;
11.car Animation
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
int main()
err = graphresult();
if (err != grOk) {
/* error occurred */
grapherrormsg(err));
maxx = getmaxx();
midy = getmaxy() / 2;
cleardevice();
setcolor(WHITE);
setcolor(YELLOW);
setfillstyle(SOLID_FILL, YELLOW);
setcolor(DARKGRAY);
if (i % 2 == 0)
setfillstyle(SLASH_FILL, DARKGRAY);
else {
setfillstyle(BKSLASH_FILL, DARKGRAY);
getch();
closegraph();
return 0;
12.Concentric circle
include<stdio.h>
#include<graphics.h>
#include<conio.h>
int main()
int gd = DETECT,gm;
int x ,y;
x = getmaxx()/2;
y = getmaxy()/2;
setcolor(RED);
circle(x, y, 30);
setcolor(GREEN);
circle(x, y, 50);
circle(x, y, 70);
setcolor(BLUE);
circle(x, y, 90);
getch();
closegraph();
return 0;
13.goal
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
int x=0,gd=DETECT,gm,points[]={0,220,1600,220,1600,900,0,900,0,220};
float y=0;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
setcolor(MAGENTA);
settextstyle(6,HORIZ_DIR,6);
outtextxy(200,250,"Hi");
delay(1000);
cleardevice();
settextstyle(7,VERT_DIR,1);
cleardevice();
setcolor(GREEN);
setfillstyle(SOLID_FILL,GREEN);
fillpoly(5,points);
setcolor(WHITE);
circle(100,100,25);
delay(1000);
line(100,125,100,185);
delay(1000);
line(100,135,125,170);
delay(1000);
line(100,135,75,170);
delay(1000);
line(100,185,125,220);
delay(1000);
line(100,185,75,220);
delay(1000);
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(135+x,210-y,10,10);
for(x=0;x<50;x++)
setcolor(WHITE);
line(100,185,75+x,220-y);
setcolor(BLACK);
line(100,185,75+x,220-y);
y=y+0.25;
setcolor(WHITE);
line(100,185,125,220);
line(100,185,75,220);
for(x=0,y=0;y<100;x++)
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(135+x,210-y,10,10);
delay(10);
setcolor(GREEN);
setfillstyle(SOLID_FILL,GREEN);
fillpoly(5,points);
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillellipse(135+x,210-y,10,10);
y=y+0.5;
for(;x<490;x++)
setcolor(RED);
fillellipse(135+x,y,10,10);
delay(10);
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillellipse(135+x,y,10,10);
y=y+0.25;
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(135+x,y,10,10);
delay(2000);
cleardevice();
setbkcolor(CYAN);
settextstyle(3,HORIZ_DIR,10);
outtextxy(200,80,"GOAL");
getch();
closegraph();
14.transilation
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<graphics.h>
void draw();
void trans();
void main()
int gd=DETECT,gm,c;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
printf("\n\t\t3D Translation\n\n");
scanf("%d%d",&x1,&y1);
scanf("%d%d",&x2,&y2);
depth=(x2-x1)/4;
mx=(x1+x2)/2;
my=(y1+y2)/2;
draw();
getch();
cleardevice();
trans();
getch();
void draw()
bar3d(x1,y1,x2,y2,depth,1);
int a1,a2,b1,b2,dep,x,y;
scanf("%d%d",&x,&y);
a1=x1+x;
a2=x2+x;
b1=y1+y;
b2=y2+y;
dep=(a2-a1)/4;
bar3d(a1,b1,a2,b2,dep,1);
setcolor(5);
draw();
#include<graphics.h>
#include<conio.h>
void main()
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
setcolor(9);
circle(150,150,35);
line(150,185,150,300);
line(150,200,120,230);
compiled by FikruM. RVU 2009
line(150,200,180,230);
line(150,300,120,330);
line(150,300,180,330);
getch();
16.transilation
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
setcolor(9);
circle(150,150,35);
line(150,185,150,300);
line(150,200,120,230);
line(150,200,180,230);
line(150,300,120,330);
line(150,300,180,330);
getch();
17.flood
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void flood(int,int,int,int);
void main()
int gd,gm=DETECT;
clrscr();
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
rectangle(50,50,100,100);
flood(55,55,12,0);
getch();
if(getpixel(x,y)==old_col)
delay(10);
putpixel(x,y,fill_col);
flood(x+1,y,fill_col,old_col);
flood(x-1,y,fill_col,old_col);
flood(x,y+1,fill_col,old_col);
flood(x,y-1,fill_col,old_col);
}}
18.scaling
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<graphics.h>
int x1,x2,y1,y2,mx,my,depth;
void draw();
void scale();
void main()
int gd=DETECT,gm,c;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
printf("\n\t\t3D Scaling\n\n");
scanf("%d%d",&x1,&y1);
scanf("%d%d",&x2,&y2);
depth=(x2-x1)/4;
mx=(x1+x2)/2;
draw();
getch();
cleardevice();
scale();
getch();
void draw()
bar3d(x1,y1,x2,y2,depth,1);
void scale()
int x,y,a1,a2,b1,b2,dep;
scanf("%d%d",&x,&y);
a1=mx+(x1-mx)*x;
a2=mx+(x2-mx)*x;
b1=my+(y1-my)*y;
b2=my+(y2-my)*y;
dep=(a2-a1)/4;
bar3d(a1,b1,a2,b2,dep,1);
setcolor(5);
draw();
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
cleardevice();
setcolor(BROWN);
cont:
while (!kbhit()) {
setcolor(4);
delay(50);
x++;
l--;
if (l == -15)
l = 15;
if (ht == 1)
h++;
else
h--;
if (h == 15)
ht = 0;
else if (h == -15)
ht = 1;
while (!kbhit());
getch();
goto cont;
}}
20.color:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void flood(int,int,int,int);
void main()
int gd,gm=DETECT;
clrscr();
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
rectangle(50,50,100,100);
flood(55,55,9,0);
getch();
if(getpixel(x,y)==old_col)
putpixel(x,y,fill_col);
flood(x+1,y,fill_col,old_col);
flood(x-1,y,fill_col,old_col);
flood(x,y+1,fill_col,old_col);
flood(x,y-1,fill_col,old_col);
}}
21. x shear
include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main()
int gd=DETECT,gm;
float shx,shy;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
scanf("%f",&shx);
line(100,0,200,0);
line(200,0,200,200);
line(200,200,100,200);
line(100,200,100,0);
printf("X-shear");
setcolor(12);
line((200+(0*shx)),0,(200+(200*shx)),200);
line((200+(200*shx)),200,(100+(200*shx)),200);
line((100+(200*shx)),200,(100+(0*shx)),0);
getch();
}
22. y shear
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main()
int gd=DETECT,gm;
float shx,shy;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
scanf("%f",­);
line(100,10,200,10);
line(200,10,200,200);
line(200,200,100,200);
line(100,200,100,10);
printf("Y-shear");
setcolor(12);
line(100,10+(shy*100),200,10+(shy*200));
line(200,10+(shy*200),200,200+(shy*200));
compiled by FikruM. RVU 2009
line(200,200+(shy*200),100,200+(shy*100));
line(100,200+(shy*100),100,10+(shy*100));
getch();
closegraph();
23.reflection
# include <stdio.h>
# include <conio.h>
# include <graphics.h>
# include <math.h>
char IncFlag;
void PolyLine()
int iCnt;
cleardevice();
line(0,240,640,240);
line(320,0,320,480);
line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1],
PolygonPoints[(iCnt+1)%3][0],PolygonPoints[(iCnt+1)%3][1]);
void Reflect()
float Angle;
int iCnt;
int Tx,Ty;
printf("endl");;
void main()
int iCnt;
PolygonPoints[iCnt][0] += 320;
PolyLine();
getch();
Reflect();
PolyLine();
getch();
#include<conio.h>
#include<dos.h>
#include<process.h>
int cx=300,cy=100,r=300;
int x=0,y,p;
int x1,y1;
setcolor(15);
if(x>=y)
return 0;
cleardevice();
if(dtn==1)
circle(cx+x,cy+y,20);
line(cx,cy,cx+x,cy+y);
else
circle(cx-x,cy+y,20);
line(cx,cy,cx-x,cy+y);
if(kbhit())
exit(0);
x++;
if(p<0)
p+=2*x+1;
else
y--;
p+=2*(x-y)+1;
x1=x;
y1=y;
path(dtn);
cleardevice();
if(dtn==1)
circle(cx+x1,cy+y1,20);
line(cx,cy,cx+x1,cy+y1);
else
circle(cx-x1,cy+y1,20);
line(cx,cy,cx-x1,cy+y1);
if(kbhit())
exit(0);
return(0);
void main()
int gd=DETECT,gm=DETECT;
initgraph(&gd,&gm,"C:/TURBOC3/BGI");
cleardevice();
putpixel(300,100,4);
while(1)
x=0;
y=r;
p=1-r;
path(1);
x=0;
y=r;
p=1-r;
path(0);
25. Biycle
#include<stdio.h>
#include<graphics.h>
void main()
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:/TURBOC3/BGI");
circle(200,200,50);
circle(400,200,50);
line(400,150,400,250);
line(350,200,450,200);
line(375,156,425,245);
line(356,180,446,222);
line(370,240,425,158);
line(356,220,444,180);
line(200,150,200,250);
line(150,200,250,200);
line(175,156,225,245);
line(156,180,246,222);
line(170,240,225,158);
line(156,220,244,180);
circle(400,200,3);
circle(200,200,3);
circle(200,200,10);
circle(300,200,15);
line(200,210,300,215);
line(300,170,300,230);
/*Draw Paddles*/
line(280,170,300,170);
line(320,230,300,230);
line(200,200,300,200);
line(300,200,220,120);
line(300,200,380,120);
line(220,120,380,120);
line(200,200,220,120);
line(220,120,220,110);
/*Draw Seat*/
circle(220,100,10);
setfillstyle(SOLID_FILL,BLUE);
floodfill(220,100,WHITE);
/*Draw Handle*/
line(400,200,365,50);
ellipse(325,50,280,80,40,40);
arc(200,200,0,180,55);
arc(400,200,80,210,55);
getch();
closegraph();
26. ball
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
int x, y = 0, j, t = 400, c = 1;
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
cleardevice();
circle(x, y, 30);
floodfill(x, y, RED);
delay(40);
if (y >= 400)
c = 0;
t -= 20;
c = 1;
y = y + (c ? 15 : -15);
getch();
27. bar
#include <graphics.h>
#include <conio.h>
int main()
settextstyle(BOLD_FONT,HORIZ_DIR,2);
setlinestyle(SOLID_LINE,0,2);
line(90,410,90,50);
line(90,410,590,410);
line(85,60,90,50);
line(95,60,90,50);
line(585,405,590,410);
line(585,415,590,410);
outtextxy(65,60,"Y");
outtextxy(570,420,"X");
outtextxy(70,415,"O");
/* Print 3D bars */
getch();
closegraph();
return 0;
#include <conio.h>
#include <graphics.h>
#include <time.h>
#include <dos.h>
#include <string.h>
int main()
long current_time;
char timeStr[256];
midx = getmaxx() / 2;
while (!kbhit())
cleardevice();
setcolor(WHITE);
setfillstyle(SOLID_FILL, WHITE);
current_time = time(NULL);
strcpy(timeStr, ctime(¤t_time));
setcolor(RED);
settextjustify(CENTER_TEXT, CENTER_TEXT);
moveto(midx, midy);
outtext(timeStr);
delay(1000);
getch();
closegraph();
return 0;