Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以Qt为单位的锥形梯度(不含QConicalGradient) 我必须在qtC++中画一个圆锥梯度,但我不能用qcIc梯度。我有一个线性梯度,但我不知道如何做一个锥形梯度。我不想要完成的代码,但我要求一个简单的算法 for(int y=0;y_C++_Qt_Graph Algorithm - Fatal编程技术网

以Qt为单位的锥形梯度(不含QConicalGradient) 我必须在qtC++中画一个圆锥梯度,但我不能用qcIc梯度。我有一个线性梯度,但我不知道如何做一个锥形梯度。我不想要完成的代码,但我要求一个简单的算法 for(int y=0;y

以Qt为单位的锥形梯度(不含QConicalGradient) 我必须在qtC++中画一个圆锥梯度,但我不能用qcIc梯度。我有一个线性梯度,但我不知道如何做一个锥形梯度。我不想要完成的代码,但我要求一个简单的算法 for(int y=0;y,c++,qt,graph-algorithm,C++,Qt,Graph Algorithm,以下是一些伪代码: 给你一个可以画画的区域和一个确定的渐变中心 对于区域中正在绘制的每个点,计算到渐变中心的角度 // QPoint currentPoint; // created/populated with a x, y value by two for loops QPoint relativeToCenter = currentPoint - centerPoint; angle = atan2(relativeToCenter.y(), relativeToCenter.x());

以下是一些伪代码:

给你一个可以画画的区域和一个确定的渐变中心

对于区域中正在绘制的每个点,计算到渐变中心的角度

// QPoint currentPoint;  // created/populated with a x, y value by two for loops
QPoint relativeToCenter = currentPoint - centerPoint;
angle = atan2(relativeToCenter.y(), relativeToCenter.x());
然后使用线性渐变或某种映射函数将该角度映射为颜色

float hue = map(-PI, angle, PI, 0, 255); // convert angle in radians to value
// between 0 and 255
绘制该像素,并对区域中的每个像素重复

编辑:根据渐变的模式,您需要创建不同的
QColor
像素。例如,如果您有一个“彩虹”渐变,只需从一个色调切换到下一个色调,您可以使用如下线性映射函数:

float map(float x1, float x, float x2, float y1, float y2)
{
     if(true){
          if(x<x1)
                x = x1;
          if(x>x2)
                x = x2;
     }

     return y1 + (y2-y1)/(x2-x1)*(x-x1);
}
然后将此
QColor
对象与您正在使用的
QPainter
QBrush
QPen
一起使用。或者,如果您将qRgb值放回:

line[x] = c.rgb();


希望有帮助。

为什么你不能使用
QConicalGradient
?因为我们必须实现你自己版本的绘制圆锥梯度我不知道这行需要做什么:float hue=map(-PI,angle,PI,0,255);我将代码粘贴在下面。
float hue = map(-PI, angle, PI, 0, 255); // convert angle in radians to value
// between 0 and 255
QColor c;
c.setHsl( (int) hue, 255, 255);
line[x] = c.rgb();