3

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.

3

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}

\pgfdeclareradialshading{sphere}{\pgfpoint{0.5cm}{0.5cm}}%
   {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}
    \pgfuseshading{sphere}
\end{document}

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? – Equivalent Triangle Jan 31 '17 at 18:37
  • @lamkingming They are RGB values. So if you keep them the same you get tones of gray – percusse Jan 31 '17 at 18:41
  • @percusse But when I set all three of them to be the same, the shading somehow goes away – Equivalent Triangle Jan 31 '17 at 18:46
  • check the last comment of Simon about the color with matte and RGB @lamkingming – percusse Jan 31 '17 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 '17 at 23:16
1

Is this what you're seeking?

enter image description here

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

\begin{document}

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

\shade[sphereBlack]  (0,0) circle (1cm); 
\shade[sphereYellow] (3,0) circle (1cm); 
\end{tikzpicture}

\end{document}
  • 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". – Equivalent Triangle Jan 31 '17 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 '17 at 2:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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