Created
November 9, 2023 13:40
-
-
Save Inndy/1be63e854992b805a8f74a3cb1fdbd2f to your computer and use it in GitHub Desktop.
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 "fmt" | |
func fcolor(r, g, b byte) string { | |
return fmt.Sprintf("\x1b[38;2;%d;%d;%dm", r, g, b) | |
} | |
func bcolor(r, g, b byte) string { | |
return fmt.Sprintf("\x1b[48;2;%d;%d;%dm", r, g, b) | |
} | |
const resetColor = "\x1b[0m" | |
func swap(a, b *uint64) { | |
*a, *b = *b, *a | |
} | |
func strItemColor(s string) string { | |
r := 12345 - 777*uint64(len(s)) | |
g := 34567 + 999*uint64(len(s)) | |
b := 56789 ^ (333 / (3 + uint64(len(s)))) | |
a := []uint64{0x80, 0x40, 0x20, 0x10} | |
for i, _c := range []rune(s) { | |
c := uint64(_c) | |
r = r ^ (r << (i & 7)) ^ (c * ^uint64(i)) | |
g = g ^ (g >> (i & 7)) ^ (c * uint64(-i)) | |
b = (b * r) ^ (b * g) ^ (b * 333) | |
if (r & 0xff) > (b & 0xff) { | |
swap(&a[0], &a[1]) | |
swap(&a[2], &a[3]) | |
swap(&a[0], &a[3]) | |
} else { | |
swap(&a[0], &a[2]) | |
swap(&a[1], &a[3]) | |
} | |
if (g & 0xff) > (r & 0xff) { | |
swap(&a[0], &a[3]) | |
swap(&a[1], &a[2]) | |
} else { | |
swap(&a[1], &a[3]) | |
} | |
} | |
return fcolor(byte(r|a[0]), byte(g|a[1]), byte(b|a[2])) + s + resetColor | |
} | |
func intItemColor(s uint64) string { | |
s0 := s | |
r := 12345 - 777*s | |
g := 34567 + 999*s | |
b := 56789 ^ (333 / (3 + s)) | |
a := []uint64{0x80, 0x40, 0x20, 0x10} | |
for i := uint64(0); i < 16; i++ { | |
s = s ^ (s >> 9) ^ (s>>3)*9999 | |
s = ^s * 99999999 | |
r = r ^ (r << (i & 7)) ^ (s * ^i) | |
g = g ^ (g >> (i & 7)) ^ (s * -i) | |
b = (b * r) ^ (b * g) ^ (b * 333) | |
if (r & 0xff) > (b & 0xff) { | |
swap(&a[0], &a[1]) | |
swap(&a[2], &a[3]) | |
swap(&a[0], &a[3]) | |
} else { | |
swap(&a[0], &a[2]) | |
swap(&a[1], &a[3]) | |
} | |
if (g & 0xff) > (r & 0xff) { | |
swap(&a[0], &a[3]) | |
swap(&a[1], &a[2]) | |
} else { | |
swap(&a[1], &a[3]) | |
} | |
} | |
return fmt.Sprintf("%s0x%x%s", fcolor(byte(r|a[0]), byte(g|a[1]), byte(b|a[2])), s0, resetColor) | |
} | |
func main() { | |
for i := uint64(0); i < 100; i++ { | |
fmt.Print(intItemColor(i) + " ") | |
} | |
fmt.Println(strItemColor("\n0")) | |
fmt.Println(strItemColor("Hello, World")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment