Skip to content

Instantly share code, notes, and snippets.

@whopiyush
Created February 10, 2022 18:10
Show Gist options
  • Select an option

  • Save whopiyush/e0a31bff62106e676c80163bc7a7f607 to your computer and use it in GitHub Desktop.

Select an option

Save whopiyush/e0a31bff62106e676c80163bc7a7f607 to your computer and use it in GitHub Desktop.
#include <iostream.h>
#include <graphics.h>
#include <dos.h>
void calculate(int *pk, int dx, int dy, int *x, int *y) {
++(*x);
if(*pk < 0) {
*pk = *pk + (2*dy);
} else if(*pk > 0) {
*pk = *pk + (2*dy) - (2*dx);
++(*y);
}
};
int main() {
int x, y, x1=200, y1=100, x2=300, y2=180, gdriver=DETECT, gdm;
int pk, dx, dy;
initgraph(&gdriver, &gdm, "c:\\tc\\bgi");
dx = x2 - x1;
dy = y2 - y1;
pk = (2*dy) - dx;
x = x1;
y = y1;
while(x<=x2 && y<=y2) {
putpixel(x, y, 5);
calculate(&pk, dx, dy, &x, &y);
delay(100);
}
closegraph();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment