Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following code works, except that the colors aren't showing in the output. Wh? I probably made a trivial mistake, but I'm yet unable to find it.

  Flatten[Table[{x, y, z} = 
      {RandomReal[{-10, 10}], RandomReal[{-10, 10}], RandomReal[{-10, 10}]};
    p = 0.1;
    {u, v, w} = {0.0, 0.0, 0.0};
    NestList[(u += RandomReal[NormalDistribution[0, s]];
       v += RandomReal[NormalDistribution[0, s]];
       w += RandomReal[NormalDistribution[0, s]];
       # + p {u, v, w}) &, {x, y, z}, 50],
    {s, 0.1, 1, 0.05}], 1];
PlotColor = ColorData["SunsetColors"];

Graphics3D[{PointSize[0.1], {PlotColor[Norm[#]], Sphere[#, 0.1]}& /@ RandomWalkCoords}, 
  Boxed -> False, Background -> Black, Lighting -> "Neutral", SphericalRegion -> True]

I'm not very familiar with this way of programming Mathematica (I'm on version 7.0 by the way), but I'm learning!

The output should show a bunch of random curves made of small balls (no lines), with a radial color gradient.

Maybe there's a simpler way of doing this?

share|improve this question
If you remove the Lighting->"Neutral" option, your code should work. – gpap Mar 11 '13 at 15:54
Well, it doesn't make the SunsetColors to be used. There's something else. – Cham Mar 11 '13 at 15:58
ah, yes, sorry - missed they weren't normalised to 1. As the answer says, dividing the Norm by the max will do. Also, why Sphere and not Point? – gpap Mar 11 '13 at 16:09
up vote 5 down vote accepted

Colour functions from ColorData take values between 0 and 1. You're giving it much higher values.

Do this:

max = Max[Norm /@ RandomWalkCoords]

then change PlotColor[Norm[#]] to PlotColor[Norm[#]/max].

Side comment: it's good practice not to create symbols with names starting with capital letters. This way you can be sure you'll avoid conflicts with either built-in or package symbols.

share|improve this answer
AAaah ! Thanks ! It's perfectly clear ! :-) – Cham Mar 11 '13 at 16:00

Your Answer


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.