6
A
回答
14
您需要登錄到read this paper。認真。
除此之外,它可能需要的是使用QColor::fromHslF(x/*0.8, 0.95, 0.5)
在HSL顏色表示中迭代色相,其中x
在彩虹上從0.0變化到1.0。這在物理上並不準確,但也許它會這樣做。
否則,您需要一個稍微更復雜的代碼,它非常簡單地近似上面引用的論文。
#include <QApplication>
#include <QPainter>
#include <QPixmap>
#include <QLabel>
#include <algorithm>
#include <cmath>
QColor wavelengthToColor(qreal lambda)
{
// Based on: http://www.efg2.com/Lab/ScienceAndEngineering/Spectra.htm
// The foregoing is based on: http://www.midnightkite.com/color.html
struct Color {
qreal c[3];
QColor toColor(qreal factor) const {
qreal const gamma = 0.8;
int ci[3];
for (int i = 0; i < 3; ++i) {
ci[i] = c[i] == 0.0 ? 0.0 : qRound(255 * pow(c[i] * factor, gamma));
}
return QColor(ci[0], ci[1], ci[2]);
}
} color;
qreal factor = 0.0;
static qreal thresholds[] = { 380, 440, 490, 510, 580, 645, 780 };
for (unsigned int i = 0; i < sizeof(thresholds)/sizeof(thresholds[0]); ++ i) {
using std::swap;
qreal t1 = thresholds[i], t2 = thresholds[i+1];
if (lambda < t1 || lambda >= t2) continue;
if (i%2) swap(t1, t2);
color.c[i % 3] = (i < 5) ? (lambda - t2)/(t1-t2) : 0.0;;
color.c[2-i/2] = 1.0;
factor = 1.0;
break;
}
// Let the intensity fall off near the vision limits
if (lambda >= 380 && lambda < 420) {
factor = 0.3 + 0.7*(lambda-380)/(420 - 380);
}
else if (lambda >= 700 && lambda < 780) {
factor = 0.3 + 0.7*(780 - lambda)/(780 - 700);
}
return color.toColor(factor);
}
QPixmap rainbow(int w, int h)
{
QPixmap pm(w, h);
QPainter p(&pm);
qreal f1 = 1.0/400;
qreal f2 = 1.0/780;
for (int x = 0; x < w; ++ x) {
// Iterate across frequencies, not wavelengths
qreal lambda = 1.0/(f1-(x/qreal(w)*(f1-f2)));
p.setPen(wavelengthToColor(lambda));
p.drawLine(x, 0, x, h);
}
return pm;
}
class RainbowLabel : public QLabel {
protected:
void resizeEvent(QResizeEvent *) {
setPixmap(rainbow(width(), height()));
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
RainbowLabel l;
l.resize(600, 100);
l.show();
return a.exec();
}
+0
+1。感謝您參考該論文。這是我已經閱讀過的關於正確渲染顏色的最清晰和最有用的解釋之一。 –
+0
我接受你的回答。非常感謝! – MelMed
相關問題
- 1. java畫彩虹
- 2. 彩虹效果
- 3. 光譜顏色選擇器,使色彩
- 4. 開發彩虹表
- 5. 如何在Freeglut中繪製彩虹?
- 6. 彩虹表:如何防禦他們?
- 7. Java生成彩虹色 - 如何?
- 8. 高效渲染譜圖的可視化
- 9. 如何從光譜圖像中提取EELS光譜?
- 10. 彩虹的接近度
- 11. 彩虹效應多用戶
- 12. openGL中的彩虹線es
- 13. 創建(彩虹)調色板
- 14. 彩虹表和加密
- 15. 給我一個彩虹
- 16. 翹曲R中的彩虹
- 17. 從freerainbowtables.com讀取彩虹桌
- 18. 彩虹色的傳說R
- 19. Java Swing:JComponent的彩虹邊框
- 20. 如何獲取openGL渲染彩色四邊形?
- 21. 光譜重建
- 22. 如何渲染XML
- 23. 如何渲染DotML
- 24. 如何渲染UITableViewCell
- 25. 延遲渲染中的光積累
- 26. 渲染JList時更改光標
- 27. 延期渲染和移動點光線
- 28. 燈光渲染效果低FPS
- 29. 畫布渲染模糊不光滑
- 30. 用文字渲染D3.js陽光圖
QT擁有的QColor類,您可以設置色調,你可以得到的RGB從中 –
看一看這樣的:http://qt-project.org/doc/qt -4.8/paintsystem.html,它有你需要知道的一切。一旦你完成了一些閱讀/學習,如果你陷入困境,回來後發佈一個特定的編程問題。 – JBentley
你真的在問1)如何計算欄上每個位置的RGB(或HSL,HSV等)值,或者2)如何給出正確的顏色來創建欄,或者3)兩者? –