megadrive_test2

diff tools/tunnel.c @ 4:72ab63f262bf

tiles
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 19 Jun 2017 08:02:51 +0300
parents
children ea70f3da150f
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/tunnel.c	Mon Jun 19 08:02:51 2017 +0300
     1.3 @@ -0,0 +1,45 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <math.h>
     1.7 +
     1.8 +#define XSZ		512
     1.9 +#define YSZ		512
    1.10 +
    1.11 +int main(void)
    1.12 +{
    1.13 +	int i, j;
    1.14 +	unsigned char *pixels, *pptr;
    1.15 +
    1.16 +	pixels = malloc(XSZ * YSZ);
    1.17 +	pptr = pixels;
    1.18 +
    1.19 +	for(i=0; i<YSZ; i++) {
    1.20 +		float y = 2.0 * (float)i / (float)YSZ - 1.0;
    1.21 +		for(j=0; j<XSZ; j++) {
    1.22 +			float x = 2.0 * (float)j / (float)XSZ - 1.0;
    1.23 +			float tu = atan2(y, x) / M_PI * 0.5 + 0.5;
    1.24 +			float d = sqrt(x * x + y * y);
    1.25 +			float tv = d == 0.0 ? 0.0 : 1.0 / d;
    1.26 +
    1.27 +			int ty = (int)(tv * 64.0) & 0xf;
    1.28 +			int tx = (int)(tu * 256.0) & 0xf;
    1.29 +
    1.30 +			*pptr++ = tx ? ty : 0;
    1.31 +		}
    1.32 +	}
    1.33 +
    1.34 +	pptr = pixels;
    1.35 +	printf("P6\n%d %d\n15\n", XSZ, YSZ);
    1.36 +
    1.37 +	for(i=0; i<YSZ; i++) {
    1.38 +		for(j=0; j<XSZ; j++) {
    1.39 +			unsigned char c = *pptr++;
    1.40 +			putchar(c);
    1.41 +			putchar(c);
    1.42 +			putchar(c);
    1.43 +		}
    1.44 +	}
    1.45 +	fflush(stdout);
    1.46 +
    1.47 +	return 0;
    1.48 +}