/* C PROGRAM TO DEMONSTRATE TRAFFIC SIGNALS */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR */
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
main() {
int gd = DETECT, gm, midx, midy;
initgraph( & gd, & gm, "C:/TC/BGI");
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(RED);
settextstyle(SCRIPT_FONT, HORIZ_DIR, 3);
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(midx, midy - 10, "Traffic Light Simulation");
outtextxy(midx, midy + 10, "Press any key to start");
getch();
cleardevice();
setcolor(WHITE);
settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
circle(midx, midy - 50, 22);
setfillstyle(SOLID_FILL, RED);
floodfill(midx, midy - 50, WHITE);
setcolor(BLUE);
outtextxy(midx, midy - 50, "STOP");
delay(2000);
graphdefaults();
cleardevice();
setcolor(WHITE);
rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
circle(midx, midy, 20);
setfillstyle(SOLID_FILL, YELLOW);
floodfill(midx, midy, WHITE);
setcolor(BLUE);
outtextxy(midx - 18, midy - 3, "READY");
delay(2000);
cleardevice();
setcolor(WHITE);
rectangle(midx - 30, midy - 80, midx + 30, midy + 80);
circle(midx, midy + 50, 22);
setfillstyle(SOLID_FILL, GREEN);
floodfill(midx, midy + 50, WHITE);
setcolor(BLUE);
outtextxy(midx - 7, midy + 48, "GO");
setcolor(RED);
settextstyle(SCRIPT_FONT, HORIZ_DIR, 4);
outtextxy(midx - 150, midy + 100, "Press any key to exit...");
getch();
closegraph();
return 0;
}
Amazon banner
Showing posts with label graphics. Show all posts
Showing posts with label graphics. Show all posts
Thursday, 30 August 2012
C PROGRAM TO DEMONSTRATE TRAFFIC SIGNALS
C PROGRAM TO DESIGN A MOVING WHEEL
/* C PROGRAM TO DESIGN A MOVING WHEEL */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR */
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<dos.h>
int xc = 50, yc = 200, r = 35;
int x[15], y[15];
void drawcircles() {
setcolor(YELLOW);
circle(xc, yc, r);
circle(xc, yc, r + 5);
}
void main() {
double angle = 0, theta;
int i, a;
int gd = DETECT, gm;
initgraph( & gd, & gm, "C:\TC\BGI");
a = xc + r;
while (!kbhit()) {
while (a <= 630) {
theta = M_PI * angle / 180;
cleardevice();
drawcircles();
for (i = 0; i < 18; i++) {
theta = M_PI * angle / 180;
x[i] = xc + r * cos(theta);
y[i] = yc + r * sin(theta);
angle += 20;
line(xc, yc, x[i], y[i]);
}
angle += 2;
xc += 2;
a = xc + r;
delay(50);
}
xc = 50;
r = 35;
a = xc + r;
}
getch();
closegraph();
}
C PROGRAM CREATE CIRCLES DESIGN
/* C PROGRAM CREATE CIRCLES DESIGN */
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<graphics.h>
#include<conio.h>
#include<dos.h>
main()
{
int gd = DETECT, gm, x, y, color, angle = 0;
struct arccoordstype a, b;
initgraph(&gd, &gm, "C:/TC/BGI");
delay(2000);
while(angle<=360)
{
setcolor(BLACK);
arc(getmaxx()/2,getmaxy()/2,angle,angle+2,100);
setcolor(RED);
getarccoords(&a);
circle(a.xstart,a.ystart,25);
setcolor(BLACK);
arc(getmaxx()/2,getmaxy()/2,angle,angle+2,150);
getarccoords(&a);
setcolor(GREEN);
circle(a.xstart,a.ystart,25);
angle = angle+5;
delay(50);
}
getch();
closegraph();
return 0;
}
C PROGRAM TO DEMONSTRATE BRICK GAME
/* C PROGRAM TO DEMONSTRATE BRICK GAME *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/
#include<stdio.h>#include<graphics.h>
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
int getkey();
void main()
{
int gd,gm;
gd=DETECT;
initgraph(&gd,&gm,"C:/TC/BGI");
cleardevice();
int ar,xc,yc,xr=0,yr=195,a=1,b=1,c=0,are;
void *bu,*buf;
int X=0,Y=0,s,area1;
void *buff1;
rectangle(0,0,50,25);
setfillstyle(6,6);
floodfill(2,2,15);
ar=imagesize(0,0,50,25);
bu=malloc(ar);
getimage(0,0,50,25,bu);
putimage(0,0,bu,XOR_PUT);
rectangle(0,0,50,25);
setfillstyle(6,8);
floodfill(2,2,15);
are=imagesize(0,0,50,25);
buf=malloc(are);
getimage(0,0,50,25,buf);
putimage(0,0,buf,XOR_PUT);
for(int j=0;j<180;j+=27)
for(int i=0;i<600;i+=52)
putimage(0+i,27+j,bu,XOR_PUT);
putimage(0,27,bu,XOR_PUT);
putimage(572,27,bu,XOR_PUT);
putimage(0,27,buf,XOR_PUT);
putimage(572,27,buf,XOR_PUT);
setcolor(3);
rectangle(80,445,159,452);
setfillstyle(1,1);
floodfill(82,447,3);
area1=imagesize(80,445,159,452);
buff1=malloc(area1);
getimage(80,445,159,452,buff1);
setcolor(4);
line(0,479,640,479);
int area,x=325,y=325,ch,xdirn=-1,ydirn=-1,step;
int maxx,maxy;
void *buff;
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED);
circle(350,350,5);
floodfill(350,350,WHITE);
area=imagesize(345,345,355,355);
buff=malloc(area);
getimage(345,345,355,355,buff);
putimage(345,345,buff,XOR_PUT);
while (1)
{
putimage(x, y, buff, XOR_PUT);
delay(15);
putimage(x, y, buff, XOR_PUT);
x=x+(xdirn*2);
y=y+(ydirn*3);
if ( x + 10 - 1 > 640 )
{
xdirn*=-1;
x = 640 - 10 + 1;
}
if (x < 0)
{
xdirn*=-1;
x = 0;
}
if ( y + 10 - 1 > 470 )
{
cleardevice();
outtextxy(200,200,"Sorry! You loose the game.");
outtextxy(250,240,"Try Again!!!");
gotoxy(30,8);
cout<<"Total Score : ";
delay(5000);
getch();
goto tt;
}
if(c==1020)
{
outtextxy(180,200,"Congrats! You have finished the game.");
gotoxy(30,8);
cout<<"Total Score : ";
delay(5000);
getch();
goto tt;
}
if ( getpixel(x,y)==1 )
{
sound(500);
delay(15);
nosound();
ydirn*=-1;
}
if (getpixel(x,y)==6)
{
sound(100);
delay(50);
nosound();
ydirn*=-1;
xc=x;
yc=y;
a=xc/52;
b=(yc/27);
xr=a*52;
yr=b*27;
putimage(xr,yr,bu,XOR_PUT);
c+=10;
}
if (getpixel(x,y)==8)
{
sound(800);
delay(200);
nosound();
ydirn*=-1;
xc=x;
yc=y;
a=xc/52;
b=(yc/27);
xr=a*52;
yr=b*27;
putimage(xr,yr,buf,XOR_PUT);
c+=100;
}
if( y < 0 )
{
ydirn*=-1;
y=0;
}
gotoxy(65,1);
cout<<"SCORE : ";
if(kbhit())
{
s=getkey();
if(s!=1)
{
if(X>480)
{
X=480;
putimage(160+X,445+Y,buff1,XOR_PUT);
}
if(X<-80)
{
X=-80;
putimage(80+X,445+Y,buff1,XOR_PUT);
}
putimage(80+X,445+Y,buff1,XOR_PUT);
if(s==75)
X+=-40;
if(s==77)
X+=40;
putimage(80+X,445+Y,buff1,XOR_PUT);
}
if(s==1)
{
tt: free(bu);
free(buff);
free(buff1);
closegraph();
exit(0);
}
}
}
free(bu);
free(buff);
free(buff1);
closegraph();
}
int getkey()
{
union REGS j,o;
j.h.ah=0;
int86(22,&j,&o);
return(o.h.ah);
}
C PROGRAM TO DEMONSTRATE A MOVING FISH
/* C PROGRAM TO DEMONSTRATE A MOVING FISH *//* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/#include<stdio.h>
#include<time.h>#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int x=10,y=200,x1=675,y1=380;
int stangle=35,endangle=140,radius=90;
initgraph(&gd,&gm,"C:/TC/BGI");
while(!kbhit())
{
cleardevice();
setbkcolor(BLACK);
if(x<640)
{
x+=5;
y+=1;
arc(x,y,stangle,endangle+35,radius);
arc(x,y-110,190,323,radius+2);
circle(x+40,y-60,5);
line(x-90,y-90,x-90,y-8);
}
else
{
x1-=5;
y1-=1;
arc(x1,y1,stangle-30,endangle+4,radius);
arc(x1,y1-110,217,350,radius+2);
circle(x1-40,y1-60,5);
line(x1+90,y1-90,x1+90,y1-10);
}
setcolor(YELLOW);
delay(90);
}
closegraph();
}
Friday, 17 August 2012
C PROGRAM TO DEMONSTRATE SHEARING TRANSFORMATION
/* C PROGRAM TO DEMONSTRATE SHEARING TRANSFORMATION*/
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main()
{
int poly[30],a[9][3],b[3][3],c[9][3],poly2[30];
int x=0,y=0,p,i,j,k,xc,yc,ch;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:/TC/BGI");
xc=getmaxx()/2;
yc=getmaxy()/2;
setcolor(1);
setbkcolor(15);
setfillstyle(6,3);
printf("\n Enter number of points : ");
scanf("%d",&p);
j=0;
for(i=0;i<p*2;i+=2)
{
printf("\n Enter cordinate point x%d and y%d : ",j+1,j+1);
scanf("%d",&poly[i]);
scanf("%d",&poly[i+1]);
j++;
}
poly[p*2]=poly[0];
poly[p*2+1]=poly[1];
for(i=0;i<p*2;i+=2)
{
poly2[i]=xc+poly[i];
poly2[i+1]=yc-poly[i+1];
}
poly2[p*2]=poly2[0];
poly2[p*2+1]=poly2[1];
fillpoly(p+1,poly2);
line(0,yc,xc*2,yc);
line(xc,0,xc,yc*2);
printf("\n Shearing of : \n 1. x \n 2. y \n 3. Both\n enter choice : ");
scanf("%d",&ch);
if(ch==1)
{
printf("\n Enter x shear value : ");
scanf("%d",&x);
}
if(ch==2)
{
printf("\n Enter y shear value : ");
scanf("%d",&y);
}
if(ch==3)
{
printf("\n Enter x shear value : ");
scanf("%d",&x);
printf("\n Enter y shear value : ");
scanf("%d",&y);
}
j=0;
for(i=0;i<p;i++)
{
a[i][0]=poly[j];
a[i][1]=poly[++j];
a[i][2]=1;
++j;
}
if(ch==1)
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=0;
if(i==j)
{
b[i][j]=1;
}
}
}
b[1][0]=x;
}
else if(ch==2)
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=0;
if(i==j)
{
b[i][j]=1;
}
}
}
b[0][1]=y;
}
else if(ch==3)
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=0;
if(i==j)
{
b[i][j]=1;
}
}
}
b[1][0]=x;
b[0][1]=y;
}
for(i=0;i<p;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\n\n\n\n\n\t After Shearing : ");
for(i=0,j=0;i<p;i++,j+=2)
{
poly[j] =xc+c[i][0];
poly[j+1]=yc-c[i][1];
}
poly[j] =poly[0];
poly[j+1]=poly[1];
setfillstyle(9,2);
fillpoly(p+1,poly);
getch();
closegraph();
}
Thursday, 16 August 2012
C PROGRAM TO DEMONSTRATE REFLECTION TRANSFORMATION ABOUT X-AXIS, Y-AXIS AND ORIGIN
/* C PROGRAM TO DEMONSTRATE REFLECTION TRANSFORMATION ABOUT X-AXIS, Y-AXIS AND ORIGIN*/
/* AUTHOR : DEEPAK MAHAKALE 3RD YEAR IT SRCOEM, NAGPUR*/#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
void main()
{
int poly[30],a[9][3],b[3][3],c[9][3],poly2[30];
int x,y,p,i,j,k,xc,yc;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"C:/TC/BGI");
xc=getmaxx()/2;
yc=getmaxy()/2;
setcolor(1);
setbkcolor(15);
setfillstyle(6,3);
printf("\n Enter number of points : ");
scanf("%d",&p);
j=0;
for(i=0;i<p*2;i+=2)
{
printf("\n Enter cordinate point x%d and y%d : ",j+1,j+1);
scanf("%d",&poly[i]);
scanf("%d",&poly[i+1]);
j++;
}
poly[p*2]=poly[0];
poly[p*2+1]=poly[1];
for(i=0;i<p*2;i+=2)
{
poly2[i]=xc+poly[i];
poly2[i+1]=yc-poly[i+1];
}
poly2[p*2]=poly2[0];
poly2[p*2+1]=poly2[1];
fillpoly(p+1,poly2);
line(0,yc,xc*2,yc);
line(xc,0,xc,yc*2);
printf("\n Reflection about : \n 1. x axis\n 2. y axis\n 3. origin\n enter choice : ");
scanf("%d",&x);
j=0;
for(i=0;i<p;i++)
{
a[i][0]=poly[j];
a[i][1]=poly[++j];
a[i][2]=1;
++j;
}
if(x==1)
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=0;
if(i==j)
{
b[i][j]=1;
}
}
}
b[1][1]=-1;
}
else if(x==2)
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=0;
if(i==j)
{
b[i][j]=1;
}
}
}
b[0][0]=-1;
}
else if(x==3)
{
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
b[i][j]=0;
if(i==j)
{
b[i][j]=-1;
}
}
}
b[2][2]=1;
}
for(i=0;i<p;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\n\n\n\n\n\t Reflection : ");
for(i=0,j=0;i<p;i++,j+=2)
{
poly[j] =xc+c[i][0];
poly[j+1]=yc-c[i][1];
}
poly[j] =poly[0];
poly[j+1]=poly[1];
setfillstyle(9,2);
fillpoly(p+1,poly);
getch();
closegraph();
}
Subscribe to:
Posts (Atom)


