Last active
February 28, 2016 17:28
-
-
Save kp96/036c0f349f6b8292c008 to your computer and use it in GitHub Desktop.
GenralLineDrawingAlgorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <graphics.h> | |
#include <stdlib.h> | |
int main() { | |
int gd = DETECT, gm; | |
int x1,y1,x2,y2; | |
initgraph(&gd,&gm,"DDA"); | |
x1 = 5, y1 = 5, x2 = 32, y2 = 54; | |
float m = (y2 - y1) * 1.0 / (x2 - x1) * 1.0; | |
float c = y2 - m * x2; | |
for(int i = x1; i <= x2; i++) { | |
int j = m * i + c; | |
putpixel(i, j, WHITE); | |
} | |
delay(5000); | |
line(x1, y1, x2, y2); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment