Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

1. write a program to rotate an image.

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int i=0,j=0,x0,y0,maxx,maxy,x[10],y[10],x1[10],y1[10],r;
char q[10],w[10];
initgraph(&gd,&gm," ");
cout<<"enter the vertex of triangle\n";
for(i=1;i<=3;i++)
{
cout<<"vertex"<<i<<"\n";
cin>>x[i]>>y[i];
x1[i]=x[i];
y1[i]=y[i];
}
cout<<"enter the rotation value:\n";
cin>>r;
cleardevice();
maxx=getmaxx();
maxy=getmaxy();
line(50,8,50,maxy-30);
outtextxy(10,15,"y");
line(50,maxy-30,maxx-50,maxy-30);
outtextxy(600,460,"x");
for(i=30;i<=570;i+=30)
{
printf(q,"%2d",j);
outtextxy(50+j,450,q);
outtextxy(25,450-j,q);
}
line(50+x1[1],y1[1],50+x1[2],y1[2]);
line(50+x1[2],y1[2],50+x1[3],y1[3]);
line(50+x1[3],y1[3],50+x1[1],y1[1]);
for(i=0;i<15;i++)
{
x1[1]+=2*r;
y1[1]+=r;
x1[2]+=r;
delay(100);
}
setcolor(RED);
line(50+x1[1],y1[1],50+x1[2],y1[2]);
line(50+x1[2],y1[2],50+x1[3],y1[3]);
line(50+x1[3],y1[3],50+x1[1],y1[1]);
getch();
closegraph();
}
Output 40 40 160 40 40 180 5

2. write a program to drop each word of a sentence one by one from the top.
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<string.h>
#include<dos.h>
#include<stdio.h>
void main()
{
char n[5];
int i,j,l,y=20;
int gd=DETECT,gm;
clrscr();
cout<<"SENTENCE FORMAT\n";
cout<<" ********\n";
cout<<"Enter the sentence:\n";
gets(n);
initgraph(&gd,&gm," ");
setbkcolor(RED);
gotoxy(20,3);
cout<<"SENTENCE FORMAT\n";
cout<<"\n\n\n\n\t\t";
l=strlen(n);
puts(n);
setcolor(14);
line(5,320,700,320);
sleep(1);
for(i=0;i<l;i++)
{
gotoxy(i+2,y);
cout<<n[i];
delay(50);
getch();
}
closegraph();
}
3. .write a program to drop a line using DDA Algorithm.

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int i,j,x1,y1,x2,y2;
float dx,dy,steps,xin,yin,x,y;
initgraph(&gd,&gm," ");
cout<<"Enter the x1,y1,x2,y2 :\n";
cin>>x1>>y1>>x2>>y2;
cleardevice();
x1=x1+50;
y1=450-y1;
x2=x2+50;
y2=450-y2;
int maxx=getmaxx();
int maxy=getmaxy();
line(50,8,50,maxy-30);
outtextxy(10,15,"y");
line(50,maxy-30,maxx-30,maxy-30);
outtextxy(600,460,"x");
char g[10];
for(i=30;j<=550;i+=30,j+=30)
{
sprintf(g,"%2d",j);
outtextxy(50+j,450,g);
outtextxy(25,450-j,g);
}
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xin=dx/steps;
yin=dy/steps;
x=x1;
y=y1;
for(i=0;i<steps;i++)
{
putpixel(x,y,WHITE);
x+=xin;
y+=yin;
}
getch();
closegraph();
}

4. write a program to move a car with sound effect.


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
void *buf;
float copyput;
unsigned s;
void image();
class animation
{
private:
int i;
public:
void image();
void animate(void *buf,float copyput);
};
void animation::image()
{
moveto(50,100);
lineto(100,100);
lineto(130,70);
lineto(180,70);
lineto(210,100);
lineto(270,120);
lineto(260,130);
lineto(230,130);
moveto(190,130);
lineto(190,130);
lineto(120,130);
moveto(80,130);
lineto(50,130);
lineto(50,100);
circle(210,130,15);
circle(100,130,15);
}
void animation::animate(void *buf,float copyput)
{
for(i=0;i<=900;i++)
{
outtextxy(200,30,"CAR MOVING");
putimage(i,150,buf,copyput);
}
}
int main()
{
int i,gd=DETECT,gm;
animation a;
initgraph(&gd,&gm," ");
setbkcolor(0);
settextstyle(7,0,2);
a.image();
s=imagesize(10,60,270,160);
buf=malloc(s);
getimage(10,60,270,160,buf);
cleardevice();
a.animate(buf,copyput);
getch();
closegraph();
return(0);
}

5. write a program to bounce a ball an move it with sound effect.


#include<dos.h>
#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"e:1%<<bg:");
float x=1,y=0.000,j=7,count=-1;
float r=15;
setcolor(10);
line(0,215,650,215);
sleep(1);
for(int k=0;k<=7;k++)
{
for(float i=90;i<=270;i+=10)
{
y=cos((i*15/7)/180)/j;
if(y>0)
y=-y;
x+=10;
setcolor(14);
setfillstyle(1,17);
circle(x,y*100+200,r);
floodfill(x,y*100+200,14);
delay(100);
setcolor(0);
setfillstyle(1,0);
circle(x,y*100+200,r);
floodfill(x,y*100+200,0);
}
j+=count;
count+=1;
}
getch();
closegraph();
}

6. write a program to test whether a given pixel is inside or outside or on a polygon.

#include<iostream.h>
#include<dos.h>
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int i,j,x,y,maxx,maxy;
char q[10];
initgraph(&gd,&gm," ");
cout<<"Enter the pixel position:\n";
cin>>x>>y;
cleardevice();
circle(x,y,3);
maxx=getmaxx();
maxy=getmaxy();
line(50,10,50,maxy-30);
outtextxy(10,15,"y");
line(50,maxy-30,maxx-50,maxy-30);
outtextxy(600,460,"x");
for(i=30;j<570;i+=30,j+=30)
{
sprintf(q,"%2d",j);
outtextxy(50+j,450,q);
outtextxy(25,450-j,q);
}
line(120,200,120,320);
line(120,200,200,200);
line(120,320,200,320);
line(200,200,260,260);
line(200,320,260,260);
if((x>100)&&(x<120)&&(y>200)&&(y<240))
{
cout<<"Pixel is outside the polygon";
}
else
{
if((x>120)&&(x<260)&&(y>210)&&(y<320))
{
cout<<"Pixel is inside the polygon";
}
else
{
cout<<"Pixel is on the polygon";
}
getch();
closegraph();
}
}

Output
Outside : 300 280
Inside : 160 240
On : 120 240

You might also like