Thursday, 23 January 2014

// // Leave a Comment

Programe of CG for moving object

Computer Graphics is very interesting subject.Computer Graphics is one of the subject in Engineering.The term"Computer Graphics"is a combination of two things:that is Graphic and Computer. Means that we can create the graphics using the programming language.

Here the simple "C" program of moving one object.
That object is moving Diagonally.

CG PROGRAMME FOR MOVING OBJECT:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{

int gdriver = DETECT, gmode, errorcode;
int midx, midy,a=25,b=30,c=70,d=50,e=70;
int radius = 50,i;


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

/*here in last argument is your"BGI" directory path*/


errorcode = graphresult();
if (errorcode != grOk)  /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}

midx = 50;
midy = 50;
setcolor(YELLOW); //Use any colors which are availables in library

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

circle(midx,midy, radius); //draw a circle
circle(midx,midy,5);
putpixel(a,b,YELLOW);     //display the pixels
putpixel(c,b,YELLOW);
arc(d,e,180,360,20);     //draw an arc
midx=midx+1;
midy=midy+1;
a=a+1;
b=b+1;
c=c+1;
d=d+1;
e=e+1;                 //suspend the execution
delay(10);
cleardevice();

}

/* clean up */
closegraph();
return 0;
}


SUJJESTION:-
Your program is only run if and only if you save your program in your "BGI" directory

0 comments:

Post a Comment