/*______________________________________________ | | | txplot v1.0 - a simple tty plotting utility | | Copyright (c) 1994-2002 by Antoni Sawicki | | http://www.tenox.tc/out/ tenox@tenox.tc | |______________________________________________| |''''''''''''''''''''''''''''''''''''''''''''' | | /\ | / \ ,'. /\ distributed under ,' | / \' `. ,'. \ , /\ __,'_---- | ,' \ `'/ `.\ ,' `. /\__,_/_---,' | ,' \ GNU /_____`\/\---`.--,' `. ,\ | '_____--\---/ \ / `' \/ `' \ | General \ / Public \/ License \ | ' \ | */ #include #include #include #define PLOTCHAR 'O' int draw_scale(int argc, int argm, int xmax, int ymax); int draw_line(int x1, int y1, int x2, int y2); int main(int argc, char *argv[]) { char *env; int n,argmax=0; struct position { int x; int y; } pos[argc]; //this is GCC-only extension if(argc<3) usage(); //find y-scale maximum env=getenv("TXPLOT_SCALE"); if(env!=0) argmax=atoi(env); else for(n=1;nargmax) argmax=atoi(argv[n]); //init curses screen initscr(); //draw scale draw_scale(argc, argmax, COLS, LINES); //build position table and rescale to real screen size for(n=1; n"); return 0; } int draw_line(int x1, int y1, int x2, int y2) { float a,x; int b,y; a=(float) (y2-y1) / (x2-x1); b=y1-a*x1; for(x=x1; x<=x2; x=x+0.1) { y=a*x+b; mvaddch(y,x,PLOTCHAR); } return 0; } int usage(void) { printf( "Usage: txplot val val val ...\n"\ "Example: txplot 95 50 95 100 25 50 10 15 12 10 5\n\n"\ "For fixed scale, set environment vairable TPLOT_SCALE"\ "to the desired Y-Max.\n"\ "For latest version go to: http://www.tenox.tc/out/\n" ); exit(1); } // vi:sw=4:ts=4