#include #include #include #include #include void DDALine(unsigned, unsigned, unsigned, unsigned); void Line(int, int, int, int); void set_mode(char mode) { union REGS regs; regs.h.ah = 0; regs.h.al = mode; int86(0x10, ®s, ®s); /* asm mov ah, 0x0; asm mov al, mode; asm int 0x10; */ } //void Putpixel(unsigned x, unsigned y, char color) void Putpixel(int x, int y, char color) { union REGS regs; regs.h.ah = 0x0c; regs.h.al = color; regs.x.cx = x; regs.x.dx = y; int86(0x10, ®s, ®s); /* asm mov ah, 0x0c; asm mov al, color; asm mov cx, x; asm mov dx, y; asm int 0x10; */ } template T Abs(T x) { if(x < 0) return ((-1) * x); else return x; } /* unsigned Abs(int x) { if(x < 0) return (-1 * x); else return x; } */ int Round(float x) { return ((x * 10 + 5) / 10); } char Getch() { char C; asm mov ah, 0x07; asm int 0x21; asm mov C,al; return C; } void main() { // set_mode(0x12); /* int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode, ""); */ clrscr(); Line(1, 2, 4, 9); /* // Line(0, 0, 639, 479); getch(); getch(); line(479, 0, 0, 479); // DDALine(0, 0, 63, 47); getch(); getch(); // line(0, 0, 639, 479);*/ getch(); getch(); // closegraph(); // set_mode(0x03); } void Line(int x1, int y1, int x2, int y2) { int x, y, dx, dy, p, end, inc; dx = Abs(x1 - x2); dy = Abs(y1 - y2); if(dx > dy) { p = 2 * dy - dx; if(x1 > x2) { x = x2; y = y2; end = x1; if(y2 > y1) inc = -1; else inc = 1; } else { x = x1; y = y1; end = x2; if(y1 > y2) inc = -1; else inc = 1; } // Putpixel(x , y, 1); cout< y2) { x = x2; y = y2; end = y1; if(x2 > x1) inc = -1; else inc = 1; } else { x = x1; y = y1; end = y2; if(x1 > x2) inc = -1; else inc = 1; } // Putpixel(x, y, 1); cout< abs(dy)) step = abs(dx); else step = abs(dy); if(step != 0) { incx = (float) dx/step; incy = (float) dy/step; } x = x1; y = y1; Putpixel(x, y, 4); // cout<