#include #include #include #include #include /* In honor of Jocelyn Bell Burnell, who deserved the Nobel. */ /* TODO: * Resize the initial window, if we can make everything fit. */ /* Space between lines, multiplier on x & y spacing, line thickness. */ int offset, magx, magy, thick; #define NCOLORS 6 Image *cols[NCOLORS][3]; /* NLINES and LINELEN match the original pulsar data. */ #define NLINES 80 #define LINELEN 300 static float pulsar[NLINES][LINELEN]; void drawline(int i) { int n, baseline; int hmargin = 10; int vmargin = 150; Point new, prev, start; hmargin = (screen->r.max.x - screen->r.min.x - LINELEN*magx)/2; baseline = screen->r.min.y+vmargin+NLINES*offset; prev = start = addpt(screen->r.min, Pt(hmargin, vmargin+offset*i)); for(n = 0; n < LINELEN; n++) { new = addpt(start, Pt(magx*n, magy*-pulsar[i][n])); line(screen, prev, new, Endsquare, Endsquare, thick, cols[i%NCOLORS][2], ZP); line(screen, new, Pt(new.x, baseline), Endsquare, Endsquare, magx, cols[i%NCOLORS][1], ZP); prev = new; } } void resize(void) { int i; for(i = 0; i < NLINES; i++) { drawline(i); flushimage(display, 1); } } void eresized(int new) { if(new && getwindow(display, Refnone) < 0) { fprint(2, "%s: can't reattach to window\n", argv0); exits("reattach"); } resize(); } /* These colors are from stats.c. * Stats uses c0 for above the line, c1 for below, and c2 for the line. * I think using c0 fro below might look better here. */ void mkcol(int i, int c0, int c1, int c2) { cols[i][0] = allocimagemix(display, c0, DWhite); cols[i][1] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, c1); cols[i][2] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, c2); } void colinit(void) { /* Peach */ mkcol(0, 0xFFAAAAFF, 0xFFAAAAFF, 0xBB5D5DFF); /* Aqua */ mkcol(1, DPalebluegreen, DPalegreygreen, DPurpleblue); /* Yellow */ mkcol(2, DPaleyellow, DDarkyellow, DYellowgreen); /* Green */ mkcol(3, DPalegreen, DMedgreen, DDarkgreen); /* Blue */ mkcol(4, 0x00AAFFFF, 0x00AAFFFF, 0x0088CCFF); /* Grey */ cols[5][0] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF); cols[5][1] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF); cols[5][2] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x888888FF); } void parsefile(char* f) { Biobuf* b; char* line, *buf; int i, j; b = Bopen(f, OREAD); if(b == nil) { fprint(2, "%s: cannot open %s: %r\n", argv0, f); exits("open"); } for(i=0; iscreen->fill = display->black; colinit(); einit(Emouse); parsefile(csv); for (;;) { resize(); switch(eread(Ekeyboard, &e)) { case Ekeyboard: if(e.kbdc==0x7F || e.kbdc=='q') exits(0); break; } } }