gocolor

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 4 Imported by: 0

README

gocolor

gocolor is a simple tool that generates Shades and Tints of a given color.

Description

Ideally, this repository contains exported libraries that helps with color manipulations.
However, it was built as a tool to generate shades and tints of a given color.

Installation

Easy way

To install gocolor, simply download the binary from the releases page and place it in your PATH.

Alternatives
MacOS
brew tap varsityscape/varsityscape
brew install varsityscape/varsityscape/gocolor
Go Install

You can also install gocolor using go install (if you have go installed):

go install github.com/varsityscape/gocolor/cmd/gocolor@latest

Usage

gocolor -h
# Usage of gocolor:
#   -color string
#         color to display without # (default "fff")
#   -count int
#         number of shades and tints to generate (default 10)
#   -no-html
#         disable html output
#   -port string
#         port to listen on (default "8080")

The app can be used in two major ways (depending on the presence of the -no-html flag):

  1. Quickly generate shades and tints from the CLI
  2. Run a local web server that hosts a web interface to generate shades and tints
CLI

To use the CLI, a typical command would look like this:

gocolor -color "#FF0000" -no-html

CMD Example Image

Web Server

To use the web server, a typical command would look like this:

gocolor -port 8080 -color FF0000 -count 10

Then, you can visit http://localhost:8080/FF0000?count=10 to see the web interface.

Server Example Image

NOTE that editing the URL address bar will change the color and count.

Summary
Flag Description Default
-color Color to generate shades and tints of.
To be safe do not add "#" as a prefix.
"#" can be added when running in cli mode
fff
-count The number of shades / tints to generate 10
-no-html Disable the web server and only generate shades and tints in the CLI false
-port Port to listen on when running the web server 8080

Contributing

Contributions are welcome!

License

MIT

Author

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	White = RGB(255, 255, 255)
	Black = RGB(0, 0, 0)
)
View Source
var (
	ErrInvalid = func(c Color) error { return fmt.Errorf("invalid color: %v", c) }
)

Functions

func Rmh added in v0.2.2

func Rmh(s string) (string, bool)

Rmh removes the hash from a hex color it returns the string and a bool indicating if there was a hash

Types

type Color

type Color struct {
	R, G, B, A uint32
}

func Hex

func Hex(hex string) (Color, error)

func RGB

func RGB(r, g, b uint32) Color

func RGBA

func RGBA(r, g, b, a uint32) Color

func (Color) Hex

func (c Color) Hex(noAlpha ...bool) string

Hex returns the hex representation of the color Note that it always begins with a hash Hex does not return the alpha channel if Color.A != 255 unless the first value of noAlpha is true

Example
c := RGB(255, 255, 255)
fmt.Println(c.Hex())
Output:

#ffffff

func (Color) HexA

func (c Color) HexA() string

func (Color) IsValid

func (c Color) IsValid() bool

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)
Example
c := White
r, g, b, a := c.RGBA()
fmt.Println(r, g, b, a)
Output:

255 255 255 255

func (Color) Shade

func (c Color) Shade(percent float64) (Color, error)

func (Color) Shades

func (c Color) Shades(n int) ([]Color, error)
Example
c := White
shades, _ := c.Shades(5)
for _, s := range shades {
	fmt.Print(s.Hex(), " ")
}
Output:

#ffffff #cccccc #999999 #666666 #333333

func (Color) Subtract

func (c Color) Subtract(c2 Color) (Color, error)

func (Color) Tint

func (c Color) Tint(percent float64) (Color, error)

func (Color) Tints

func (c Color) Tints(n int) ([]Color, error)

Tints return n tints of the color spread evenly

Example
c := Black
tints, _ := c.Tints(5)
for _, t := range tints {
	fmt.Print(t.Hex(), " ")
}
Output:

#000000 #333333 #666666 #999999 #cccccc

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL