Linearly increasing color darkness algorithm
I want to write a function in ruby ββthat gives a number from 1 to 500, produces a six-digit six-color code that gets darker for higher numbers. It's not that hard, but I'm not sure where to start. How to implement this?
change
Tint seems to be a more reliable way. I would like to give a control color, like a tint of green, and then darken or lighten it based on the input number.
input: 10
output: color code (in rgb or HSV) which is the lighter shade of the reference color
input: 400
output: color code (in rgb or HSV) which is a rather dark shade of the reference color
change 2
The only reason I need to use 1 to 500 is because I have to work with. It is good if some cards that are close to each other correspond to the same color.
Basic linear interpolation?
// Pseudocode
function fade_colour(source, factor)
const max = 500
const min = 1
foreach component in source
output[component] = round(source[component] * (max - value) / (max - min))
endforeach
return output
endfunction
The 6 digit hexadecimal color code is in RGB. You want to work in HSV: select hue and saturation and gradually decrease the value. Convert from HSV to RGB for color output. See here for an example.
Why not just bring back the gray level and then #ffffff to # 000000? The 500 levels of darkness are not really distinguishable, and the gray ones give you 256 levels.
If you only want to darken your reference color, this is easy. Given the R, G, B color which is the brightest you want to increase, multiply each of the three values ββby (500-input) and divide by 499. Convert each of the values ββto 2 hex digits and add them with # to the front.