Skip to content

Commit

Permalink
Merge pull request #1 from dim13/go
Browse files Browse the repository at this point in the history
Go
  • Loading branch information
dim13 authored Aug 10, 2019
2 parents 9bd0cbb + cbc39de commit e295ccf
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 136 deletions.
34 changes: 0 additions & 34 deletions .gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions Makefile

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
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
21 changes: 21 additions & 0 deletions cmd/hashcolor/main.go
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))
}
5 changes: 5 additions & 0 deletions go.mod
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
2 changes: 2 additions & 0 deletions go.sum
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=
89 changes: 0 additions & 89 deletions hashcolor.c

This file was deleted.

36 changes: 36 additions & 0 deletions hashcolor.go
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
}

0 comments on commit e295ccf

Please sign in to comment.