X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Ftungen.c;h=62e0d637aa28ed7a0d846b40ffd3c3e7d2dde9d8;hb=ff74cf463fa44906add9344891096cada0970205;hp=4849ec3fd2097a32ecb9ec8e345f7d1eb1f63797;hpb=4f58871ec2e25fb8cd7dfc19d1e4999453cf9555;p=gbajam21 diff --git a/tools/tungen.c b/tools/tungen.c index 4849ec3..62e0d63 100644 --- a/tools/tungen.c +++ b/tools/tungen.c @@ -3,11 +3,16 @@ #include #include +struct vec2 { + float x, y; +}; + int main(int argc, char **argv) { - int i, j, xsz = 240, ysz = 160, texsz = 128; + int i, j, imgrad, xsz = 240, ysz = 160, texsz = 128; struct vec2 *tunbuf, *tun; - float aspect; + float aspect, prev_r; + struct vec2 *buf, *ptr; for(i=1; i= 0 && x < xsz && y >= 0 && y < ysz) { + ptr = buf + y * xsz + x; + ptr->x = u; + ptr->y = v * 8; + } + } + prev_r = r; + } + FILE *fp = fopen("tun_preview.ppm", "wb"); if(fp) { fprintf(fp, "P6\n%d %d\n255\n", xsz, ysz); @@ -43,28 +81,29 @@ invalopt: fprintf(stderr, "invalid argument: %s\n", argv[i]); aspect = (float)xsz / (float)ysz; - tun = tunbuf; + ptr = buf; for(i=0; ix; + float v = ptr->y; + int r = (int)(u * 8.0 * 255.0f) & 0xff; + int g = (int)(v * 8.0 * 255.0f) & 0xff; + int b = (~(int)(v * 0.5 * 255.0f) & 0xff) + 105; + if(b > 255) b = 255; + if(b < 0) b = 0; - float r = sqrt(x * x + y * y); - float theta = atan2(y, x); + /*if(v > 2.0) r = g = b = 0;*/ - float u = 0.5f * theta / M_PI + 0.5f; - float v = r; + ptr++; - uint32_t out = ((uint32_t)(u * 65535.0f) & 0xffff) | - (((uint32_t)(v * 65535.0f) & 0xffff) << 16); + uint16_t out = ((uint16_t)(u * 255.0f) & 0xff) | + (((uint16_t)(v * 255.0f) & 0xff) << 8); fwrite(&out, sizeof out, 1, stdout); if(fp) { - int cr = (int)(u * 2048.0f) & 0xff; - int cb = (int)(r * 2048.0f) & 0xff; - fputc(cr, fp); - fputc(0, fp); - fputc(cb, fp); + fputc(r, fp); + fputc(g, fp); + fputc(b, fp); } } }