Function makeGradient

  • Produce a multicolor gradient that transitions between the provided colors in the specified steps. All colors are [r,g,b] tuples of integers 0 <= r,g,b <= 255.

    For example, given:

    • { 0: [0,0,252], 3: [0,126,0], 5: [254,0,0] }

    Produces:

    • { 0: [0,0,252], 1: [0,42,168], 2: [0,84,84], 3: [0,126,0], 4: [127,63,0], 5: [254,0,0] }

    Parameters

    • colors: Map<number, Color>

      a map of integer keys to RGB colors, not containing keys that differ by more than 2^10

    Returns Map<number, Color>

    a map whose keys are the integers from the lowest to highest keys in colors, inclusive, and each key k maps to the RGB color:

    • colors[k] if k is a key in colors
    • otherwise, letting prev and next be the nearest lower and higher keys in colors, respectively, the linear interpolation between colors[prev] and colors[next], rounded (half up), at t equal to k's fractional distance from prev to next