megadrive_test2

view tools/tunnel.c @ 5:ea70f3da150f

color cycling tunnel
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 20 Jun 2017 06:08:58 +0300
parents 72ab63f262bf
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
5 #define XSZ 320
6 #define YSZ 240
8 int main(void)
9 {
10 int i, j;
11 unsigned char *pixels, *pptr;
12 float aspect = (float)XSZ / (float)YSZ;
14 pixels = malloc(XSZ * YSZ);
15 pptr = pixels;
17 for(i=0; i<YSZ; i++) {
18 float y = 2.0 * (float)i / (float)YSZ - 1.0;
19 for(j=0; j<XSZ; j++) {
20 float x = aspect * (2.0 * (float)j / (float)XSZ - 1.0);
21 float tu = atan2(y, x) / M_PI * 0.5 + 0.5;
22 float d = sqrt(x * x + y * y);
23 float tv = d == 0.0 ? 0.0 : 0.5 / d;
25 int ty = (int)(tv * 64.0) % 14 + 1;
26 int tx = (int)(tu * 256.0) & 0xf;
28 if(d < 0.2) {
29 *pptr++ = 0;
30 } else {
31 *pptr++ = tx ? ty : 0xf;
32 }
33 }
34 }
36 pptr = pixels;
37 printf("P6\n%d %d\n15\n", XSZ, YSZ);
39 for(i=0; i<YSZ; i++) {
40 for(j=0; j<XSZ; j++) {
41 unsigned char c = *pptr++;
42 putchar(c);
43 putchar(c);
44 putchar(c);
45 }
46 }
47 fflush(stdout);
49 return 0;
50 }