Skip to content

Commit 70915ca

Browse files
committed
Merge pull request #1019 from nyalldawson/random_colors
Tweak random color ramp for nicer colors
2 parents 36c2f7f + bce3588 commit 70915ca

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/core/symbology-ng/qgsvectorcolorrampv2.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,12 @@ double QgsRandomColorsV2::value( int index ) const
345345
QColor QgsRandomColorsV2::color( double value ) const
346346
{
347347
Q_UNUSED( value );
348-
int r = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
349-
int g = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
350-
int b = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
351-
return QColor( r, g, b );
348+
int minVal = 130;
349+
int maxVal = 255;
350+
int h = 1 + ( int )( 360.0 * rand() / ( RAND_MAX + 1.0 ) );
351+
int s = ( rand() % ( DEFAULT_RANDOM_SAT_MAX - DEFAULT_RANDOM_SAT_MIN + 1 ) ) + DEFAULT_RANDOM_SAT_MIN;
352+
int v = ( rand() % ( maxVal - minVal + 1 ) ) + minVal;
353+
return QColor::fromHsv( h, s, v );
352354
}
353355

354356
QString QgsRandomColorsV2::type() const

0 commit comments

Comments
 (0)