X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=tools%2Ftungen.c;h=ec21217dd74839d44774b0c0194f291cc10cc526;hb=b88c03f1cf5b5f66bec905e5b43e797abf8c18e0;hp=8122c9508ad47b00fea5e5d5d616d55528087dc2;hpb=fb94d0fa89684121874bb3a4b0cb51172cab4a90;p=gbajam21 diff --git a/tools/tungen.c b/tools/tungen.c index 8122c95..ec21217 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,32 +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 = 0.8f / 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); } } }