Assignmet1 Hridoy 114 6B1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

University of Information Technology & Science

Department of Computer Science and Engineering

Computer Graphics & Multimedia Laboratory


CSE 358
Assignment No. 1

Submitted To
Salim Shadman Ankur
Lecturer

Submitted By
Md. Hridoy Mia
ID : 2014751114
SEC : 6B1
Code for DDA line drawing algorithm

#include<bits/stdc++.h>
using namespace std;

int main(){

int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int delx,dely,m;

delx=(x2-x1);
dely=(y2-y1);
m=dely/delx;

cout<<"("<<x1<<","<<y1<<")"<<"\n";
int x=0,y=0;
if(delx>=dely){
while(x<x2 && y<y2){
x=x1+1;
y=y1+1;
x1++;
y1++;
cout<<"("<<x<<","<<y<<")"<<"\n";
}
}
else{
while(x<x2 && y<y2){
x=x1+(1/m);
y=y1+1;
x1++;
y1++;
cout<<"("<<x<<","<<y<<")"<<"\n";
}
}
return 0;
}

You might also like