-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go
- Loading branch information
Showing
8 changed files
with
67 additions
and
136 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# hashcolor | ||
|
||
Simple color randomizer for uxterm | ||
|
||
Build and install with `pmake' on linux | ||
## install | ||
|
||
Patch uxterm with `pmake patch' | ||
go get -u github.com/dim13/hashcolor/cmd/hashcolor |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"image/color" | ||
"os" | ||
"strings" | ||
|
||
"github.com/dim13/hashcolor" | ||
) | ||
|
||
func hex(c color.Color) string { | ||
rgba := color.RGBAModel.Convert(c).(color.RGBA) | ||
return fmt.Sprintf("#%.2x%.2x%.2x", rgba.R, rgba.G, rgba.B) | ||
} | ||
|
||
func main() { | ||
c := hashcolor.New(strings.Join(os.Args[1:], " ")) | ||
t, s := hashcolor.Tint(c), hashcolor.Shade(c) | ||
fmt.Println("-fg", hex(t), "-bg", hex(s)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/dim13/hashcolor | ||
|
||
go 1.12 | ||
|
||
require github.com/dim13/crc24 v0.0.0-20190308110643-af7201913116 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/dim13/crc24 v0.0.0-20190308110643-af7201913116 h1:Yg0Qk0ozxBmyHXaFiyAokM5Gf/uCFm7Vy+ukpFPiFVQ= | ||
github.com/dim13/crc24 v0.0.0-20190308110643-af7201913116/go.mod h1:TejqRSRwQ36N6MSUaGN8WipY4g3bgf5HeEi9fApCxG0= |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package hashcolor | ||
|
||
import ( | ||
"image/color" | ||
|
||
"github.com/dim13/crc24" | ||
) | ||
|
||
// New color from hashed string | ||
func New(s string) color.RGBA { | ||
c := crc24.Sum([]byte(s)) | ||
return color.RGBA{ | ||
R: uint8(c >> 0x10), | ||
G: uint8(c >> 0x08), | ||
B: uint8(c), | ||
A: 0xff, | ||
} | ||
} | ||
|
||
// Tint color | ||
func Tint(c color.Color) color.RGBA { | ||
rgba := color.RGBAModel.Convert(c).(color.RGBA) | ||
rgba.R += (0xff - rgba.R) >> 1 | ||
rgba.G += (0xff - rgba.G) >> 1 | ||
rgba.B += (0xff - rgba.B) >> 1 | ||
return rgba | ||
} | ||
|
||
// Shade color | ||
func Shade(c color.Color) color.RGBA { | ||
rgba := color.RGBAModel.Convert(c).(color.RGBA) | ||
rgba.R >>= 2 | ||
rgba.G >>= 2 | ||
rgba.B >>= 2 | ||
return rgba | ||
} |