Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create a Go stone in TikZ. "ball color" option in node style is almost OK.
Here is my result:

alt text

But I don't like the stones, they are "too balish". The "reflection" should be less spot-on and more ambient.

I could get such a result if I could manipulate both shading colors or shading curve. Can I do it in TikZ?

Here is what I want to achieve:

alt text

PS. Any ideas to render wood-like background w/o texture?

share|improve this question
    
MAybe I should use inkscape to draw stone and use it in TikZ? Is it possible to import a drawing from inkspace to Tikz? –  Łukasz Lew Aug 18 '10 at 14:14
    
You can easily with the traditional \includegraphics (which I use). pgf also offers something similar for this. –  Leo Liu Aug 18 '10 at 14:21
    
But you have gotten pretty close to what you want just needs a bit of tweaking. –  Leo Liu Aug 18 '10 at 14:21
    
Will \pgfimage allow you to position stone graphics at will? –  Mikael Vejdemo-Johansson Aug 18 '10 at 14:27
    
The question regarding a wood-like background could be discussed in a separate question. It doesn't fit to the original question and its title. –  Stefan Kottwitz Aug 18 '10 at 14:35

3 Answers 3

You can get an effect like the shading on the go stones in the picture with radial shading. I don't know how to get radial shading off-center, so some clipping is needed:

\begin{tikzpicture}
    \begin{scope}
        \fill[black] (0,0) circle (0.5);
        \clip (0,0) circle (0.5);
        \shade[outer color=black, inner color=black!30] (-0.15,0.5) circle (0.7);
    \end{scope}
\end{tikzpicture}

an example

The scope is needed in order to have the clipping only applied to the shading.


I had some time to kill and the following is the result:

go board example

This is produced with the following code

\usetikzlibrary{calc,shadows}

\newenvironment{goboard}{%
    \begin{tikzpicture}[
        scale=0.5,
        stone/.style={drop shadow={shadow xshift=0.03, shadow yshift=-0.05}},
        black-stone/.style={black!80},
        black-highlight/.style={outer color=black!80, inner color=black!30},
        black-number/.style={white},
        white-stone/.style={white!70!black},
        white-highlight/.style={outer color=white!70!black, inner color=white},
        white-number/.style={black}]
        \fill[brown!80] (-1,-1) rectangle (19,19);
        \draw[black] (0,0) grid (18,18);
        \draw[thick,black] (0,0) rectangle (18,18);
        \fill (3,3) circle (0.1);
        \fill (3,9) circle (0.1);
        \fill (3,15) circle (0.1);
        \fill (9,3) circle (0.1);
        \fill (9,9) circle (0.1);
        \fill (9,15) circle (0.1);
        \fill (15,3) circle (0.1);
        \fill (15,9) circle (0.1);
        \fill (15,15) circle (0.1);
    }{%
    \end{tikzpicture}
    }

\newcommand\gostone[4][]{%
    \begin{scope}
        \fill[stone,#2-stone] (#3,#4) circle (0.45);
        \clip (#3,#4) circle (0.45);
        \shade[#2-highlight] (-0.15+#3,0.5+#4) circle (0.7);
    \end{scope}
    \node[#2-number] at (#3,#4) {\sffamily\bfseries{#1}};
}

\begin{goboard}
    \gostone[4]{black}{2}{2}
    \gostone{black}{3}{3}
    \gostone[2]{black}{2}{5}
    \gostone[3]{white}{3}{1}
    \gostone[1]{white}{5}{2}
    \gostone[5]{white}{8}{2}
\end{goboard}

The syntax for the goboard environment and \gostone command is modeled after the psgo package.

share|improve this answer
    
This is almost perfect! Can I create style for node that will look like that? Or do I have to create new command ? –  Łukasz Lew Aug 18 '10 at 15:42
    
ball shading is an option. –  Łukasz Lew Aug 18 '10 at 15:43
    
@Łukasz: I don't know how to do this as a node, but I updated the answer with some code to automate the drawing. –  Caramdir Aug 18 '10 at 16:03

This only concerns your additional question, e.g. how to get such a "wood like" background:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,spy}

\begin{document}

% parameters for the "wooden rectangle", chosen to be measures of a Go board
\pgfmathsetmacro{\relativefibrethickness}{0.50}
\pgfmathsetmacro{\relativefibrevariation}{0.07}
\pgfmathsetmacro{\numberoffibres}{84}
\pgfmathsetmacro{\fibresteps}{84}
\pgfmathsetmacro{\boardwidth}{20}
\pgfmathsetmacro{\boardheight}{20}
\newcommand{\backgroundcolor}{brown}
\newcommand{\fibrecolor}{brown!90!black}

\begin{tikzpicture}[scale=0.5,spy using outlines={circle, size=7cm, connect spies}]
    %auto generated wood board  
    \filldraw[\backgroundcolor] (0,0) rectangle (\boardwidth,\boardheight);

    \pgfmathsetmacro{\segmentwidth}{\boardwidth/(\numberoffibres+1)}
    \pgfmathsetmacro{\segmentvariation}{\relativefibrethickness/2*\segmentwidth}

    \pgfmathsetmacro{\secondfibre}{2*\segmentwidth}
    \pgfmathsetmacro{\lastfibre}{\numberoffibres*\segmentwidth}

    \pgfmathsetmacro{\stepheight}{\boardheight/\fibresteps}

    \foreach \x in {1,2,...,\numberoffibres}
    {   \fill[\fibrecolor] ($(\x*\segmentwidth-\segmentvariation,0) + (rand*\relativefibrevariation*\relativefibrethickness,0)$) 
        \foreach \y in {1,...,\fibresteps}
        {   -- ($(\x*\segmentwidth-\segmentvariation,\y*\stepheight) + (rand*\relativefibrevariation*\relativefibrethickness,0)$)
        }
        -- ($(\x*\segmentwidth+\segmentvariation,\boardheight)+ (rand*\relativefibrevariation*\relativefibrethickness,0)$) 
        \foreach \y in {\fibresteps,...,0}
        {   -- ($(\x*\segmentwidth+\segmentvariation,\y*\stepheight) + (rand*\relativefibrevariation*\relativefibrethickness,0)$)
        }
        -- cycle;
    }
    \draw[thick] (0,0) rectangle (\boardwidth,\boardheight);

    % manually added stuff, only for Go board look  
    \draw (1,1) grid (19,19);
    \foreach \x in {4,10,16}
    {   \foreach \y in {4,10,16}
        {   \fill (\x,\y) circle (0.1);
        }
    }
    % spy for seeing the structure
    \spy[magnification=10,yellow] on (5.3,5.8) in node at (8,-8);
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer

You could use \pgfdeclareradialshading to modify the ball shading.

For example, insert:

\makeatletter
\pgfdeclareradialshading[tikz@ball]{ball}{\pgfqpoint{-10bp}{10bp}}{%
 color(0bp)=(tikz@ball!30!white);
 color(9bp)=(tikz@ball!75!white);
 color(18bp)=(tikz@ball!90!black);
 color(25bp)=(tikz@ball!70!black);
 color(50bp)=(black)}
\makeatother

The "reflection" will be less spotty and more ambient than with the original code:

alt text

Adjust the color values according to your needs.

share|improve this answer
1  
That looks great ;) –  Leo Liu Aug 18 '10 at 14:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.