From: Thomas T. <tt...@bi...> - 2000-04-30 22:51:09
|
Hi folks, I just generated a new dither with a rather simple algorithm that starts with 3 pixels you choose manually, and then continues finding the position that has the largest total distance from all the pixels that are already on. The distance per pixel is mangled before it is added to the total, otherwise things do not work. The dither is a bit too regular to my taste, but it works well. The good thing: ordered dither is not splotchy any more, although a few light speckles remain. Ordered dither output is now fully acceptible even though the matrix looks a tad too regular to me. All irregularities follow from placement of the 3 initial pixels - that is not much. This is a 73x73 matrix. It is 401 lines of C source. What shall I do with it? Put it in my CVS directory, and then use some magic CVS command to bring it to sourceforge? The program used to generate it is fairly short but takes about 5 hours to run on my (333MHz PII) machine. I think it could use a tiny bit of randomization. I'll try that soon. Any suggestions/instructions on what to do with the generated matrix? When I'm happy with randomization I could build a 113 x 113 matrix in a few days CPU. /* Dither matrix generation */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #define HSIZE 73 #define VSIZE 73 #define HSIZE2 (HSIZE/2) #define VSIZE2 (VSIZE/2) #define TRUE 1 #define FALSE 0 /* X1, Y1, etc are initial bits to be set in the matrix. Choose well!! */ #define X1 2 #define Y1 1 #define X2 48 #define Y2 24 #define X3 24 #define Y3 49 int main(void) { int x, y, xd, yd, i, j, bitcount, largehole, largetotal, result[HSIZE*VSIZE]; float distance, thishole, maximum, total; int initial[HSIZE*VSIZE]; /* Set up array with zeroes and a number of 'ones' */ bitcount=0; for ( x=0; x<HSIZE; ++x ) for ( y=0; y<VSIZE; ++y ) { initial[x+y*HSIZE]=FALSE; result[x+y*HSIZE]=0; } initial[X1+Y1*HSIZE]=TRUE; result[X1+Y1*HSIZE]=bitcount++; initial[X2+Y2*HSIZE]=TRUE; result[X2+Y2*HSIZE]=bitcount++; initial[X3+Y3*HSIZE]=TRUE; result[X3+Y3*HSIZE]=bitcount++; while (bitcount < VSIZE*HSIZE) { maximum=0; /* Start looking for the largest hole */ for ( i=0; i<HSIZE; ++i ) for ( j=0; j<VSIZE; ++j ) { total=0; /* check only if it is a hole right now */ if (initial[i+j*HSIZE]==FALSE) { for ( x=0; x<HSIZE; ++x ) for ( y=0; y<VSIZE; ++y ) /* scan all positions, find distance, munge and add */ if (initial[x+y*HSIZE]==TRUE) { xd = abs(x - i); yd = abs(y - j); if (xd > HSIZE2) xd = HSIZE - xd; if (yd > VSIZE2) yd = VSIZE - yd; distance = sqrt(xd*xd+yd*yd); total+=(1-1/distance); } if (total > maximum) { /* it is the largest so far */ largetotal = i+j*HSIZE; maximum = total; } } } /* put a "1" in the largest hole */ initial[largetotal] = TRUE; result[largetotal]=bitcount++; /* print the result so far */ for ( i=0; i<HSIZE; ++i ) { for ( j=0; j<VSIZE; ++j ) if (initial[i+j*HSIZE]) printf("@"); else printf("-"); printf("\n"); } } /* print result */ printf("\n\n"); for (j=0; j<HSIZE*VSIZE; ++j) printf("%d, ",result[j]); printf("\n\n"); } |