Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 f012065
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/core/symbology-ng/qgsvectorcolorrampv2.cpp
Expand Up @@ -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 ) );
Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology-ng/qgsvectorcolorrampv2.h
Expand Up @@ -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
{
Expand Down

0 comments on commit f012065

Please sign in to comment.