Consider the case where you have many sentences pieced together from different sources and want to highlight each one of those sentences based on the source number. In HTML, the standard for highlighting text utilizes the
<mark> tag with the
background-color attribute set to a light yellow color.
The first value in
hsl() is a value in degrees for hue which ranges from 0 to 360, spanning from red to green to blue and back to red in circular form. The goal of the following function (i.e., line of code) is to return maximally different hues based on the total amount of colors you want to use.
If the first color is a standard yellow (used above) then
startHue is 50.
nColors is the total number of colors you want to use and
ii is the current color you want to select. Consider where
nColors = 6:
ii = 1).1 The second source has a different color.2 So does the third!3 All of the colors are meant to contrast.4 Unless
nColorsis very large.5 This is the where
ii = 6; that's all of them.6
Pro Tip: If you want to selectively highlight text based on a word or regex pattern in Ruby on Rails there is a great Text Helper called highlight.