Docsity

Computer Graphics DDA Algorithm, Assignments of Computer Graphics

Toggle sidebar
bg1
Name: - Siddhi Mehta Roll no: - 2203213
Course: - CSL 303 Batch: - C34
Program Code:
//SIDDHI MEHTA 213
//DDA LINE ALGORITHM
#include<stdio.h>
#include<conio.h>
#include<dos.h>
//for delay()function
#include<graphics.h>
int abs_val(int n) //to calculate absolute value to plot
{
if (n>0)
{
return n;
}
else
{
return -n;
}
}
int dda(int x1,int y1,int x2, int y2) //line drawing algorithm
{
int dx, dy , step;
float xinc,yinc,x,y;
dx = x2-x1;
dy = y2-y1;
if(abs_val(dx)>abs_val(dy))
{
step = abs_val(dx);
}
Experiment 2 1
pf3
pf4

Partial preview of the text

Download Computer Graphics DDA Algorithm and more Assignments Computer Graphics in PDF only on Docsity!

Course: - CSL 303 Batch: - C

Program Code:

//SIDDHI MEHTA 213

//DDA LINE ALGORITHM

#include<stdio.h> #include<conio.h> #include<dos.h> //for delay()function #include<graphics.h> int abs_val(int n) //to calculate absolute value to plot { if (n>0) { return n; } else { return -n; } } int dda(int x1,int y1,int x2, int y2) //line drawing algorithm { int dx, dy , step; float xinc,yinc,x,y; dx = x2-x1; dy = y2-y1; if(abs_val(dx)>abs_val(dy)) { step = abs_val(dx); }

Course: - CSL 303 Batch: - C

else { step = abs_val(dy); } xinc = dx/step; yinc = dy/step; x=x1; y=y1; for(int i = 0; i<=step; i++) //putting pixels { if(i%2==0) { x+=xinc; y+=yinc; delay(200); } putpixel(x,y,YELLOW); x+=xinc; y+=yinc; delay(200); } return 0; } int main() { int gd = DETECT,gm; int x1,x2,y1,y2; clrscr(); initgraph(&gd,&gm,"..\BGI"); printf("\n\nSiddhi Mehta - 213\n\n"); printf("Enter Starting points of line: "); scanf("%d %d",&x1,&y1); printf("Enter Ending points of line: "); scanf("%d %d",&x2,&y2);

  • Course: - CSL 303 Batch: - C