Access Millions of academic & study documents

Cg lab manual

Content type
User Generated
School
IIIT Jabalpur PDPM Indian Institute of Information Technology Design Manufacturing
Showing Page:
1/60
Practical 2
AIM: WAP to draw a straight line using DDA Algorithm
SOFTWARE USED:
Tool : TURBO C++
Operating system : WINDOWS
Hardware : COMPUTER
SOURCE CODE:
#include<conio.h>
#include<iostream.h>
#include<graphics.h>
#include<math.h>
#define ROUND(a)((int)(a+0.5))
void DDA(int xa,int ya,int xb,int yb)
{
int dx=xb-xa,dy=yb-ya,steps,k;
float xinc,yinc,x=xa,y=ya;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xinc=dx/float(steps;
yinc=dy/float(steps;
putpixel(ROUND(x),ROUND(y),15);
for(k=0;k<steps;k++)
{
x=x+xinc; y=y+yinc;
putpixel(ROUND(x),ROUND(y),15);
}}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/60
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\tc:\bgi"); int
xa,xb,ya,yb;
cout<<"Enter the points";
cin>>xa>>xb>>ya>>yb;
DDA(xa,xb,ya,yb);
getch();
}
INPUT/OUTPUT:
Enter the points 50 60 300 250

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/60

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 60 pages?
Access Now
Unformatted Attachment Preview
Practical 2 AIM: WAP to draw a straight line using DDA Algorithm SOFTWARE USED: Tool Operating system Hardware : TURBO C++ : WINDOWS : COMPUTER SOURCE CODE: #include #include #include #include #define ROUND(a)((int)(a+0.5)) void DDA(int xa,int ya,int xb,int yb) { int dx=xb-xa,dy=yb-ya,steps,k; float xinc,yinc,x=xa,y=ya; if(abs(dx)>abs(dy)) steps=abs(dx); else steps=abs(dy); xinc=dx/float(steps; yinc=dy/float(steps; putpixel(ROUND(x),ROUND(y),15); for(k=0;k>xb>>ya>>yb; DDA(xa,xb,ya,yb); getch(); } INPUT/OUTPUT: Enter the points 50 60 300 250 Practical 3 AIM: WAP to draw a straight line using Bresenham’s Algorithm. SOFTWARE USED: Tool Operating system Hardware : TURBO C++ : WINDOWS : COMPUTER SOURCE CODE: #include #include #include #include void lineBres(int xa,int ya,int xb,int yb) { int dx=abs(xa-xb),dy=abs(ya-yb); int p=2*dy-dx; int twoDy=2*dy,twoDyDx=2*(dy-dx); int x,y,xEnd; clrscr(); //determine which point to use as start,which as end if(xa>xb) { x=xb; y=yb; xEnd=xa; } else { x=xa; y=ya; xEnd=xb; } putpixel(x,y,45); while(x ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4