8

I'm trying to get a realistically looking continuum potato. This is what I already achieved but i would like to improve the outcome by rotating the light-shading and make it bigger. Is there any way to do that?

\documentclass[a4,10pt,fleqn]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{decorations.text}
\begin{document}


\makeatletter
\pgfdeclareradialshading[tikz@ball]{ball}{\pgfqpoint{-20bp}{10bp}}{%
 color(0bp)=(tikz@ball!0!white);
 color(10bp)=(tikz@ball!0!white);
 color(15bp)=(tikz@ball!70!black);
 color(20bp)=(black!70);
 color(30bp)=(black!70)}
\makeatother
\begin{tikzpicture}[>=stealth,
axis/.style={densely dashed,font=\small}]

\coordinate (K) at (3,1);


\shade[ball color= gray!10!white, opacity=.6] (K) plot [smooth cycle,tension=0.7] coordinates {(3,1) (5,1.2) (7,1) (8,3) (7,4.5) (5,4.5) (2,4) (1.7,2.5)};

\end{tikzpicture}

\end{document}

enter image description here

4

1 Answer 1

3

As it can be seen, the code you're using came from the Yori's answer to How to draw a shaded sphere?. I liked Alain Matthes' answer better:

\documentclass[tikz]{standalone}
\usetikzlibrary{shadings}
\pgfdeclareradialshading{ballshading}{
 \pgfpoint{-10bp}{10bp}}
 {color(0bp)=(gray!30!white); 
  color(9bp)=(gray!75!white);
  color(18bp)=(gray!70!black); 
  color(25bp)=(gray!50!black); 
  color(50bp)=(black)}
\begin{document}
\begin{tikzpicture}
\coordinate (K) at (3,1);
\shade[shading=ballshading] (K) plot [smooth cycle,tension=0.7] coordinates {(3,1) (5,1.2) (7,1) (8,3) (7,4.5) (5,4.5) (2,4) (1.7,2.5)};
\end{tikzpicture}
\end{document}

enter image description here

Now to answer your actual question, which is how to rotate the shading or make it bigger (change the light source position). The shading will start at the specified \pgfpoint{<x>}{<y>} (first argument of \pgfdeclareradialshading) where \pgfpoint{0}{0} is the potato center. The shading colors will follow the order given in the second argument of \pgfdeclareradialshading where the dimension in parenthesis is the radial distance from the specified \pgfpoint. So, by changing the value of the \pgfpoint you can "rotate" the shading, for instance changing it to \pgfpoint{20bp}{10bp} results in the following:

enter image description here

By changing the dimensions in () you can change the gradient itself, making the brighter region smaller or bigger. The same can be said for the dark region(the bright region is defined by the two color statements where you have <num>!white and the dark region by <num>!black). Note that these dimensions are not relative to the size of the shading shape, they're absolute. An example of making the brighter area larger: using \pgfpoint{10bp}{10bp} and the dimensions in () in the following sequence: 0bp 15bp 20bp 25bp 50bp, you get the following (note that I increased the 9bp to 15b´therefore the white area will be bigger).

enter image description here

To get more control of everything it's possible to declare a sphere color that shall be used for this shading, and by changing this color you change the shading color, like in the below MWE. Also, since the dimensions on the shading are absolute, it's a good idea to keep the maximum value within the size of the shape, so I changed the dimensions to fit in.

\documentclass[tikz]{standalone}
\usetikzlibrary{shadings}
\definecolor{sphere color}{RGB}{0,0,0}
\pgfdeclareradialshading[sphere color]{ballshading}{
 \pgfpoint{6mm}{3mm}}
 {color(0mm)=(sphere color!30!white); 
  color(4mm)=(sphere color!75!white);
  color(8mm)=(sphere color!70!black); 
  color(12mm)=(sphere color!50!black); 
  color(15mm)=(black)}
\begin{document}
\begin{tikzpicture}
\coordinate (K) at (3,1);
\colorlet{sphere color}{blue}
\shade[shading=ballshading] (K) plot [smooth cycle,tension=0.7] coordinates {(3,1) (5,1.2) (7,1) (8,3) (7,4.5) (5,4.5) (2,4) (1.7,2.5)};
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .