Bresenham Line Algorithm C++ Code
Learn Bresenham Line Algorithm C++ Code here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#include<bits/stdc++.h> #include<graphics.h> using namespace std; void drawline(int x0, int y0, int x1, int y1) { int dx, dy, p, x, y; dx=x1-x0; dy=y1-y0; x=x0; y=y0; p=2*dy-dx; while(x<x1) { if(p>=0) { putpixel(x,y,7); y=y+1; p=p+2*dy-2*dx; } else { putpixel(x,y,7); p=p+2*dy; } x=x+1; delay(100); } } int main() { int gdriver=DETECT, gmode, error, x0, y0, x1, y1; initgraph(&gdriver, &gmode, ""); cout<<"Enter co-ordinates of first point: "; cin>>x0>>y0; cout<<"Enter co-ordinates of second point: "; cin>>x1>>y1; drawline(x0, y0, x1, y1); getch(); return 0; } |
Thanks for viewing.