C++ program to show animated dancing dolls in graphics

#include<dos.h>
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
class doll
{
     public:
void dolldraw(int x)
{
int y=100;
circle(x,y+10,10);
line(x,y+20,x,y+100);
line(x,y+40,x-20,y+70);
line(x,y+40,x+20,y+70);
line(x,y+100,x-20,y+120);
line(x,y+100,x+20,y+120);
}
void dollmoll(int x)
{
int y=100;
circle(x,y+10,10);
line(x,y+20,x,y+100);
line(x,y+50,x-20,y+30);
line(x,y+50,x+20,y+30);
line(x,y+100,x-20,y+90);
line(x,y+100,x+20,y+90);
}

};
void main()
{
doll a,b,c,d,e;
int h,i,j,k;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
int w=50;
while(!kbhit())
{
a.dolldraw(w);
h=w+45;
b.dolldraw(h);
j=h+45;
c.dolldraw(j);
i=j+45;
d.dolldraw(i);
k=i+45;
e.dolldraw(k);
delay(500);
cleardevice();
w=150;
a.dollmoll(w);
b.dollmoll(h);
c.dollmoll(i);
d.dollmoll(j);
e.dollmoll(k);
delay(500);
cleardevice();
}
getch();
closegraph();
}


Read More

C++ Program to show animated pendulum clock in graphics

#include<math.h>
#include<process.h>
#include<dos.h>
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
int x1=300,y1=180,x,y;
void display(double i)
{
circle(300,130,50);
line(210,60,210,320);
line(210,60,390,60);
line(390,60,390,320);
line(210,320,390,320);
outtextxy(295,88,"12");
outtextxy(260,130,"9");
outtextxy(340,130,"3");
outtextxy(295,168,"6");
line(300,130,300,98);
line(300,98,297,101);
line(300,98,303,101);
line(337,130,300,130);
line(337,130,334,127);
line(337,130,334,133);
x=x1+95*cos(i);
y=y1+95*sin(i);
line(x1,y1,x,y);
circle(x,y,10);
delay(30);
clearviewport();
}

void main()
{
int gd=DETECT,gm;
double i;
initgraph(&gd,&gm,"C:\\Tc\\BGI");
while(!kbhit())
{
for(i=2;i>1;i=i-0.01)
display(i);
for(i=1;i<2;i=i+0.01)
display(i);
}
getch();
}
Read More

C++ Program to show animated bouncing ball

Program 
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
clrscr();
int gd=0,gm,x=20,flag=0,y=200,uplimit=250;
initgraph(&gd,&gm,"C:\\Tc\\BGI");
while(!kbhit())
{
setcolor(4);
line(0,400,679,400);
if(flag==0)
{
y+=2;
x+=1;
if(y>=385)
flag=1;
}
if(flag==1)
{
y-=2;
x+=1;
if(y<=uplimit)
{
flag=0;
uplimit+=20;

}
}

setcolor(15);
fillellipse(x,y,15,15);
delay(15);
setcolor(0);
setfillstyle(1,10);
fillellipse(x,y,15,15);
cleardevice();
}

getch();
}
Read More

C++ program to show animated traffic signal (Simple graphics)

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
clrscr();
int gd=0,gm;
initgraph(&gd,&gm,"C:\\Tc\\BGI");
rectangle(250,50,350,350);
circle(300,100,50);
circle(300,200,50);
circle(300,300,50);
line(80,80,80,500);
line(80,80,250,80);

while(!kbhit())
{
int x=100;
setfillstyle(1,RED);
floodfill(x+200,100,WHITE);
delay(500);
setfillstyle(1,BLACK);
floodfill(x+200,100,WHITE);
setfillstyle(1,YELLOW);
floodfill(x+200,200,WHITE);
delay(500);
setfillstyle(1,BLACK);
floodfill(x+200,200,WHITE);
setfillstyle(1,GREEN);
floodfill(x+200,300,WHITE);
delay(300);
setfillstyle(1,BLACK);
floodfill(x+200,300,WHITE);
}

getch();
closegraph();
}

Read More

C++ Program to draw a moving jeep (Simple Graphics)


Program

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<stdlib.h>
#include<process.h>
void main()
{
clrscr();
int gd=DETECT,gm;
int x=320;
initgraph(&gd,&gm,"C:\\TC\\BGI");
while(!kbhit())
{
setcolor(RED);
line(x,200,x,290);
line(x,290,x+280,290);
line(x+280,290,x+280,100);
line(x+280,100,x+110,100);
line(x+110,100,x+85,200);
line(x+85,200,x,200);
rectangle(x+250,120,x+200,170);
setcolor(3);
circle(x+60,290,30);
circle(x+210,290,30);
delay(50);
cleardevice();
x=x-3;
}
getch();
closegraph();
}

Read More

C++ program to implement shearing in graphics

A shear is a transformation that distorts the shape of an object along either or both of the axies. Like scale and translate, a shear can be done along just one or along both of the coordinate axes. A shear along one axis (say, the x-axis) is performed in terms of the point's coordinate in the other axis (the y-axis). Thus a shear of 1 in the x-axis will cause the x-coodinate of the point ot distort by 1*(y-coordinate). 

Read More

C++ Program to implement reflection in graphics

Reflection in computer graphics is used to emulate reflective objects like mirrors and shiny surfaces.
Reflection is accomplished in a ray trace renderer by following a ray from the eye to the mirror and then calculating where it bounces from, and continuing the process until no surface is found, or a non-reflective surface is found. Reflection on a shiny surface like wood or tile can add to the photorealistic effects of a 3D rendering.

Read More