megadrive_test2

diff 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 diff
     1.1 --- a/tools/tunnel.c	Mon Jun 19 08:02:51 2017 +0300
     1.2 +++ b/tools/tunnel.c	Tue Jun 20 06:08:58 2017 +0300
     1.3 @@ -2,13 +2,14 @@
     1.4  #include <stdlib.h>
     1.5  #include <math.h>
     1.6  
     1.7 -#define XSZ		512
     1.8 -#define YSZ		512
     1.9 +#define XSZ		320
    1.10 +#define YSZ		240
    1.11  
    1.12  int main(void)
    1.13  {
    1.14  	int i, j;
    1.15  	unsigned char *pixels, *pptr;
    1.16 +	float aspect = (float)XSZ / (float)YSZ;
    1.17  
    1.18  	pixels = malloc(XSZ * YSZ);
    1.19  	pptr = pixels;
    1.20 @@ -16,15 +17,19 @@
    1.21  	for(i=0; i<YSZ; i++) {
    1.22  		float y = 2.0 * (float)i / (float)YSZ - 1.0;
    1.23  		for(j=0; j<XSZ; j++) {
    1.24 -			float x = 2.0 * (float)j / (float)XSZ - 1.0;
    1.25 +			float x = aspect * (2.0 * (float)j / (float)XSZ - 1.0);
    1.26  			float tu = atan2(y, x) / M_PI * 0.5 + 0.5;
    1.27  			float d = sqrt(x * x + y * y);
    1.28 -			float tv = d == 0.0 ? 0.0 : 1.0 / d;
    1.29 +			float tv = d == 0.0 ? 0.0 : 0.5 / d;
    1.30  
    1.31 -			int ty = (int)(tv * 64.0) & 0xf;
    1.32 +			int ty = (int)(tv * 64.0) % 14 + 1;
    1.33  			int tx = (int)(tu * 256.0) & 0xf;
    1.34  
    1.35 -			*pptr++ = tx ? ty : 0;
    1.36 +			if(d < 0.2) {
    1.37 +				*pptr++ = 0;
    1.38 +			} else {
    1.39 +				*pptr++ = tx ? ty : 0xf;
    1.40 +			}
    1.41  		}
    1.42  	}
    1.43