如何在Google Go中创建自己的颜色数组?

I don't want to use the standard color palettes in the go language, so I am wondering how can you create your own color palette.

You can have a look at the project lucasb-eyer/go-colorful, which can generate color palettes.

pal1, err1 := colorful.WarmPalette(10)
pal2 := colorful.FastWarmPalette(10)
pal3, err3 := colorful.HappyPalette(10)
pal4 := colorful.FastHappyPalette(10)
pal5, err5 := colorful.SoftPalette(10)

The following picture shows the palettes generated by all of these methods (sourcecode in doc/palettegens/palettegens.go), in the order they were presented, i.e. from top to bottom:

  • Warm,
  • FastWarm,
  • Happy,
  • FastHappy,
  • Soft,
  • SoftEx(isbrowny).

All of them contain some randomness, so YMMV.

https://raw.githubusercontent.com/lucasb-eyer/go-colorful/master/doc/palettegens/palettegens.png