void drawline ( int dx, int dy /* endpoint is (hpos+dx, vpos+dy) */ ) { /* * * Draws a line from (hpos, vpos) to (hpos+dx, vpos+dy), and leaves the current * position at the endpoint. * */ if ( dx == 0 && dy == 0 ) drawcirc(1, 'c'); else fprintf(tf, "%d %d %d %d Dl\n", hpos + dx, vpos + dy, hpos, vpos); hgoto(hpos+dx); /* where troff expects to be */ vgoto(vpos+dy); resetpos(); /* not sure where the printer is */ } /* End of drawline */
int main() { int win; int cnt; float x_cen = X_CEN; float y_cen = Y_CEN; win = gopen(WIDTH,HEIGHT); puts("Move your mouse cursor on the window :-)"); /* レイヤの設定をする */ layer(win, 0,1); /* ノンブロックモードにする */ gsetnonblock(ENABLE); cnt = 0; while ( 1 ) { int win_ev; /* イベントのあったウィンドゥ番号 */ int type, b; /* イベントのタイプ,ボタン */ float r, x, y; win_ev = ggetevent(&type,&b,&x,&y) ; if ( win_ev == win ) { if ( type == MotionNotify ){ x_cen = x; y_cen = y; } else if ( type == ButtonPress ) { break; } } else { int i; if ( CNT_MAX <= cnt ) cnt = 0; gclr(win); for ( i=0 ; i < 4 ; i++ ) { r = pow((cnt+i*(CNT_MAX/4)) % CNT_MAX, 2)/DIV; drawcirc(win,x_cen,y_cen,r,r); } copylayer(win, 1,0); msleep(20); cnt++; } } gclose(win); return(0); }
void conv(register FILE *fp) { register int c, k; int m, n, n1, m1; char str[4096], buf[4096]; while ((c = getc(fp)) != EOF) { switch (c) { case '\n': /* when input is text */ case ' ': case 0: /* occasional noise creeps in */ break; case '{': /* push down current environment */ t_push(); break; case '}': t_pop(); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* two motion digits plus a character */ hmot((c-'0')*10 + getc(fp)-'0'); put1(getc(fp)); break; case 'c': /* single ascii character */ put1(getc(fp)); break; case 'C': sget(str, sizeof str, fp); put1s(str); break; case 't': /* straight text */ fgets(buf, sizeof(buf), fp); t_text(buf); break; case 'D': /* draw function */ fgets(buf, sizeof(buf), fp); switch (buf[0]) { case 'l': /* draw a line */ sscanf(buf+1, "%d %d", &n, &m); drawline(n, m, "."); break; case 'c': /* circle */ sscanf(buf+1, "%d", &n); drawcirc(n); break; case 'e': /* ellipse */ sscanf(buf+1, "%d %d", &m, &n); drawellip(m, n); break; case 'a': /* arc */ sscanf(buf+1, "%d %d %d %d", &n, &m, &n1, &m1); drawarc(n, m, n1, m1); break; case '~': /* wiggly line */ drawwig(buf+1); break; default: error(FATAL, "unknown drawing function %s\n", buf); break; } break; case 's': fscanf(fp, "%d", &n); if (n == -23) { float f; fscanf(fp, "%f", &f); setsize(f); } else setsize(t_size(n));/* ignore fractional sizes */ break; case 'f': sget(str, sizeof str, fp); setfont(t_font(str)); break; case 'H': /* absolute horizontal motion */ /* fscanf(fp, "%d", &n); */ while ((c = getc(fp)) == ' ') ; k = 0; do { k = 10 * k + c - '0'; } while (isdigit(c = getc(fp))); ungetc(c, fp); hgoto(k); break; case 'h': /* relative horizontal motion */ /* fscanf(fp, "%d", &n); */ while ((c = getc(fp)) == ' ') ; k = 0; do { k = 10 * k + c - '0'; } while (isdigit(c = getc(fp))); ungetc(c, fp); hmot(k); break; case 'w': /* word space */ putc(' ', stdout); break; case 'V': fscanf(fp, "%d", &n); vgoto(n); break; case 'v': fscanf(fp, "%d", &n); vmot(n); break; case 'p': /* new page */ fscanf(fp, "%d", &n); t_page(n); break; case 'n': /* end of line */ while (getc(fp) != '\n') ; t_newline(); break; case '#': /* comment */ while (getc(fp) != '\n') ; break; case 'x': /* device control */ devcntrl(fp); break; default: error(!FATAL, "unknown input character %o %c\n", c, c); done(); } } }