我终于明白了
首先,我使用了本教程中提到的来自 BoostWorthy.com 的 Ryan Taylor 的代码:http:
//www.boostworthy.com/blog/? p=200
本教程的问题是颜色范围没有得到我的色调色轮可用的所有可能色调,因为他使用正弦波来计算角度颜色。如果您查看色调的维基百科文章,您会发现色谱不是正弦波,而是红绿和蓝色的简单混合。这是直观地解释了我在说什么的图表:
http://en.wikipedia.org/wiki/File:HSV-RGB-comparison.svg
如果您使用正弦波,则波仅在每 60 度一次的最大值处达到峰值......当颜色值的斜率需要在每 60 度期间保持恒定时(即在一个时期内,每种颜色的最大值将为 255 或该期间的最小值为 0)
这是在教程的帖子中作为他的代码问题提出的,但没有人发布解决方案......这是实际的解决方案:
//Define our variables
var nRadians:Number;
var nColor:int = 0;
var nX:Number;
var nY:Number;
var nIX:Number;
var nIY:Number;
var nR:Number;
var nG:Number;
var nB:Number;
// Calculate the thickness of the lines which draw the colors.
var iThickness:int = 1 + int(nRadius / 50);
// Loop from '0' to '360' degrees, drawing lines from the center
// of the wheel outward the length of the specified radius.
for(var i:int = 0; i < 360; i++)
{
nRadians = i * (Math.PI / 180);
var offset:Number = i;
do
{
offset = offset - 60;
} while (offset >= 60)
if (offset < 0) offset = offset + 60;
var greenSlope:String = "up";
var redSlope:String = "max";
var blueSlope:String = "min";
//GREEN-----------------
if (i >= 60) greenSlope = "max";
if (i > 180) greenSlope = "down";
if (i >= 240) greenSlope = "min";
//RED-------------------
if (i > 60) redSlope = "down";
if (i >= 120) redSlope = "min";
if (i > 240) redSlope = "up";
if (i >= 300) redSlope = "max";
//BLUE------------------
if (i > 120) blueSlope = "up";
if (i >= 180) blueSlope = "max";
if (i > 300) blueSlope = "down";
var colorArr:Array = new Array(blueSlope,greenSlope,redSlope);
var valueArr:Array = new Array(nB,nG,nR);
var counter:int = 0;
var bitRotation:int = 0;
for each (var color:String in colorArr)
{
var value:Number = 0;
var percentUpOffset:Number = ((100 / 60) * offset) / 100;
var percentDownOffset:Number = ((100 / 60) * (60 - offset)) / 100;
if (color == "max") value = 255;
if (color == "min") value = 0;
if (color == "up") value = 255 * percentUpOffset;
if (color == "down") value = 255 * percentDownOffset;
valueArr[counter] = value << bitRotation;
if (i == 0) trace(value);
bitRotation = bitRotation + 8;
counter++;
}
nR = valueArr[2];
nG = valueArr[1];
nB = valueArr[0];
// OR the individual color channels together.
nColor = nR | nG | nB;
// Calculate the coordinate in which the line should be drawn to.
// (nIX / nIY is the inner start position of the ring
nX = (nRadius * Math.cos(nRadians)) + DEFAULT_RADIUS;
nY = (nRadius * Math.sin(nRadians)) + DEFAULT_RADIUS;
nIX = ((nRadius - nHeight) * Math.cos(nRadians)) + DEFAULT_RADIUS;
nIY = ((nRadius - nHeight) * Math.sin(nRadians)) + DEFAULT_RADIUS;
//Draw the line
var line:Line = new Line();
var stroke:SolidColorStroke = new SolidColorStroke(nColor,iThickness);
line.stroke = stroke;
line.xFrom = nIX;
line.xTo = nX;
line.yFrom = nIY;
line.yTo = nY;
this.addElement(line);
}