// how many lines and columns
#declare Width = 35;

// calculate some board values
#declare linespace = 20.0 / Width;
#declare stonesize = linespace * 10 / 11;
#declare Jitter = linespace - stonesize;

#declare cl = 5;

#if (cl = 1)
  #declare press=1;
#else
  #declare press=0;
#end

#include "colors.inc"
#include "stones.inc"
#include "woodTexture.inc"

#include "board.inc"
#include "lines.inc"


#declare R1=seed(432);
#declare R2=seed(432);
#declare R3=seed(152);
#declare R4=seed(968);
#declare R5=seed(536);
#declare R6=seed(674);
#declare R7=seed(521);

#declare Pos1 = mod(cl, 3);
#declare Pos2 = div(cl, 3);

#declare xp = 1;
#while (xp <= Width)
  #declare yp = 1;
  #while (yp <= Width)
    #declare h1 = mod(xp + yp, 2);
    #if (((h1 = 0) & (Pos1 = 1)) | ((h1 = 1) & (Pos2 = 1)))
      sphere {
        <0,0,0> stonesize scale <0.5,0.5,0.2> translate z*0.1
        texture {
	  T_Stone16 scale 0.6 
	  translate <rand(R1)*200, rand(R1)*213, rand(R1)*321>
	}
	scale <rand(R5)*0.2+0.8, rand(R5)*0.2+0.8, 1> 
	rotate x*(rand(R5)*20-10) rotate y*(rand(R5)*20-10) rotate z*rand(R5)*90
	translate <0.55-linespace/2+xp*linespace+rand(R4)*Jitter-Jitter/2, 
	           0.55-linespace/2+yp*linespace+rand(R4)*Jitter-Jitter/2, 0>
      }
    #else
      #declare h = rand(R1);  #declare h = rand(R1);  #declare h = rand(R1);
      #declare h = rand(R5);  #declare h = rand(R5);
      #declare h = rand(R5);  #declare h = rand(R5);  #declare h = rand(R5);
      #declare h = rand(R4);  #declare h = rand(R4);
    #end
    #if (((h1 = 0) & (Pos1 = 2)) | ((h1 = 1) & (Pos2 = 2)))
      sphere {
        <0,0,0> stonesize scale <0.5,0.5,0.2> translate z*0.1
  	texture {
	  T_Stone17 scale 0.6 
	  translate <rand(R2)*200, rand(R2)*213, rand(R2)*321>
	}
	scale <rand(R6)*0.2+0.8, rand(R6)*0.2+0.8, 1> 
	rotate x*(rand(R6)*20-10) rotate y*(rand(R6)*20-10) rotate z*rand(R6)*90
	translate <0.5-linespace/2+xp*linespace+rand(R7)*Jitter-Jitter/2, 
	           0.5-linespace/2+yp*linespace+rand(R7)*Jitter-Jitter/2, 0> 
      }
    #else
      #declare h = rand(R2);  #declare h = rand(R2);  #declare h = rand(R2);
      #declare h = rand(R6);  #declare h = rand(R6);
      #declare h = rand(R6);  #declare h = rand(R6);  #declare h = rand(R6);
      #declare h = rand(R7);  #declare h = rand(R7);
    #end
  #declare yp = yp + 1;
  #end
#declare xp = xp + 1;
#end

light_source { <11,0, 20> color 0.7 }
light_source { <0,11, 20> color 0.3 }

camera { 
  sky y right -x up y angle 55
  location <10.5, 10.5, 20.0> 
  look_at <10.5, 10.5, 0> 
}