Skip to content
Permalink
Browse files

Fix #4419, improve random color ramp appearance and generate colors w…

…ith better chance of uniqueness
  • Loading branch information
nyalldawson committed Jun 4, 2013
1 parent 1df825f commit f01206565847655d1caee64d342d999988c66491
Showing with 13 additions and 5 deletions.
  1. +9 −1 src/core/symbology-ng/qgsvectorcolorrampv2.cpp
  2. +4 −4 src/core/symbology-ng/qgsvectorcolorrampv2.h
@@ -288,9 +288,17 @@ void QgsVectorRandomColorRampV2::updateColors()
int h, s, v;

mColors.clear();
//start hue at random angle
double currentHueAngle = 360.0 * ( double )rand() / RAND_MAX;

for ( int i = 0; i < mCount; i++ )
{
h = ( rand() % ( mHueMax - mHueMin + 1 ) ) + mHueMin;
//increment hue by golden ratio (approx 137.507 degrees)
//as this minimises hue nearness as count increases
//see http://basecase.org/env/on-rainbows for more details
currentHueAngle += 137.50776;
//scale hue to between mHueMax and mHueMin
h = ( fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( mHueMax - mHueMin ) + mHueMin;
s = ( rand() % ( mSatMax - mSatMin + 1 ) ) + mSatMin;
v = ( rand() % ( mValMax - mValMin + 1 ) ) + mValMin;
mColors.append( QColor::fromHsv( h, s, v ) );
@@ -101,10 +101,10 @@ class CORE_EXPORT QgsVectorGradientColorRampV2 : public QgsVectorColorRampV2
#define DEFAULT_RANDOM_COUNT 10
#define DEFAULT_RANDOM_HUE_MIN 0
#define DEFAULT_RANDOM_HUE_MAX 359
#define DEFAULT_RANDOM_VAL_MIN 0
#define DEFAULT_RANDOM_VAL_MAX 255
#define DEFAULT_RANDOM_SAT_MIN 0
#define DEFAULT_RANDOM_SAT_MAX 255
#define DEFAULT_RANDOM_VAL_MIN 200
#define DEFAULT_RANDOM_VAL_MAX 240
#define DEFAULT_RANDOM_SAT_MIN 100
#define DEFAULT_RANDOM_SAT_MAX 240

class CORE_EXPORT QgsVectorRandomColorRampV2 : public QgsVectorColorRampV2
{

0 comments on commit f012065

Please sign in to comment.
You can’t perform that action at this time.