Created
March 23, 2019 20:49
-
-
Save gmemstr/ce6ff3cb429e62f59df90d9fc9201e72 to your computer and use it in GitHub Desktop.
Generates all possible CSS hex colours
This file contains 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
package main | |
import ( | |
"encoding/hex" | |
"os" | |
"strconv" | |
) | |
func main() { | |
f, err := os.OpenFile("colours.css", os.O_WRONLY, 0600) | |
if err != nil { | |
panic(err) | |
} | |
defer f.Close() | |
_, err = f.WriteString("hex {") | |
if err != nil { | |
panic(err) | |
} | |
for r := 0; r <= 255; r++ { | |
rHex := getHex(r) | |
for g := 0; g <= 255; g++ { | |
gHex := getHex(g) | |
for b := 0; b <= 255; b++ { | |
bHex := getHex(b) | |
formatted := "color: #" + rHex + gHex + bHex | |
_, err := f.Write([]byte(formatted)) | |
if err != nil { | |
panic(err) | |
} | |
} | |
} | |
} | |
_, err = f.WriteString("}") | |
if err != nil { | |
panic(err) | |
} | |
} | |
func getHex(num int) string { | |
hexColour := hex.EncodeToString([]byte(strconv.Itoa(num))) | |
if len(hexColour) == 1 { | |
hexColour = "0" + hexColour | |
} | |
return hexColour | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version by @spoopy on Discord
< 3 seconds on ramdisk