6 int main(int argc, char **argv)
8 int i, j, xsz = 240, ysz = 160, texsz = 128;
9 struct vec2 *tunbuf, *tun;
12 for(i=1; i<argc; i++) {
13 if(argv[i][0] == '-') {
14 if(argv[i][2] != 0) goto invalopt;
17 if(sscanf(argv[++i], "%dx%d", &xsz, &ysz) != 2 || xsz <= 1 || ysz <= 1) {
18 fprintf(stderr, "-s must be followed by WxH\n");
24 if(!(texsz = atoi(argv[++i])) || texsz > 256) {
25 fprintf(stderr, "-t must be followed by the texture size (1-256)\n");
34 invalopt: fprintf(stderr, "invalid argument: %s\n", argv[i]);
39 FILE *fp = fopen("tun_preview.ppm", "wb");
41 fprintf(fp, "P6\n%d %d\n255\n", xsz, ysz);
44 aspect = (float)xsz / (float)ysz;
47 for(i=0; i<ysz; i++) {
48 float y = 2.0f * (float)i / (float)(ysz - 1) - 1.0f;
49 for(j=0; j<xsz; j++) {
50 float x = (2.0f * (float)j / (float)(xsz - 1) - 1.0f) * aspect;
52 float r = sqrt(x * x + y * y);
53 float theta = atan2(y, x);
55 float u = 0.5f * theta / M_PI + 0.5f;
58 uint32_t out = ((uint32_t)(u * 65535.0f) & 0xffff) |
59 (((uint32_t)(v * 65535.0f) & 0xffff) << 16);
60 fwrite(&out, sizeof out, 1, stdout);
63 int cr = (int)(u * 2048.0f) & 0xff;
64 int cb = (int)(r * 2048.0f) & 0xff;