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

I am trying to color a BSplineSurface in a complex way but not having any luck using ColorFunction. I can use ColorFunction if I using BSplineFunction and ParametricPlot3D but would prefer not to go that route. Here is an example of the surface I would like to color:

Graphics3D[{EdgeForm[], SeedRandom[4];
  BSplineSurface[Table[{x, y, 0.25 + UnitStep[30 - Abs[x] - 0.001] UnitStep[50 -Abs[y] - 0.001] (0.25/RandomReal[{0.1, 2}]^2)}, 
  {x, -30, 30, 5.}, {y, -50, 50, 5.}]]}, Boxed -> False]

I would like to be able to color the peaks with one color (red) and have that color fade away to gray in the flat parts.enter image description here

share|improve this question
I think that you cannot, as it's a single graphics object. But you can construct a BSplineFunction, use Plot3D to plot it, and use ColorFunction in Plot3D. This'll build up the plot from many graphics objects (polygons), each of which will be separately coloured based on your ColorFunction – Szabolcs Jul 1 '14 at 17:49
Are you the same person as here? – Szabolcs Jul 1 '14 at 17:50
Yes. I was not able to log-in to the account for some reason. – BeauGeste Jul 1 '14 at 18:17
It's better to prepend your comment with @szabolcs if you want him to get a notification – Dr. belisarius Jul 1 '14 at 18:44
@BeauGeste Please try to merge your accounts using this page – R. M. Jul 1 '14 at 20:56
pts = Table[{x, y, 0.25 + UnitStep[30 - Abs[x] - 0.001] UnitStep[50 - Abs[y] - 0.001]
            (0.25/RandomReal[{0.1, 2}]^2)}, {x, -30,  30, 5}, {y, -50, 50, 5}];

 BSplineFunction[pts, SplineDegree -> 2][u, v], {u, 0, 1}, {v, 0, 1}, 
 PlotRange -> All, Boxed -> False, Axes -> False, Mesh -> None, 
 ColorFunction -> Function[{x, y, z}, Blend[{Gray, Red}, z]]]

Mathematica graphics

share|improve this answer

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.