How to draw a shaded sphere?

is a yellow shaded sphere. How can I turn it to be black and white? Thanks for any help! I have been trying for an hour, changing values randomly but did't achieve anything, since I don't understand the code.

The colors are set here:

%% currently there is just one number in the stack.
%% we need three corresponding to the RGB values
dup
0.4


You have to put the RGB values you desire to change the color, for example if you set:

dup
0.4
0.5


You get something like pink.

RGB means red, green and blue, the primary colors, in this notation they have value from 0 (= no light) to 1 (= full light), for example:

r g b
0 0 0 = black
1 0 0 = red
0 1 0 = green
0 0 1 = blue
1 1 1 = white


If all the 3 values are equal to a value from 0 to 1, you get the scale of gray.

As you said in a comment, if you put all the rgb equal you lost the shade, I think you can reach you desired result by changing other commands, but don't know them, because they are a simplified form of a subset of the PostScript language, search for \pgfdeclarefunctionalshading in the Ti_k_Z & PGF Manual and see Section 3.9.4 [here] (http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_reference_1-7.pdf) for more info.

Instead, I suggest to you to use a simpler solution, if you don't like CroCo's one, try something like this (modify the values until you find what you're looking for):

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

{rgb(0cm)=(1,1,1);
rgb(0.9cm)=(0.7,0.7,0.7);
rgb(1cm)=(0.5,0.5,0.5);
rgb(1.05cm)=(0,0,0)}

\begin{document}
\end{document}


• Thanks! I tried changing the values, but I cannot get it to be black and white. Is there some way to simply remove the colour while preserving the shading? Jan 31, 2017 at 18:37
• @lamkingming They are RGB values. So if you keep them the same you get tones of gray Jan 31, 2017 at 18:41
• @percusse But when I set all three of them to be the same, the shading somehow goes away Jan 31, 2017 at 18:46
• check the last comment of Simon about the color with matte and RGB @lamkingming Jan 31, 2017 at 18:55
• @lamkingming Change the last 0.4 to dup and decrease separately the numbers 0.6 or 0.4 until you are happy in Simon's answer. It makes it gray. Jan 31, 2017 at 23:16

Is this what you're seeking?

\documentclass[border={10pt}]{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
[
sphereBlack/.style={ball color = black},
sphereYellow/.style={ball color = yellow}
]


• @lamkingming, under Choosing a Shading Type section in the manual, there are several options for this matter. Take a look at inner color and outer color Feb 2, 2017 at 2:28