Last active
December 25, 2015 02:42
-
-
Save libliflin/39d1c05535acbdf7072e to your computer and use it in GitHub Desktop.
Not really a rainbow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func RAINBOW() []color.Color { | |
const ( | |
paletteSize = 256 | |
) | |
var palette [paletteSize]color.Color | |
// 1 0 0 : RED 1 + | |
// 1 1 0 : YELLOW 0 - | |
// 0 1 0 : GREEN 2 + | |
// 0 1 1 : TEAL 1 - | |
// 0 0 1 : BLUE 0 + | |
// 1 0 1 : PURPLE 2 - | |
// 1 0 0 : RED | |
stepSize := paletteSize / 6 | |
stepExtra := paletteSize - (stepSize * 6) | |
colorStep := 255 / stepSize | |
colorExtra := 255 - (colorStep * stepSize) | |
place := []int{1, 0, 2, 1, 0, 2} | |
col := [3]uint8{0xFF, 0x00, 0x00} | |
var j int | |
palette[j] = color.Black | |
j++ | |
var p int | |
for p = 0; p < len(place); p++ { | |
for i := 0; i < stepSize; i++ { | |
palette[j] = color.RGBA{col[0], col[1], col[2], 0xFF} | |
// increment color | |
col[place[p]] += uint8(colorStep) | |
j++ | |
} | |
if colorExtra != 0 { | |
col[place[p]] += uint8(colorExtra) | |
} | |
colorStep = -1 * colorStep | |
colorExtra = -1 * colorExtra | |
} | |
p = 0 | |
for i := 0; i < stepExtra-1; i++ { | |
palette[j] = color.RGBA{col[0], col[1], col[2], 0xFF} | |
j++ | |
} | |
return palette[:] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment