BSc Computer Science /BCA Kerala University School Of Distance Education 2013-2016 (Regular) Batch
Thursday, 16 November 2017
Sunday, 12 November 2017
Computer Graphics 2- BRESENHAM’S LINE DRAWING ALGORITHM
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
main()
{
int gd=DETECT,gm;
int xa,xb,ya,yb;
int dx,dy,x,y,xend,p;
clrscr();
initgraph(&gd,&gm," ");
printf("enter the left end points(xa,ya):");
scanf("%d%d",&xa,ya);
printf("enter the two right end points(xb,yb):");
scanf("%d%d",&xb,&yb);
dx=abs(xa-xb);
dy=abs(ya-yb);
p=2*dy-dx;
if(xa>xb)
{
x=xb;
y=yb;
xend=xa;
}
else
{
x=xa;
y=ya;
xend=xb;
}
putpixel(x,y,6);
while(x<xend)
{
x=x+1;
if(p<0)
{
p=p+2*dy;
}
else
{
y=y+1;
p=p+2*(dy-dx);
}
putpixel(x,y,6);
}
getch();
return 0;
}
#include<conio.h>
#include<math.h>
#include<graphics.h>
main()
{
int gd=DETECT,gm;
int xa,xb,ya,yb;
int dx,dy,x,y,xend,p;
clrscr();
initgraph(&gd,&gm," ");
printf("enter the left end points(xa,ya):");
scanf("%d%d",&xa,ya);
printf("enter the two right end points(xb,yb):");
scanf("%d%d",&xb,&yb);
dx=abs(xa-xb);
dy=abs(ya-yb);
p=2*dy-dx;
if(xa>xb)
{
x=xb;
y=yb;
xend=xa;
}
else
{
x=xa;
y=ya;
xend=xb;
}
putpixel(x,y,6);
while(x<xend)
{
x=x+1;
if(p<0)
{
p=p+2*dy;
}
else
{
y=y+1;
p=p+2*(dy-dx);
}
putpixel(x,y,6);
}
getch();
return 0;
}
Computer Graphics 1- How to draw a DDA Line Algorithm ?
DDA Line Algorithm ,
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int x1,y1,x2,y2,dx,dy,i,length;
float x,y,xinc,yinc;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("enter x coordinates");
scanf("%d%d",&x1,x2);
printf("enter y coordinates");
scanf("%d%d",&y1,y2);
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
length=abs(dx);
else
length=abs(dy);
xinc=dx/(float)length;
yinc=dy/(float)length;
x=x1;
y=y1;
putpixel(x,y,7);
for(i=0;i<length;i++)
{
putpixel(x,y,7);
x=x+xinc;
y=y+yinc;
delay(10);
}
getch();
closegraph();
}
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int x1,y1,x2,y2,dx,dy,i,length;
float x,y,xinc,yinc;
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("enter x coordinates");
scanf("%d%d",&x1,x2);
printf("enter y coordinates");
scanf("%d%d",&y1,y2);
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
length=abs(dx);
else
length=abs(dy);
xinc=dx/(float)length;
yinc=dy/(float)length;
x=x1;
y=y1;
putpixel(x,y,7);
for(i=0;i<length;i++)
{
putpixel(x,y,7);
x=x+xinc;
y=y+yinc;
delay(10);
}
getch();
closegraph();
}
Subscribe to:
Posts (Atom)