Annotation of researchv10dc/vol2/Faces/How/src/pfill.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: 
        !             3: #define SZ     512
        !             4: 
        !             5: typedef struct Node {
        !             6:        int x, y;
        !             7:        struct Node *nxt;       /* contour */
        !             8:        int soc;                /* node is start of new curve */
        !             9: } Node;
        !            10: 
        !            11: Node *frst = (Node *) 0;
        !            12: int lcnt=0;
        !            13: extern int Factor;
        !            14: 
        !            15: zaplist()
        !            16: {      Node *ptr = frst;
        !            17:        Node *save;
        !            18: 
        !            19:        while (ptr)
        !            20:        {       save = ptr->nxt;
        !            21:                free(ptr);
        !            22:                ptr = save;
        !            23:        }
        !            24:        frst = (Node *) 0;
        !            25: }
        !            26: 
        !            27: addnode(n, m, p)
        !            28: {      Node *tmp, *hunt, *last;
        !            29: 
        !            30:        tmp = (Node *) malloc(sizeof(Node));
        !            31:        if (!tmp)
        !            32:                return;
        !            33: 
        !            34:        tmp->nxt = (Node *) 0;
        !            35:        tmp->x = n;
        !            36:        tmp->y = m;
        !            37:        tmp->soc = p;
        !            38:        if (!frst)
        !            39:                frst = tmp;
        !            40:        else
        !            41:        {       last = frst; hunt = last->nxt;
        !            42:                while (hunt)
        !            43:                {       last = hunt;
        !            44:                        hunt = last->nxt;
        !            45:                }
        !            46:                last->nxt = tmp;
        !            47:        }
        !            48: }
        !            49: 
        !            50: compar(a, b)
        !            51:        int *a, *b;
        !            52: {
        !            53:        return (*a>*b)?1:(*a<*b)?-1:0;
        !            54: }
        !            55: 
        !            56: runcontour()
        !            57: {      Node *hunt;
        !            58:        int miny, maxy;
        !            59:        int *xx, *yy;
        !            60:        int x, y, cnt, total, partial;
        !            61: 
        !            62:        if (!frst)
        !            63:                return;
        !            64: 
        !            65:        hunt = frst;
        !            66:        miny = hunt->y; maxy = hunt->y;
        !            67:        cnt = 0;
        !            68:        while (hunt)
        !            69:        {       if (hunt->y < miny) miny = hunt->y;
        !            70:                if (hunt->y > maxy) maxy = hunt->y;
        !            71:                hunt = hunt->nxt;
        !            72:                cnt++;
        !            73:        }
        !            74:        xx = (int *) malloc(cnt * sizeof(int)); /* max # intersections */
        !            75:        yy = (int *) malloc(cnt * sizeof(int)); /* max # intersections */
        !            76:        if (!xx || !yy)
        !            77:        {       fprintf (stderr, "out of memory\n");
        !            78:                return;
        !            79:        }
        !            80:        for (y = miny; y < maxy; y++)
        !            81:        {       if ((cnt = intersect(xx, y)) <= 1)
        !            82:                        continue;
        !            83:                qsort(xx, cnt, sizeof(int), compar);
        !            84: /* scale */
        !            85:                for (x = 0; x < cnt-1; x += 2)
        !            86:                {       if (x == 0)
        !            87:                                yy[0]   = xx[0] - (xx[0]*Factor)/100;
        !            88:                        else
        !            89:                                yy[x]   = xx[x] - ((xx[x]-xx[x-1])*Factor)/200;
        !            90:                        if (x+1 == cnt-1)
        !            91:                                yy[x+1] = xx[x+1] + ((SZ - xx[x+1])*Factor)/100;
        !            92:                        else
        !            93:                                yy[x+1] = xx[x+1] + ((xx[x+2]-xx[x+1])*Factor)/200;
        !            94:                }
        !            95:                for (x = 0; x < cnt; x++)
        !            96:                        xx[x] = yy[x];
        !            97: /* end scale */
        !            98:                for (x = total = 0; x < cnt-1; x += 2)
        !            99:                        total += xx[x+1] - xx[x];
        !           100:                for (x = partial = 0; x < cnt-1; x += 2)
        !           101:                {       doline(xx[x], xx[x+1], SZ-y, partial, total);
        !           102:                        partial += xx[x+1] - xx[x];
        !           103:        }       }
        !           104:        free(xx);
        !           105: }
        !           106: 
        !           107: doline(a, b, c, p, t)
        !           108: {      int q;
        !           109: 
        !           110:        if (a >= b) return;
        !           111:        lcnt++;
        !           112:        if (lcnt%100 == 0)
        !           113:                printf("}\ndef curve%d() {\n", lcnt);
        !           114:        if (b-a == t)
        !           115:                printf("mapper(%d,%d,0,%d,%d)\n", a, b, SZ-1, c);
        !           116:        else
        !           117:        {       if (p == 0)
        !           118:                {       printf("setter(0, %d, %d, %d)\n", a, c, c*255/(SZ-1));
        !           119:                        printf("mapper(%d,%d,0,(%d*%d)/%d,%d)\n",a,b,SZ-1,b-a,t,c);
        !           120:                } else
        !           121:                {       printf("x=(%d*%d)/%d;\n", SZ-1, p, t);
        !           122:                        printf("y=x+(%d*%d)/%d;\n", SZ-1, (b-a), t);
        !           123:                        printf("mapper(%d,%d,x,y,%d)\n", a, b, c);
        !           124:                        if (p+b-a == t)
        !           125:                        printf("setter(%d, %d, %d, %d)\n",b,SZ-1,c,c*255/(SZ-1));
        !           126:                }
        !           127:        }
        !           128: }
        !           129: 
        !           130: #define Sign(n)        ((n>0)?1:0)     
        !           131: 
        !           132: intersect(xx, y)
        !           133:        int *xx;
        !           134: {
        !           135:        Node *hunt, *last;
        !           136:        int i, j, n, m;
        !           137:        int nhit=0;
        !           138: 
        !           139:        last = frst;
        !           140:        hunt = last->nxt;
        !           141:        while (hunt)
        !           142:        {       n = last->y - y;
        !           143:                m = hunt->y - y;
        !           144:                if (Sign(n) != Sign(m))
        !           145:                {       i = last->x; j = hunt->x;
        !           146:                        if (hunt->x > last->x)
        !           147:                                xx[nhit++] = i + (j-i)*n/(n-m);
        !           148:                        else
        !           149:                                xx[nhit++] = i - (i-j)*n/(n-m);
        !           150:                } /* else if (n == 0 && m == 0)
        !           151:                {       if (hunt->x > last->x)
        !           152:                                doline(last->x, hunt->x, SZ-y);
        !           153:                        else
        !           154:                                doline(hunt->x, last->x, SZ-y);
        !           155:                } */
        !           156:                last = hunt;
        !           157:                hunt = last->nxt;
        !           158:                if (hunt && hunt->soc)
        !           159:                {       last = hunt;
        !           160:                        hunt = last->nxt;
        !           161:                }
        !           162:        }
        !           163:        return nhit;
        !           164: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.