Using asymptote I'm trying to fill shapes with gradient shading in the HSV color space. Unfortunately, I think that HSV is not an available color space in asymptote. However, asymptote does have the `hsv` function that returns a `pen` in the RGB color space. I've used the following code to produce the two squares as shown.

``````unitsize(1inch);

// left square
pen p1 = hsv(240,1,1); // blue
pen p2 = hsv(  0,1,1); // red

// right square
real hband = 0.05;
for (real y = 0.0; y < 1.0; y += hband)
{
fill(shift(1.2,y)*scale(1,hband)*unitsquare, hsv((1.0-y)*240,1,1));
}
``````

The `axialshade` function is producing a gradient in the RGB color space on the left. The right square illustrates the HSV gradient that I want. However, it is produced manually by filling bands with solid HSV colors. Is there a method to automatically produce a HSV gradient?

EDIT: I see in comments at this question from 2012 that this color model is not supported by PDF. If true, that probably means that I'm asking for the impossible.

• If you're really determined to do it all in one area, you can specify the gradient as a postscript function (asymptote.sourceforge.net/gallery/functionshading.asy), but this will be slow to render. A probably better alternative is the latticeshade function, which should essentially allow you to smooth out your image on the right. Mar 6, 2016 at 21:54

Thank you @CharlesStaats for your great tip regarding the `latticeshade` function.

After doing more reading at Wikipedia I learned that the HSV color space consists simply of an RGB linear interpolation between the color sequence red--yellow--green--cyan--blue--magenta--red. Trimming that sequence to fit my need gives the following code.

``````unitsize(1inch);

// left square
pen[][] pens = { {red}, {yellow}, {green}, {cyan}, {blue} };