Vous êtes sur la page 1sur 39

NAME WRITING

#include <stdio.h>

#include <conio.h>

#include<dos.h>

int a;

void main ()

{ clrscr();

for(a=1; a<2; a++)

gotoxy(a,13);

delay(200);

textcolor(a);

cprintf("ANURAG");

for(a=2; a>1 ;a--)

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");

/* get mid positions in x and y-axis */


x = getmaxx()/2;
y = 30;

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);

/* delay for 50 milli seconds */


delay(50);
/* clears screen */
cleardevice();
if(flag){
y = y + 5;
} else {
y = y - 5;
}
}

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>

void reset (int h[][2])

int val[9][2] = {

{ 50, 50 },{ 75, 50 },{ 75, 75 },{ 100, 75 },

{ 100, 50 },{ 125, 50 },{ 125, 100 },{ 87, 125 },{ 50, 100 }

};

int i;

for (i=0; i<9; i++)

h[i][0] = val[i][0]-50;

h[i][1] = val[i][1]-50;

void draw (int h[][2])

int i;
setlinestyle (DOTTED_LINE, 0, 1);

line (320, 0, 320, 480);

line (0, 240, 640, 240);

setlinestyle (SOLID_LINE, 0, 1);

for (i=0; i<8; i++)

line (320+h[i][0], 240-h[i][1], 320+h[i+1][0], 240-h[i+1][1]);

line (320+h[0][0], 240-h[0][1], 320+h[8][0], 240-h[8][1]);

void rotate (int h[][2], float angle)

int i;

for (i=0; i<9; i++)

int xnew, ynew;

xnew = h[i][0] * cos (angle) - h[i][1] * sin (angle);

ynew = h[i][0] * sin (angle) + h[i][1] * cos (angle);

h[i][0] = xnew; h[i][1] = ynew;

void scale (int h[][2], int sx, int sy)

int i;

for (i=0; i<9; i++)

h[i][0] *= sx;
h[i][1] *= sy;

void translate (int h[][2], int dx, int dy)

int i;

for (i=0; i<9; i++)

h[i][0] += dx;

h[i][1] += dy;

void reflect (int h[][2], int m, int c)

int i;

float angle;

for (i=0; i<9; i++)

h[i][1] -= c;

angle = M_PI/2 - atan (m);

rotate (h, angle);

for (i=0; i<9; i++)

h[i][0] = -h[i][0];

angle = -angle;

rotate (h, angle);

for (i=0; i<9; i++)


h[i][1] += c;

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("1. Scaling about the origin.\n");

printf("2. Scaling about an arbitrary point.\n");

printf("3. Reflection about the line y = mx + c.\n");

printf("4. Exit\n");

printf("Enter the choice: ");


scanf("%d",&choice);

switch(choice)

case 1: printf ("Enter the x- and y-scaling factors: ");

scanf ("%d%d", &sx, &sy);

ini();

reset (h);

draw (h);getch();

scale (h, sx, sy);

cleardevice();

draw (h);

dini();

break;

case 2: printf ("Enter the x- and y-scaling factors: ");

scanf ("%d%d", &sx, &sy);

printf ("Enter the x- and y-coordinates of the point: ");

scanf ("%d%d", &x, &y);

ini();

reset (h);

translate (h, x, y);// Go to arbitrary point

draw(h); getch();//Show its arbitrary position

cleardevice();

translate(h,-x,-y);//Take it back to origin

draw(h);
getch();

cleardevice();

scale (h, sx, sy);//Now Scale it

draw(h);

getch();

translate (h, x, y);//Back to Arbitrary point

cleardevice();

draw (h);

putpixel (320+x, 240-y, WHITE);

dini();

break;

case 3: printf ("Enter the values of m and c: ");

scanf ("%d%d", &m, &c);

ini();

reset (h);

draw (h); getch();

reflect (h, m, c);

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");

