Skip to content

Instantly share code, notes, and snippets.

@kp96
Last active February 28, 2016 17:28
Show Gist options
  • Save kp96/036c0f349f6b8292c008 to your computer and use it in GitHub Desktop.
Save kp96/036c0f349f6b8292c008 to your computer and use it in GitHub Desktop.
GenralLineDrawingAlgorithm
#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