0% found this document useful (0 votes)
5 views2 pages

Ddadashline

dda line drawing algorithm

Uploaded by

pankajrathod4510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Ddadashline

dda line drawing algorithm

Uploaded by

pankajrathod4510
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <math.h>
using namespace std;
int x1, x2;
int Y1, Y2;
float gap;
void display(void) {
int DelX, DelY, Max;
int n = 0, Total = 1, j = 0;
double Sigma = 1, XIncr, YIncr, x, y, slope;
double gapX, gapY;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 1.0, 0.0);
if (x2 < x1 && Y2 < Y1) {
int var;
var = x1; x1 = x2; x2 = var;
var = Y1; Y1 = Y2; Y2 = var;
}
DelX = x2 - x1;
DelY = Y2 - Y1;
Max = ((DelX > DelY) ? DelX : DelY);
for (n = 0; Total <= Max; n++) {
Total = Total * 2;
}
for (int i = n; i > 0; i--) {
Sigma = Sigma / 2;
}
XIncr = Sigma * DelX;
YIncr = Sigma * DelY;
x = x1; y = Y1;
glBegin(GL_POINTS);
glVertex2s(x1, Y1);
slope = DelY / DelX;
gapX = gap / sqrt(1 + slope * slope);
while (x != x2 || y != Y2) {
x = x + XIncr;
y = y + YIncr;
j = x / gapX;
if ((j % 2) == 0) {
glVertex2s(x, y);
cout << x << y;
}
}
glColor3f(0.0, 5.0, 0.0);
for (int i = -100; i <= 100; i++) {
glVertex2s(i, 0);
glVertex2s(0, i);
}
for (int i = -2; i <= 2; i++) {
glVertex2s(95 + i, 4 + i);
glVertex2s(95 - i, 4 + i);
}
for (int i = 0; i <= 2; i++) {
glVertex2s(4 + i, 95 + i);
glVertex2s(4 - i, 95 + i);
glVertex2s(4, 95 - i);
}
glEnd();
glFlush();
}
void init(void) {
glClearColor(0.0, 0.0, 0.0, 0.0);
glOrtho(-100.0, 100.0, -100.0, 100.0, -1.0, 1.0);
}
int main(int argc, char **argv) {
cout << "Enter Initial points:\n";
cin >> x1 >> Y1;
cout << "Enter Final points:\n";
cin >> x2 >> Y2;
cout << "Enter Gapping\n";
cin >> gap;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("DDA Algo");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

You might also like