outtextxy(500,10,"press any key...");

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() {

/* request auto detection */

int gdriver = DETECT, gmode, err;

int i, j, k, x, y, color;

char str[64];

/* initialize graphic mode */

initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");

err = graphresult();

if (err != grOk) {

/* error occurred */

printf("Graphics Error: %s\n",

grapherrormsg(err));

return 0;

for (i = 0; i < 3; i++) {

/* clears graphic screen */

cleardevice();

/* draw the signal post */

setcolor(DARKGRAY);

setfillstyle(SOLID_FILL, DARKGRAY);
rectangle(50, 45, 150, 300);

rectangle(90, 300, 110, getmaxy());

floodfill(55, 55, DARKGRAY);

floodfill(91, 301, DARKGRAY);

/* make place for signals */

setcolor(BLACK);

setfillstyle(SOLID_FILL, BLACK);

circle(100, 90, 30);

floodfill(100, 90, BLACK);

circle(100, 170, 30);

floodfill(100, 170, BLACK);

circle(100, 250, 30);

floodfill(100, 250, BLACK);

x = 150 + (getmaxx() - 150) / 2;

y = 125;

moveto(x, y);

settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4);

settextjustify(CENTER_TEXT, CENTER_TEXT);

/* signal for stop */

if (i == 0) {

setcolor(LIGHTRED);

outtext("STOP");

color = LIGHTRED;
y = 90;

} else if (i == 1) {

/* yellow signal - to get ready */

setcolor(YELLOW);

outtext("READY");

color = YELLOW;

y = 170;

} else {

/* green signal - to start */

setcolor(GREEN);

outtext("START");

color = GREEN;

y = 250;

x = 100;

/* for red & green timer is 10 seconds */

if (color != YELLOW) {

k = 10;

} else {

/* timer is 5 sec for yellow signal */

k = 5;

}
for (j = k; j > 0; j--) {

/* clear the signal-to rewrite timer */

setcolor(BLACK);

setfillstyle(SOLID_FILL, BLACK);

circle(x, y, 30);

floodfill(x, y + 25, BLACK);

/* turn on the given signal(color) */

setcolor(color);

setfillstyle(SOLID_FILL, color);

circle(x, y, 30);

floodfill(x, y + 25, color);

/* print the counter inside signal */

setcolor(BLACK);

settextstyle(TRIPLEX_FONT, HORIZ_DIR, 3);

sprintf(str, "%d", j);

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() {

/* request auto detection */

int gdriver = DETECT, gmode, err;

int radius = 10, x, y, midy;

/* initialize graphic mode */

initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");

err = graphresult();

if (err != grOk) {

/* error occurred */
printf("Graphics Error: %s\n",

grapherrormsg(err));

return 0;

x = 50;

midy = getmaxy() / 2;

y = midy - 100;

/*

* used 5 stick man (still/image)

* position to get walking animation

*/

while (x < getmaxx() - 25) {

/* clears graphic screen */

cleardevice();

setlinestyle(SOLID_LINE, 1, 3);

/* road for stick man */

line(0, midy, getmaxx(), midy);

/* image 1 - first position of stick man */

circle(x, y, radius);

line(x, y + radius, x, y + radius + 50);


/* leg design */

line(x, y + radius + 50, x - 10, midy);

line(x, y + radius + 50, x + 10, midy - 30);

line(x + 10, midy - 30, x + 10, midy);

/* hand motion */

line(x, y + radius + 10, x - 15, y + radius + 30);

line(x - 15, y + radius + 30, x + 15, y + radius + 40);

delay(150);

/* image 2 - second position of stick man */

cleardevice();

/* forwarding the position of stick man */

x++;

setlinestyle(SOLID_LINE, 1, 3);

line(0, midy, getmaxx(), midy);

circle(x, y, radius);

line(x, y + radius, x, y + radius + 50);

/* leg design */

line(x, y + radius + 50, x - 15, midy);

line(x, y + radius + 50, x + 10, midy - 30);

line(x + 10, midy - 30, x + 10, midy);


/* hand motion */

line(x, y + radius + 5, x - 10, y + radius + 20);

line(x - 10, y + radius + 20, x - 10, y + radius + 45);

line(x, y + radius + 5, x + 5, y + radius + 25);

line(x + 5, y + radius + 25, x + 15, y + radius + 45);

delay(100);

/* image 3 */

cleardevice();

setlinestyle(SOLID_LINE, 1, 3);

line(0, midy, getmaxx(), midy);

x++;

circle(x, y, radius);

line(x, y + radius, x, y + radius + 50);

/* leg design */

line(x, y + radius + 50, x - 20, midy);

line(x, y + radius + 50, x + 20, midy);

/* hand motion */

line(x, y + radius + 5, x - 20, y + radius + 20);

line(x - 20, y + radius + 20, x - 20, y + radius + 30);

line(x, y + radius + 5, x + 20, y + radius + 25);

line(x + 20, y + radius + 25, x + 30, y + radius + 30);


delay(150);

/* image 4 */

cleardevice();

x++;

setlinestyle(SOLID_LINE, 1, 3);

line(0, midy, getmaxx(), midy);

circle(x, y, radius);

line(x, y + radius, x, y + radius + 50);

/* leg design */

line(x, y + radius + 50, x - 8, midy - 30);

line(x - 8, midy - 30, x - 25, midy);

line(x, y + radius + 50, x + 10, midy - 30);

line(x + 10, midy - 30, x + 12, midy);

/* hand motion */

line(x, y + radius + 5, x - 10, y + radius + 10);

line(x - 10, y + radius + 10, x - 10, y + radius + 30);

line(x, y + radius + 5, x + 15, y + radius + 20);

line(x + 15, y + radius + 20, x + 30, y + radius + 20);

delay(100);

/* image 5 */

cleardevice();
x++;

setlinestyle(SOLID_LINE, 1, 3);

line(0, midy, getmaxx(), midy);

circle(x, y, radius);

line(x, y + radius, x, y + radius + 50);

/* leg design */

line(x, y + radius + 50, x + 3, midy);

line(x, y + radius + 50, x + 8, midy - 30);

line(x + 8, midy - 30, x - 20, midy);

/* hand motion */

line(x, y + radius + 5, x - 15, y + radius + 10);

line(x - 15, y + radius + 10, x - 8, y + radius + 25);

line(x, y + radius + 5, x + 15, y + radius + 20);

line(x + 15, y + radius + 20, x + 30, y + radius + 20);

delay(150);

x++;

getch();

/* deallocate memory allocated for graphic screen */

closegraph();
return 0;

Solar system

#include <stdio.h>

#include <conio.h>

#include <graphics.h>

#include <dos.h>

#include <math.h>

/* manipulates the position of planets on the orbit */

void planetMotion(int xrad, int yrad, int midx, int midy, int x[60], int y[60]) {

int i, j = 0;

/* positions of planets in their corresponding orbits */

for (i = 360; i > 0; i = i - 6) {

x[j] = midx - (xrad * cos((i * 3.14) / 180));

y[j++] = midy - (yrad * sin((i * 3.14) / 180));

return;

}
int main() {

/* request auto detection */

int gdriver = DETECT, gmode, err;

int i = 0, midx, midy;

int xrad[9], yrad[9], x[9][60], y[9][60];

int pos[9], planet[9], tmp;

/* initialize graphic mode */

initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");

err = graphresult();

if (err != grOk) {

/* error occurred */

printf("Graphics Error: %s",

grapherrormsg(err));

return 0;

/* mid positions at x and y-axis */

midx = getmaxx() / 2;

midy = getmaxy() / 2;

/* manipulating radius of all 9 planets */

planet[0] = 7;

for (i = 1; i < 9; i++) {


planet[i] = planet[i - 1] + 1;

/* offset position for the planets on their corresponding orbit */

for (i = 0; i < 9; i++) {

pos[i] = i * 6;

/* orbits for all 9 planets */

xrad[0] = 60, yrad[0] = 30;

for (i = 1; i < 9; i++) {

xrad[i] = xrad[i - 1] + 30;

yrad[i] = yrad[i - 1] + 15;

/* positions of planets on their corresponding orbits */

for (i = 0; i < 9; i++) {

planetMotion(xrad[i], yrad[i], midx, midy, x[i], y[i]);

while (!kbhit()) {

/* drawing 9 orbits */

setcolor(WHITE);

for (i = 0; i < 9; i++) {

ellipse(midx, midy, 0, 360, xrad[i], yrad[i]);


}

/* sun at the mid of the solar system */

setcolor(YELLOW);

setfillstyle(SOLID_FILL, YELLOW);

circle(midx, midy, 20);

floodfill(midx, midy, YELLOW);

/* mercury in first orbit */

setcolor(CYAN);

setfillstyle(SOLID_FILL, CYAN);

pieslice(x[0][pos[0]], y[0][pos[0]], 0, 360, planet[0]);

/* venus in second orbit */

setcolor(GREEN);

setfillstyle(SOLID_FILL, GREEN);

pieslice(x[1][pos[1]], y[1][pos[1]], 0, 360, planet[1]);

/* earth in third orbit */

setcolor(BLUE);

setfillstyle(SOLID_FILL, BLUE);

pieslice(x[2][pos[2]], y[2][pos[2]], 0, 360, planet[2]);

/* mars in fourth orbit */


setcolor(RED);

setfillstyle(SOLID_FILL, RED);

pieslice(x[3][pos[3]], y[3][pos[3]], 0, 360, planet[3]);

/* jupiter in fifth orbit */

setcolor(BROWN);

setfillstyle(SOLID_FILL, BROWN);

pieslice(x[4][pos[4]], y[4][pos[4]], 0, 360, planet[4]);

/* saturn in sixth orbit */

setcolor(LIGHTGRAY);

setfillstyle(SOLID_FILL, LIGHTGRAY);

pieslice(x[5][pos[5]], y[5][pos[5]], 0, 360, planet[5]);

/* uranus in sevth orbit */

setcolor(BROWN);

setfillstyle(SOLID_FILL, BROWN);

pieslice(x[6][pos[6]], y[6][pos[6]], 0, 360, planet[6]);

/* neptune in eigth orbit */

setcolor(LIGHTBLUE);

setfillstyle(SOLID_FILL, LIGHTBLUE);

pieslice(x[7][pos[7]], y[7][pos[7]], 0, 360, planet[7]);

/* pluto in ninth orbit */


setcolor(LIGHTRED);

setfillstyle(SOLID_FILL, LIGHTRED);

pieslice(x[8][pos[8]], y[8][pos[8]], 0, 360, planet[8]);

/* checking for one complete rotation */

for (i = 0; i < 9; i++) {

if (pos[i] <= 0) {

pos[i] = 59;

} else {

pos[i] = pos[i] - 1;

/* sleep for 100 milliseconds */

delay(100);

/* clears graphic screen */

cleardevice();

/* deallocate memory allocated for graphic screen */

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");

//draw the top rectangle and color it

setcolor(RED);

rectangle(100,100,450,150);

setfillstyle(SOLID_FILL,RED);

floodfill(101,101,RED);

//draw the middle rectangle and color it

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);

//draw the circle

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;

int xp, yp, zp, x, y, z;

a[0][0] = 100; a[1][0] = 100; a[2][0] = -100;

a[0][1] = 200; a[1][1] = 100; a[2][1] = -100;

a[0][2] = 200; a[1][2] = 200; a[2][2] = -100;

a[0][3] = 100; a[1][3] = 200; a[2][3] = -100;

a[0][4] = 100; a[1][4] = 100; a[2][4] = -200;

a[0][5] = 200; a[1][5] = 100; a[2][5] = -200;


a[0][6] = 200; a[1][6] = 200; a[2][6] = -200;

a[0][7] = 100; a[1][7] = 200; a[2][7] = -200;

detectgraph(&gd,&gm);

initgraph(&gd,&gm, "c:\\tc\\bgi");

ymax = getmaxy();

xp = 300; yp = 320; zp = 100;

for(j=0; j<8; j++)

x = a[0][j]; y = a[1][j]; z = a[2][j];

b[0][j] = xp - ( (float)( x - xp )/(z - zp)) * (zp);

b[1][j] = yp - ( (float)( y - yp )/(z - zp)) * (zp);

/*- front plane display -*/

for(j=0;j<3;j++)

x1=(int) b[0][j]; y1=(int) b[1][j];

x2=(int) b[0][j+1]; y2=(int) b[1][j+1];

line( x1,ymax-y1,x2,ymax-y2);
}

x1=(int) b[0][3]; y1=(int) b[1][3];

x2=(int) b[0][0]; y2=(int) b[1][0];

line( x1, ymax-y1, x2, ymax-y2);

/*- back plane display -*/

setcolor(11);

for(j=4;j<7;j++)

x1=(int) b[0][j]; y1=(int) b[1][j];

x2=(int) b[0][j+1]; y2=(int) b[1][j+1];

line( x1, ymax-y1, x2, ymax-y2);

x1=(int) b[0][7]; y1=(int) b[1][7];

x2=(int) b[0][4]; y2=(int) b[1][4];

line( x1, ymax-y1, x2, ymax-y2);

setcolor(7);

for(i=0;i<4;i++)

x1=(int) b[0][i]; y1=(int) b[1][i];

x2=(int) b[0][4+i]; y2=(int) b[1][4+i];

line( x1, ymax-y1, x2, ymax-y2);


}

getch(); getch();

Vous aimerez peut-être aussi