The second answer in

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.

2 Answers 2


The colors are set here:

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

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


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):




enter image description here

  • 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
    – percusse
    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
    – percusse
    Jan 31, 2017 at 18:55
  • 2
    @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.
    – percusse
    Jan 31, 2017 at 23:16

Is this what you're seeking?

enter image description here



  sphereBlack/.style={ball color = black},
  sphereYellow/.style={ball color = yellow}

\shade[sphereBlack]  (0,0) circle (1cm); 
\shade[sphereYellow] (3,0) circle (1cm); 

  • Thanks! But I need a sphere whose light area consist of a larger proportion of the sphere, yet at the same time the darkest area are quit dark. For example it wouldn't work if I change your black sphere to a gray, since the dardest area will be gray and so not dark enough. See the post I refer to in the question, there is two example "That's not a sphere" and "That's a sphere". I want somthing like "That's a sphere". Jan 31, 2017 at 18:35
  • @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
    – CroCo
    Feb 2, 2017 at 2:28

You must log in to answer this question.

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