Académique Documents
Professionnel Documents
Culture Documents
#include <stdio.h>
#include <conio.h>
#include<dos.h>
int a;
void main ()
{ clrscr();
gotoxy(a,13);
delay(200);
textcolor(a);
cprintf("ANURAG");
gotoxy(a,13);
delay(200);
textcolor(a);
cprintf("TIRKEY");
getch();
}
CAR ANIMATION
1 #include <stdio.h>
2 #include <graphics.h>
3 #include <conio.h>
#include <dos.h>
4
5 int main() {
6 int gd = DETECT, gm;
7 int i, maxx, midy;
8
9 /* initialize graphic mode */
initgraph(&gd, &gm, "X:\\TC\\BGI");
10 /* maximum pixel in horizontal axis */
11 maxx = getmaxx();
12 /* mid pixel in vertical axis */
13 midy = getmaxy()/2;
14
15 for (i=0; i < maxx-150; i=i+5) {
/* clears screen */
16 cleardevice();
17
18 /* draw a white road */
19 setcolor(WHITE);
20 line(0, midy + 37, maxx, midy + 37);
21
/* Draw Car */
22
setcolor(YELLOW);
23 setfillstyle(SOLID_FILL, RED);
24
25 line(i, midy + 23, i, midy);
26 line(i, midy, 40 + i, midy - 20);
27 line(40 + i, midy - 20, 80 + i, midy - 20);
line(80 + i, midy - 20, 100 + i, midy);
28 line(100 + i, midy, 120 + i, midy);
29 line(120 + i, midy, 120 + i, midy + 23);
30 line(0 + i, midy + 23, 18 + i, midy + 23);
31 arc(30 + i, midy + 23, 0, 180, 12);
32 line(42 + i, midy + 23, 78 + i, midy + 23);
arc(90 + i, midy + 23, 0, 180, 12);
33 line(102 + i, midy + 23, 120 + i, midy + 23);
34 line(28 + i, midy, 43 + i, midy - 15);
35 line(43 + i, midy - 15, 57 + i, midy - 15);
36 line(57 + i, midy - 15, 57 + i, midy);
line(57 + i, midy, 28 + i, midy);
37 line(62 + i, midy - 15, 77 + i, midy - 15);
38 line(77 + i, midy - 15, 92 + i, midy);
39 line(92 + i, midy, 62 + i, midy);
40 line(62 + i, midy, 62 + i, midy - 15);
41 floodfill(5 + i, midy + 22, YELLOW);
setcolor(BLUE);
42 setfillstyle(SOLID_FILL, DARKGRAY);
43 /* Draw Wheels */
44 circle(30 + i, midy + 25, 9);
45 circle(90 + i, midy + 25, 9);
46 floodfill(30 + i, midy + 25, BLUE);
47 floodfill(90 + i, midy + 25, BLUE);
/* Add delay of 0.1 milli seconds */
48 delay(100);
49 }
50
51 getch();
52 closegraph();
return 0;
53 }
54
55
56
57
58
59
60
61
62
63
Bouncing ball
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
int main() {
int gd = DETECT, gm;
int i, x, y, flag=0;
initgraph(&gd, &gm, "C:\\TC\\BGI");
while (!kbhit()) {
if(y >= getmaxy()-30 || y <= 30)
flag = !flag;
/* draws the gray board */
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
circle(x, y, 30);
floodfill(x, y, RED);
getch();
closegraph();
return 0;
}
House
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(3);
line(100,200,300,200);
line(100,400,300,400);
line(100,400,100,200);
line(300,400,300,200);
line(300,200,500,200);
line(300,400,500,400);
line(500,200,500,400);
line(170,250,270,250);
line(170,200,270,200);
line(170,250,170,400);
line(270,250,270,400);
line(200,50,400,50);
line(400,50,500,200);
line(300,200,200,50);
line(100,200,200,50);
getch();
closegraph();
}
House
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
int val[9][2] = {
{ 100, 50 },{ 125, 50 },{ 125, 100 },{ 87, 125 },{ 50, 100 }
};
int i;
h[i][0] = val[i][0]-50;
h[i][1] = val[i][1]-50;
int i;
setlinestyle (DOTTED_LINE, 0, 1);
int i;
int i;
h[i][0] *= sx;
h[i][1] *= sy;
int i;
h[i][0] += dx;
h[i][1] += dy;
int i;
float angle;
h[i][1] -= c;
h[i][0] = -h[i][0];
angle = -angle;
void ini()
int gd=DETECT,gm;
initgraph(&gd,&gm,"..\\bgi");
void dini()
getch();
closegraph();
void main()
int h[9][2],sx,sy,x,y,m,c,choice;
do
clrscr();
printf("4. Exit\n");
switch(choice)
ini();
reset (h);
draw (h);getch();
cleardevice();
draw (h);
dini();
break;
ini();
reset (h);
cleardevice();
draw(h);
getch();
cleardevice();
draw(h);
getch();
cleardevice();
draw (h);
dini();
break;
ini();
reset (h);
cleardevice();
draw (h);
dini();
break;
case 4: exit(0);
}
}while(choice!=4);
Solar system
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
void main()
int i=0,j=260,k=30,l=150,m=90;
int n=230,o=10,p=280,q=220;
float pi=3.1424,a,b,c,d,e,f,g,h,z;
int gd=DETECT,gm;
initgraph(&gd,&gm,"d:\\tc\\bgi");
outtextxy(0,10,"SOLAR SYSTEM");
circle(320,240,20); /* sun */
setfillstyle(1,4);
floodfill(320,240,15);
outtextxy(310,237,"sun");
circle(260,240,8);
setfillstyle(1,2);
floodfill(258,240,15);
floodfill(262,240,15);
outtextxy(240,220,"mercury");
circle(320,300,12);
setfillstyle(1,1);
floodfill(320,298,15);
floodfill(320,302,15);
outtextxy(335,300,"venus");
circle(320,160,10);
setfillstyle(1,5);
floodfill(320,161,15);
floodfill(320,159,15);
outtextxy(332,150, "earth");
circle(453,300,11);
setfillstyle(1,6);
floodfill(445,300,15);
floodfill(448,309,15);
outtextxy(458,280,"mars");
circle(520,240,14);
setfillstyle(1,7);
floodfill(519,240,15);
floodfill(521,240,15);
outtextxy(500,257,"jupiter");
circle(169,122,12);
setfillstyle(1,12);
floodfill(159,125,15);
floodfill(175,125,15);
outtextxy(130,137,"saturn");
circle(320,420,9);
setfillstyle(1,13);
floodfill(320,417,15);
floodfill(320,423,15);
outtextxy(310,400,"uranus");
circle(40,240,9);
setfillstyle(1,10);
floodfill(38,240,15);
floodfill(42,240,15);
outtextxy(25,220,"neptune");
circle(150,420,7);
setfillstyle(1,14);
floodfill(150,419,15);
floodfill(149,422,15);
outtextxy(120,430,"pluto");
getch();
while(!kbhit()) /*animation*/
{
a=(pi/180)*i;
b=(pi/180)*j;
c=(pi/180)*k;
d=(pi/180)*l;
e=(pi/180)*m;
f=(pi/180)*n;
g=(pi/180)*o;
h=(pi/180)*p;
z=(pi/180)*q;
cleardevice();
circle(320,240,20);
setfillstyle(1,4);
floodfill(320,240,15);
outtextxy(310,237,"sun");
circle(320+60*sin(a),240-35*cos(a),8);
setfillstyle(1,2)
pieslice(320+60*sin(a),240-35*cos(a),0,360,8);
ellipse(320,240,0,360,70,25) ;
circle(320+100*sin(b),240-60*cos(b),12);
setfillstyle(1,1);
pieslice(320+100*sin(b),240-60*cos(b),0,360,12);
ellipse(320,240,0,360,90,50) ;
circle(320+130*sin(c),240-80*cos(c),10);
setfillstyle(1,5);
pieslice(320+130*sin(c),240-80*cos(c),0,360,10);
ellipse(320,240,0,360,140,70) ;
circle(320+170*sin(d),240-100*cos(d),11);
setfillstyle(1,6);
pieslice(320+170*sin(d),240-100*cos(d),0,360,11);
ellipse(320,240,0,360,160,90) ;
circle(320+200*sin(e),240-130*cos(e),14);
setfillstyle(1,7);
pieslice(320+200*sin(e),240-130*cos(e),0,360,14);
ellipse(320,240,0,360,200,120) ;
circle(320+230*sin(f),240-155*cos(f),12);
setfillstyle(1,12);
pieslice(320+230*sin(f),240-155*cos(f),0,360,12);
circle(320+260*sin(g),240-180*cos(g),9);
ellipse(320,240,0,360,220,150) ;
setfillstyle(1,13);
pieslice(320+260*sin(g),240-180*cos(g),0,360,9);
circle(320+280*sin(h),240-200*cos(h),9);
ellipse(320,240,0,360,260,190) ;
setfillstyle(1,10);
pieslice(320+280*sin(h),240-200*cos(h),0,360,9);
circle(320+300*sin(z),240-220*cos(z),7);
ellipse(320,240,0,360,280,200) ;
setfillstyle(1,14);
pieslice(320+300*sin(z),240-220*cos(z),0,360,7);
ellipse(320,240,0,360,300,220) ;
delay(20);
i++;
j++;
k++;
l++;
m++;
n++;
o++;
p++;
q+=2;
getch();
Red light
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <string.h>
int main() {
int i, j, k, x, y, color;
char str[64];
err = graphresult();
if (err != grOk) {
/* error occurred */
grapherrormsg(err));
return 0;
cleardevice();
setcolor(DARKGRAY);
setfillstyle(SOLID_FILL, DARKGRAY);
rectangle(50, 45, 150, 300);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
y = 125;
moveto(x, y);
settextjustify(CENTER_TEXT, CENTER_TEXT);
if (i == 0) {
setcolor(LIGHTRED);
outtext("STOP");
color = LIGHTRED;
y = 90;
} else if (i == 1) {
setcolor(YELLOW);
outtext("READY");
color = YELLOW;
y = 170;
} else {
setcolor(GREEN);
outtext("START");
color = GREEN;
y = 250;
x = 100;
if (color != YELLOW) {
k = 10;
} else {
k = 5;
}
for (j = k; j > 0; j--) {
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
circle(x, y, 30);
setcolor(color);
setfillstyle(SOLID_FILL, color);
circle(x, y, 30);
setcolor(BLACK);
moveto(x, y);
outtext(str);
sleep(1);
cleardevice();
getch();
/* deallocate memory allocated for graphic screen */
closegraph();
return 0;
Stickman walking
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
int main() {
err = graphresult();
if (err != grOk) {
/* error occurred */
printf("Graphics Error: %s\n",
grapherrormsg(err));
return 0;
x = 50;
midy = getmaxy() / 2;
y = midy - 100;
/*
*/
cleardevice();
setlinestyle(SOLID_LINE, 1, 3);
circle(x, y, radius);
/* hand motion */
delay(150);
cleardevice();
x++;
setlinestyle(SOLID_LINE, 1, 3);
circle(x, y, radius);
/* leg design */
delay(100);
/* image 3 */
cleardevice();
setlinestyle(SOLID_LINE, 1, 3);
x++;
circle(x, y, radius);
/* leg design */
/* hand motion */
/* image 4 */
cleardevice();
x++;
setlinestyle(SOLID_LINE, 1, 3);
circle(x, y, radius);
/* leg design */
/* hand motion */
delay(100);
/* image 5 */
cleardevice();
x++;
setlinestyle(SOLID_LINE, 1, 3);
circle(x, y, radius);
/* leg design */
/* hand motion */
delay(150);
x++;
getch();
closegraph();
return 0;
Solar system
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <math.h>
void planetMotion(int xrad, int yrad, int midx, int midy, int x[60], int y[60]) {
int i, j = 0;
return;
}
int main() {
err = graphresult();
if (err != grOk) {
/* error occurred */
grapherrormsg(err));
return 0;
midx = getmaxx() / 2;
midy = getmaxy() / 2;
planet[0] = 7;
pos[i] = i * 6;
while (!kbhit()) {
/* drawing 9 orbits */
setcolor(WHITE);
setcolor(YELLOW);
setfillstyle(SOLID_FILL, YELLOW);
setcolor(CYAN);
setfillstyle(SOLID_FILL, CYAN);
setcolor(GREEN);
setfillstyle(SOLID_FILL, GREEN);
setcolor(BLUE);
setfillstyle(SOLID_FILL, BLUE);
setfillstyle(SOLID_FILL, RED);
setcolor(BROWN);
setfillstyle(SOLID_FILL, BROWN);
setcolor(LIGHTGRAY);
setfillstyle(SOLID_FILL, LIGHTGRAY);
setcolor(BROWN);
setfillstyle(SOLID_FILL, BROWN);
setcolor(LIGHTBLUE);
setfillstyle(SOLID_FILL, LIGHTBLUE);
setfillstyle(SOLID_FILL, LIGHTRED);
if (pos[i] <= 0) {
pos[i] = 59;
} else {
pos[i] = pos[i] - 1;
delay(100);
cleardevice();
closegraph();
return 0;
}
Indian flag
#include<stdio.h>
#include<graphics.h>
#include<math.h>
int main()
int gd,gm;
int r,i,a,b,x,y;
float PI=3.14;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
setcolor(RED);
rectangle(100,100,450,150);
setfillstyle(SOLID_FILL,RED);
floodfill(101,101,RED);
setcolor(WHITE);
rectangle(100,150,450,200);
setfillstyle(SOLID_FILL,WHITE);
floodfill(101,151,WHITE);
//draw the bottom rectangle and color it
setcolor(GREEN);
rectangle(100,200,450,250);
setfillstyle(SOLID_FILL,GREEN);
floodfill(101,201,GREEN);
a=275; //center
b=175; //center
r=25; //radius
setcolor(BLUE);
circle(a,b,r);
//spokes
for(i=0;i<=360;i=i+15)
x=r*cos(i*PI/180);
y=r*sin(i*PI/180);
line(a,b,a+x,b-y);
getch();
closegraph();
return 0;
}
3d projection
#include<stdio.h>
#include<math.h>
#include<graphics.h>
#include<conio.h>
main()
int x1,y1,x2,y2,gd,gm;
int ymax,a[4][8];
float par[4][4],b[4][8];
int i,j,k,m,n,p;
detectgraph(&gd,&gm);
initgraph(&gd,&gm, "c:\\tc\\bgi");
ymax = getmaxy();
for(j=0;j<3;j++)
line( x1,ymax-y1,x2,ymax-y2);
}
setcolor(11);
for(j=4;j<7;j++)
setcolor(7);
for(i=0;i<4;i++)
getch(); getch();