# How can I compile a ColorFunction with Blend? [duplicate]

f1 = {Max[4 # - 1.5, -4 # + 4.5], Min[4 # - 0.5, -4 # + 3.5],
Min[4 # + 0.5, -4 # + 2.5]} &;

cf1 = Compile[{{z, _Real}}, {Max[4 z - 1.5, -4 z + 4.5],
Min[4 z - 0.5, -4 z + 3.5], Min[4 z + 0.5, -4 z + 2.5]}];

ArrayPlot[Table[x y, {x, -200, 200}, {y, -200, 200}],
ColorFunction -> (RGBColor@f1@# &)] // Timing


I know how to compile the ColorFunction f1, but I dont't know whether f2 can be compiled.

f2 = Blend[{{0, RGBColor[0, 0, 9/16]}, {1/9, Blue}, {23/63, Cyan},{13/21,Yellow},
{47/63, Orange}, {55/63, Red}, {1, RGBColor[1/2, 0, 0]}}, #] &;

• See this list... Blend is not on that list, which means you can't compile it unless you re-implement Blend using functions on that list (which shouldn't be hard, since it's just linear interpolation).
– rm -rf
Mar 12 '13 at 13:32
• Why do you need to compile a ColorFunction it shouldn't be too slow... Mar 12 '13 at 18:20
• As rm, notes, Blend[] internally performs linear interpolation over the RGB color space. See the linked question for compiled functions for linear interpolation. Apr 27 '13 at 4:45