megadrive_test2

view 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 source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
5 #define XSZ 512
6 #define YSZ 512
8 int main(void)
9 {
10 int i, j;
11 unsigned char *pixels, *pptr;
13 pixels = malloc(XSZ * YSZ);
14 pptr = pixels;
16 for(i=0; i<YSZ; i++) {
17 float y = 2.0 * (float)i / (float)YSZ - 1.0;
18 for(j=0; j<XSZ; j++) {
19 float x = 2.0 * (float)j / (float)XSZ - 1.0;
20 float tu = atan2(y, x) / M_PI * 0.5 + 0.5;
21 float d = sqrt(x * x + y * y);
22 float tv = d == 0.0 ? 0.0 : 1.0 / d;
24 int ty = (int)(tv * 64.0) & 0xf;
25 int tx = (int)(tu * 256.0) & 0xf;
27 *pptr++ = tx ? ty : 0;
28 }
29 }
31 pptr = pixels;
32 printf("P6\n%d %d\n15\n", XSZ, YSZ);
34 for(i=0; i<YSZ; i++) {
35 for(j=0; j<XSZ; j++) {
36 unsigned char c = *pptr++;
37 putchar(c);
38 putchar(c);
39 putchar(c);
40 }
41 }
42 fflush(stdout);
44 return 0;
45 }