009
22.09.2003, 19:23 Uhr
0xdeadbeef
Gott (Operator)
|
Also, mein Programm sieht jetzt so aus:
C++: |
#include <iostream> #include <sstream>
void clear_screen(std::ostream& out) { out<<"\x1b[2J"<<std::flush; }
void set_point(std::ostream& out, unsigned x, unsigned y) { out<<"\x1b["<<x<<";"<<y<<"HX"<<std::flush; }
void draw_line(std::ostream &out, int x1, int y1, int x2, int y2) { if(x1 == x2 && y1 == y2) set_point(out, x1, y1); else { double dx = double(x2 - x1) / std::max(std::abs(x2 - x1), std::abs(y2 - y1)), dy = double(y2 - y1) / std::max(std::abs(x2 - x1), std::abs(y2 - y1)), rx = x1, ry = y1;
while(unsigned(rx + .5) != x2 || unsigned(ry + .5) != y2) { set_point(out, unsigned(rx + .5), unsigned(ry + .5)); rx += dx; ry += dy; } set_point(out, x2, y2); } }
int main(int argc, char *argv[]) { int a, b, c, d;
sscanf(argv[1], "%d", &a); sscanf(argv[2], "%d", &b); sscanf(argv[3], "%d", &c); sscanf(argv[4], "%d", &d);
clear_screen(std::cout); draw_line(std::cout, a, b, c, d); }
|
und läuft einwandfrei. -- Einfachheit ist Voraussetzung für Zuverlässigkeit. -- Edsger Wybe Dijkstra |