Generate a distinctive color palette

November 10, 2013

Recently I needed a set number of distinctive colors (16) for a data visualization task. Here is some Go code, that uses the marvelously documented go-colorful library:

package main

import (

var labels = [...]string{
    "Laning Presence","Jungle","Defend","Push","Escape",
    "Ward","Counterward","Harass","Contest Pull","Fight"}

func main() {
    num_colors := len(labels)

    pal, err := colorful.HappyPalette(num_colors)
    if err != nil {

    colors := make([]string, num_colors)
    for i := 0; i < num_colors; i++ {
        colors[i] = fmt.Sprintf("\"%v\": \"%v\"", labels[i],pal[i].Hex())

    fmt.Printf("colors = {\n")
    fmt.Printf("    %v\n",strings.Join(colors, ", "))

The output of this code is a JavaScript dictionary. The same approach can be used for any other language where you do not wish to deal with the hassle of generating colors during runtime.

Want to be notified when I publish new content?

Enter your email below to join my mailing list!