tavli

diff src/board.cc @ 5:e48b40a3c82a

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 25 Jun 2015 20:43:34 +0300
parents b41ceead1708
children a0d30f6f20d4
line diff
     1.1 --- a/src/board.cc	Thu Jun 25 05:58:35 2015 +0300
     1.2 +++ b/src/board.cc	Thu Jun 25 20:43:34 2015 +0300
     1.3 @@ -141,6 +141,22 @@
     1.4  	return true;
     1.5  }
     1.6  
     1.7 +static float wood(float x, float y)
     1.8 +{
     1.9 +	float u = x;
    1.10 +	float v = y;
    1.11 +	x += 1.0;
    1.12 +	x *= 10.0;
    1.13 +	y *= 20.0;
    1.14 +
    1.15 +	float len = sqrt(x * x + y * y) + turbulence2(u * 6.0, v * 12.0, 2) * 1.2 +
    1.16 +		turbulence2(u * 0.5, v, 2) * 15.0;
    1.17 +	float val = fmod(len, 1.0);
    1.18 +
    1.19 +	//val = val * 0.5 + 0.5;
    1.20 +	return val < 0.0 ? 0.0 : (val > 1.0 ? 1.0 : val);
    1.21 +}
    1.22 +
    1.23  static bool spike(float x, float y)
    1.24  {
    1.25  	x = fmod(x * 5.0, 1.0);
    1.26 @@ -169,14 +185,15 @@
    1.27  
    1.28  bool Board::generate_textures()
    1.29  {
    1.30 +	static const Vector3 wcol1 = Vector3(0.6, 0.4, 0.2);
    1.31 +	static const Vector3 wcol2 = Vector3(0.53, 0.32, 0.1);//Vector3(0.38, 0.25, 0.08);
    1.32 +
    1.33  	const int xsz = 512;
    1.34  	const int ysz = 1024;
    1.35  
    1.36  	img_field.create(xsz, ysz);
    1.37 -	clear_image(&img_field, 0, 0, 0);
    1.38  
    1.39  	unsigned char *pptr = img_field.pixels;
    1.40 -
    1.41  	for(int i=0; i<ysz; i++) {
    1.42  		float v = (float)i / (float)ysz;
    1.43  
    1.44 @@ -185,6 +202,9 @@
    1.45  
    1.46  			int r = 0, g = 0, b = 0;
    1.47  
    1.48 +			float wood_val = wood(u, v);
    1.49 +
    1.50 +			// pattern mask
    1.51  			float x = u;
    1.52  			float y = v < 0.5 ? v * 2.0 : 2.0 - v * 2.0;
    1.53  			bool inside = false;
    1.54 @@ -196,13 +216,18 @@
    1.55  				(diamond(x, y - 0.023) && !diamond(x, y - 0.028));
    1.56  			inside |= center_circle(x, y, 0.03);
    1.57  
    1.58 +			Vector3 wood_color = lerp(wcol1, wcol2, wood_val) * 0.9;
    1.59  			if(inside) {
    1.60 -				r = g = b = 255;
    1.61 +				wood_color = lerp(wcol1, wcol2, 1.0 - wood_val) * 2.0;
    1.62  			}
    1.63  
    1.64 -			pptr[0] = r;
    1.65 -			pptr[1] = g;
    1.66 -			pptr[2] = b;
    1.67 +			r = (int)(wood_color.x * 255.0);
    1.68 +			g = (int)(wood_color.y * 255.0);
    1.69 +			b = (int)(wood_color.z * 255.0);
    1.70 +
    1.71 +			pptr[0] = r > 255 ? 255 : r;
    1.72 +			pptr[1] = g > 255 ? 255 : g;
    1.73 +			pptr[2] = b > 255 ? 255 : b;
    1.74  			pptr += 3;
    1.75  		}
    1.76  	}