Professional Documents
Culture Documents
Write A Program To Draw The Line Using Line Function.: Output
Write A Program To Draw The Line Using Line Function.: Output
Write A Program To Draw The Line Using Line Function.: Output
OUTPUT:-
{
int gd=DETECT,gm;
initgraph(&gm,&gd," ");
int x1,y1,x2,y2,radius,i;
setcolor(YELLOW);
cout<<"enter the valueof x1:=";
cin>>x1;
cout<<"enter the value of y1:=";
cin>>y1;
cout<<"enter the value of x2:=";
cin>>x2;
cout<<"enter the value of y2:=";
cin>>y2;
rectangle(x1,y1,x2,y2);
getch();
closegraph();
}
{
int gd=DETECT,gm;
initgraph(&gm,&gd," ");
int x,y,radius,i;
setcolor(YELLOW);
cout<<"enter the valueof x:=";
cin>>x;
cout<<"enter the value of y:=";
cin>>y;
cout<<"enter the radius:=";
cin>>radius;
circle(x,y,radius);
getch();
closegraph();
}
OUTPUT
OUTPUT
}
else
{
steps=abs(dy);
}
x=x1;
y=y1;
putpixel(x,y,1);
for(k=0;k<steps;k++)
{
x++;
y=y+m;
putpixel(x,y,1);
}
getch();
closegraph();
}
pk=2*dy-dx;
cout<<"inital value:="<<pk;
while(x<x2)
{
x++;
if(pk<0)
{
pk2=pk+2*dy;
}
else
{
y++;
pk2=pk+2*dy-2*dx;
}
putpixel(x,y,1);
}
getch();
closegraph();
}
else
{
x++;
y--;
p=p+2*(x-y)+5;
}
putpixel(xc+x,yc+y,1);
putpixel(xc-x,yc+y,1);
putpixel(xc+x,yc-y,1);
putpixel(xc-x,yc-y,1);
putpixel(xc+y,yc+x,1);
putpixel(xc-y,yc+x,1);
putpixel(xc+y,yc-x,1);
putpixel(xc-y,yc-x,1);
}
getch();
}
putpixel(xc+x,yc+y,WHITE);
putpixel(xc+y,yc+x, WHITE;
putpixel(xc-x,yc+y, WHITE);
putpixel(xc+y,yc-x, WHITE);
putpixel(xc-x,yc-y, WHITE);
putpixel(xc-y,yc+x, WHITE);
putpixel(xc+x,yc-y, WHITE);
putpixel(xc-y,yc-x, WHITE);
}
getch();
closegraph();
}
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
void main()
{
int gd=DETECT,gm,xc,yc,rx,ry,rx2,ry2,x,y,p0,p1,py,px,trx2,try2;
initgraph(&gd,&gm, "");
cout<<"\n\t Enter the coordinates of center of ellipse: ";
cin>>xc>>yc;
cout<<"\n\t Now enter the x-radius: ";
cin>>rx;
cout<<"\n\t Now enter the y-radius: ";
cin>>ry;
rx2=rx*rx;
ry2=ry*ry;
trx2=2*rx2;
try2=2*ry2;
x=0;y=ry;px=0;py=trx2*y;
// Region 1 ..!
p0=abs(ry2-(rx2*ry2)+(0.25*rx2));
while(px<py)
{
x++;
px+=try2;
if(p0<0)
p0+=ry2+px;
else
{
y--;
py-=trx2;
p0+=ry2+px-py;
}
putpixel(xc+x,yc+y,WHITE);
putpixel(xc-x,yc+y, WHITE);
putpixel(xc+x,yc-y, WHITE);
putpixel(xc-x,yc-y, WHITE);
delay(100);
}
p1=abs(ry2*(x+0.5)*(x+0.5)+rx2*(y-1)*(y-1)-rx2*ry2);
while(y>0)
{
y--;
py-=trx2;
if(p1>0)
p1+=rx2-py;
else
{
x++;
px+=try2;
p1=rx2-py+px;
}
putpixel(xc+x,yc+y, WHITE);
putpixel(xc-x,yc+y, WHITE);
putpixel(xc+x,yc-y, WHITE);
putpixel(xc-x,yc-y, WHITE);
delay(100);
}
getch();
closegraph();
}
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm, "");
int xa,xb,ya,yb,xc,tx,ty,yc,x,y;
cout<<"enter the coordinate of triangle:=";
cin>>xa>>ya>>xb>>yb>>xc>>yc;
line(xa,ya,xb,yb);
line(xb,yb,xc,yc);
line(xc,yc,xa,ya);
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cin>>x;
cout<<"enter the translation vector ty:=";
cin>>y;
xa=x+xa;
xb=x+xb;
ya=y+ya;
yb=y+yb;
xc=x+xc;
yc=y+yc;
line(xa,ya,xb,yb);
line(xb,yb,xc,yc);
line(xc,yc,xa,ya);
getch();
}
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm, "");
int xa,xb,ya,yb,xc,yc,i,j,k;
int a[3][3],b[3][3],c[3][3];
cout<<"enter the coordinate of triangle:=";
cin>>xa>>ya>>xb>>yb>>xc>>yc;
line(xa,ya,xb,yb);
line(xa,ya,xc,yc);
line(xb,yb,xc,yc);
cout<<"Reflection about xaxis:=";
a[0][0]=1;
a[0][1]=0;
a[0][2]=0;
a[1][0]=0;
a[1][1]=-1;
a[1][2]=480;
a[2][0]=0;
a[2][1]=0;
a[2][2]=1;
b[0][0]=xa;
b[0][1]=xb;
b[0][2]=xc;
b[1][0]=ya;
b[1][1]=yb;
b[1][2]=yc;
b[2][0]=1;
b[2][1]=1;
b[2][2]=1;
for(i=0;i<3;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];
}
}
}
xa=c[0][0];
xb=c[0][1];
xc=c[0][2];
ya=c[1][0];
yb=c[1][1];
yc=c[1][2];
line(xa,ya,xb,yb);
line(xa,ya,xc,yc);
line(xb,yb,xc,yc);
getch();
}
a[2][1]=0;
a[2][2]=1;
b[0][0]=xa;
b[0][1]=xb;
b[0][2]=xc;
b[1][0]=ya;
b[1][1]=yb;
b[1][2]=yc;
b[2][0]=1;
b[2][1]=1;
b[2][2]=1;
for(i=0;i<3;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];
}
}
}
xa=c[0][0];
xb=c[0][1];
xc=c[0][2];
ya=c[1][0];
yb=c[1][1];
yc=c[1][2];
line(xa,ya,xb,yb);
line(xa,ya,xc,yc);
line(xb,yb,xc,yc);
getch();
}