Category talk:Go images

From Wikimedia Commons, the free media repository
Jump to: navigation, search

Sourcecode[edit]

To reproduce these images, save the following Metapost program as Go_template.mp:

 scale=0.6in;   % scale is the diameter of a stone
 linethickness = scale/25;
 pickup pencircle scaled linethickness;
 num = 500;  % Levels of shading in each stone.
 
 lx = -0.35;
 ly = 0.35;
 lz = sqrt(1-lx*lx-ly*ly);
   % light source direction vector.
   % note that lz = cos(ltip).
 ltheta = angle(lx, ly);
 ltip = angle(lz, lx++ly);
   % the angle at which the light source is tipped.
 
 path ellipse;
 ellipse := fullcircle scaled scale xscaled lz;
 
 color boardcolor;
 boardcolor = (0.86,0.70,0.36);
 
 % Draw a black and a white stone:
 picture blackstone;
 blackstone = currentpicture;
 addto blackstone contour fullcircle scaled scale;

 picture whitestone;
 whitestone = currentpicture;
 basewhite = 0.7;
 addto whitestone contour fullcircle scaled scale
    withcolor (basewhite*white);
 
 for ratio = 1 step -1/num until 0 :
   path ourellipse;
   ourellipse = ellipse scaled ratio
     shifted (scale*(1+-+ratio)*sind(ltip)/2, 0)
     rotated ltheta;
 
   addto blackstone contour ourellipse withcolor (0.7*(1+-+ratio)**2*white);
   addto whitestone contour ourellipse withcolor
     (basewhite + (1-basewhite)*((1+-+ratio)**4))*white;
 endfor;


 def foo(expr fig) =
  beginfig(fig);
   pickup pencircle scaled linethickness;
   fill unitsquare scaled scale shifted (-0.5scale,-0.5scale)
     withcolor boardcolor;
   linecap := butt;
   bar;
  endfig;
  beginfig(fig+1);
   pickup pencircle scaled linethickness;
   fill unitsquare scaled scale shifted (-0.5scale,-0.5scale)
     withcolor boardcolor;
   linecap := butt;
   bar;
   pickup pencircle scaled (2*linethickness);
   draw fullcircle scaled (scale/2) withcolor red;
  endfig;
 enddef;

 def bar =
  draw (0,-0.5scale)--(0,0)--(0.5scale,0);
 enddef;
 foo(1);

 def bar =
   draw (-0.5scale,0)--(0.5scale,0);
   draw (0,-0.5scale)--(0,0);
 enddef;
 foo(3);

 def bar =
   draw (-0.5scale,0)--(0,0)--(0,-0.5scale);
 enddef;
 foo(5);

 def bar =
   draw (0,0.5scale)--(0,-0.5scale);
   draw (-0.5scale,0)--(0,0);
 enddef;
 foo(7);

 def bar =
   draw (0,0.5scale)--(0,0)--(-0.5scale,0);
 enddef;
 foo(9);

 def bar =
   draw (0.5scale,0)--(-0.5scale,0);
   draw (0,0.5scale)--(0,0);
 enddef;
 foo(11);

 def bar =
   draw (0.5scale,0)--(0,0)--(0,0.5scale);
 enddef;
 foo(13);

 def bar =
   draw (0,-0.5scale)--(0,0.5scale);
   draw (0.5scale,0)--(0,0);
 enddef;
 foo(15);

 def bar =
   draw (-0.5scale,0)--(0.5scale,0);
   draw (0,-0.5scale)--(0,0.5scale);
 enddef;
 foo(17);

 def bar =
   draw (-0.5scale,0)--(0.5scale,0);
   draw (0,-0.5scale)--(0,0.5scale);
   pickup pencircle scaled (2*linethickness);
   draw (0,0);
 enddef;
 foo(19);

 beginfig(21);
   fill unitsquare scaled scale shifted (-0.5scale,-0.5scale)
     withcolor boardcolor;
   draw blackstone;
 endfig;

 beginfig(22);
   fill unitsquare scaled scale shifted (-0.5scale,-0.5scale)
     withcolor boardcolor;
   draw whitestone;
 endfig;

 beginfig(23);
   fill unitsquare scaled scale shifted (-0.5scale,-0.5scale)
     withcolor boardcolor;
   draw blackstone;
   draw thelabel("1", (0,0)) scaled (0.75*scale/10pt)
     withcolor white;
 endfig;

 beginfig(24);
   fill unitsquare scaled scale shifted (-0.5scale,-0.5scale)
     withcolor boardcolor;
   draw whitestone;
   draw thelabel("2", (0,0)) scaled (0.75*scale/10pt)
     withcolor black;
 endfig;

end;

and save the following as Go_template.tex:

\documentclass[10pt]{article}
 \usepackage{graphicx}
 \pagestyle{empty}
\begin{document}
 \includegraphics{\fig}
\end{document}

Then run

mpost Go_template
for num in 23 24; do
  latex "\def\fig{Go_template.$num} \input Go_template";
  dvips -mode lwpro -D 800 Go_template.dvi -o Go_template.ps.$num;
  mv -f Go_template.ps.$num Go_template.$num;
done
for name in Go_template.{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24}; do
  convert -density 800 $name $name.pnm;
  pnmcrop $name.pnm | pnmtopng > $name.png.uncrush;
  pngcrush -reduce -brute -l 9 $name.png.uncrush $name.png;
  rm -f $name $name.{pnm,png.uncrush};
done