static void plotBP(char* sequence, short* structure) { int i; int length; float lx, ly; float arcx, arcy, rad; length = (int)strlen(sequence) ; setlinestyle(SOLID); setcolor(BLACK); for(i = 0; i<length; i++) { if(structure[i] > i) { lx = structure[i] - i + 1; //drawline((i+0.5)*CELLSIZE, length*CELLSIZE/2 - 1, (i + 0.5)*CELLSIZE, (length+lx)*CELLSIZE/2 -1); flushinput(); //drawline((structure[i]-0.5)*CELLSIZE, length*CELLSIZE/2-1,(structure[i]-0.5)*CELLSIZE, (length+lx)*CELLSIZE/2 -1); flushinput(); //drawline((i+0.5)*CELLSIZE, (length+lx)*CELLSIZE/2-1, (structure[i]-0.5)*CELLSIZE, (length+lx)*CELLSIZE/2-1); arcx = (i + structure[i] )/2.0 * CELLSIZE; arcy = length*CELLSIZE/2 -1; rad = (structure[i] - 1 - i )/2.0 *CELLSIZE; drawarc(arcx, arcy, rad, 0, -180.0); flushinput(); } } }
static void draw_rr_switch (float from_x, float from_y, float to_x, float to_y, boolean buffered) { /* Draws a buffer (triangle) or pass transistor (circle) on the edge * * connecting from to to, depending on the status of buffered. The drawing * * is closest to the from_node, since it reflects the switch type of from. */ const float switch_rad = 0.15; float magnitude, xcen, ycen, xdelta, ydelta, xbaseline, ybaseline; float xunit, yunit; t_point poly[3]; xcen = from_x + (to_x - from_x) / 10.; ycen = from_y + (to_y - from_y) / 10.; if (!buffered) { /* Draw a circle for a pass transistor */ drawarc (xcen, ycen, switch_rad, 0., 360.); } else { /* Buffer */ xdelta = to_x - from_x; ydelta = to_y - from_y; magnitude = sqrt (xdelta * xdelta + ydelta * ydelta); xunit = xdelta / magnitude; yunit = ydelta / magnitude; poly[0].x = xcen + xunit * switch_rad; poly[0].y = ycen + yunit * switch_rad; xbaseline = xcen - xunit * switch_rad; ybaseline = ycen - yunit * switch_rad; /* Recall: perpendicular vector to the unit vector along the switch (xv, yv) * * is (yv, -xv). */ poly[1].x = xbaseline + yunit * switch_rad; poly[1].y = ybaseline - xunit * switch_rad; poly[2].x = xbaseline - yunit * switch_rad; poly[2].y = ybaseline + xunit * switch_rad; fillpoly (poly, 3); } }
void draw(void *_prms) { param_set *p = (param_set *) _prms; int id, aggr = 0, this_r; int x, y, xnt, ynt, tk, key = 0; float tx[50000], ty[50000], th; for (;;) { if (*p->new_r) { *p->new_r = 0; *p->src_r += *p->r_inc; *p->rem_r = *p->src_r + *p->r_inc; if (*p->src_r >= (*p->R / 2)) { *p->run = 0; print_density(p); break; } } th = drand48() * 2.0 * M_PI; x = *p->src_r * cos(th) + *p->mid; y = *p->src_r * sin(th) + *p->mid; tk = 0; while (*p->run) { id = floor(drand48() * 4.0); xnt = (id == 0) ? x - 1 : (id == 1) ? x + 1 : x; ynt = (id <= 1) ? y : (id == 2) ? y - 1 : y + 1; tx[tk] = xnt; ty[tk] = ynt; this_r = hypot(xnt - *p->mid, ynt - *p->mid); if ((xnt < *p->mid - *p->R) || (xnt >= *p->mid + *p->R) || (ynt < *p->mid - *p->R) || (ynt >= *p->mid + *p->R) || (this_r > *p->rem_r)) { newcolor(*p->win, "red4"); break; } /* seems to escape */ if (grid[xnt - 1][ynt] == 1 || grid[xnt][ynt - 1] == 1 || grid[xnt][ynt + 1] == 1 || grid[xnt + 1][ynt] == 1) { aggr = 1; if (drand48() <= *p->agg_prob) { grid[xnt][ynt] = 1; if (this_r >= *p->src_r) *p->new_r = 1; layer(*p->win, 0, 2); newcolor(*p->win, ECTRL_FGCOLOR); pset(*p->win, xnt, ynt); layer(*p->win, 0, 1); newcolor(*p->win, "green3"); } break; } /* aggregate */ if (aggr == 0) { x = xnt; y = ynt; } aggr = 0; tk++; } gclr(*p->win); copylayer(*p->win, 2, 1); newlinestyle(*p->win, LineSolid); drawpts(*p->win, tx, ty, tk - 1); newcolor(*p->win, "gray50"); newlinestyle(*p->win, LineOnOffDash); drawarc(*p->win, *p->mid, *p->mid, *p->src_r, *p->src_r, 0, 360, 0); copylayer(*p->win, 1, 0); msleep(5); key = ggetch(); if (key == 'q') { *p->run = 0; goto RET; } } RET: ; /* do nothing just return */ }
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(); } } }