1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ If you remove the Lighting->"Neutral" option, your code should work. $\endgroup$ – gpap Mar 11 '13 at 15:54
  • $\begingroup$ Well, it doesn't make the SunsetColors to be used. There's something else. $\endgroup$ – Cham Mar 11 '13 at 15:58
  • 1
    $\begingroup$ 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? $\endgroup$ – gpap Mar 11 '13 at 16:09
5
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ AAaah ! Thanks ! It's perfectly clear ! :-) $\endgroup$ – Cham Mar 11 '13 at 16:00

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.