From 1b75342fdec4f58aecb35869588a247e9ddc066a Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Sun, 17 Jan 2016 20:50:07 +0100 Subject: ColorScale: minor update to color sampling and generation algorithms. --- colorscale.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'colorscale.cpp') diff --git a/colorscale.cpp b/colorscale.cpp index e4e2063..38898c3 100644 --- a/colorscale.cpp +++ b/colorscale.cpp @@ -63,15 +63,14 @@ QColor ColorScale::color(float t) const } // find which colors in the scale are adjacent to ours - float step = 1.0 / m_colors.size(); - int i = int(t / step); + int i = int(t * m_colors.size()); int j = i + 1; - if (i >= m_colors.size() - 1) { return QColor(m_colors.last()); } // normalize t between the two colors + float step = 1.0f / m_colors.size(); t = (t - i*step) / (j*step - i*step); return lerp(m_colors[i], m_colors[j], t); } -- cgit v1.2.3