color

package module
v0.0.0-...-3b2b15d Latest Latest
Warning

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

Go to latest
Published: May 21, 2018 License: MIT Imports: 2 Imported by: 0

README

color

A package for converting from RGB to HSB and back.

  • HSB stands for Hue, Saturation and Brightness
  • RGB stands for Red, Green and Blue

Example usage

example

The above image was generated by the following program:

package main

import (
	hbscolor "github.com/xyproto/color"
	"image"
	"image/png"
	"os"
)

const (
	w = 512
	h = 512
)

func main() {
	// Prepare an image surface
	surface := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{w, h}})

	// Generate an image that shows a smooth transition over all 360 degrees of hues
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			c := hbscolor.NewFromFloats(float64(x)/float64(w), float64(y)/float64(h), float64(y)/float64(h), 1.0).RGBA()
			surface.Set(x, y, c)
		}
	}

	// Prepare the image file
	imageFile, err := os.Create("output.png")
	if err != nil {
		panic(err)
	}
	defer imageFile.Close()

	// Write the surface to file, as a PNG image
	png.Encode(imageFile, surface)
}

General info

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HSB

type HSB struct {
	H    int     // 色相
	S, B float64 // ,饱和度(纯度),l/b亮度
}

HSB stands for hue, saturation and brightness

Example
hsb := NewHSB(color.RGBA{R: 79, G: 24, B: 23})
fmt.Println(hsb.AsInts())
Output:

1 180 79

func NewHSB

func NewHSB(c color.RGBA) HSB

func RGBToHLS

func RGBToHLS(rgb color.RGBA) HSB

RGBToHLS is deprecated, use New instead

func (*HSB) AsInts

func (h *HSB) AsInts() (int, int, int)

AsInts is deprecated, use hsba AsInts instead

func (HSB) Gethsb

func (h HSB) Gethsb() (int, int, int)

Gethsb is deprecated, use hsba AsInts() instead

func (HSB) HSB2RGB

func (hsb HSB) HSB2RGB() color.RGBA

HSB2RGB is deprecated, use hsba RGBA() instead

func (HSB) RGB

func (hsb HSB) RGB() color.RGBA

HSB2RGB is deprecated, use hsba RGBA() instead

type HSBA

type HSBA struct {
	H    int     // hue, from 0 to 360
	S, B float64 // saturation, brightness, from 0 to 1
	A    float64 // alpha, from 0 to 1
}

HSBA stands for hue, saturation, brightness and alpha

Example
h := &HSBA{H: 1, B: 71, S: 31, A: 1.0}
rgba := h.RGBA()
fmt.Println(rgba)
Output:

{185 221 82 255}

func New

func New(rgb color.RGBA) *HSBA

New takes a color.RGBA struct and returns a pointer to an HSBA struct

func NewFromFloats

func NewFromFloats(h, s, b, a float64) *HSBA

NewFromFloats takes hue, saturation, brightness and alpha as four floats and returns a pointer to an HSBA struct

func (*HSBA) AsInts

func (h *HSBA) AsInts() (int, int, int, int)

AsInts returns the hue, saturation, brightness and alpha values as four integers, from 0 to 360, 0 to 255, 0 to 255 and 0 to 255

func (*HSBA) RGB

func (h *HSBA) RGB() color.RGBA

Return the color as RGB bytes, in a color.RGBA struct

func (*HSBA) RGBA

func (h *HSBA) RGBA() color.RGBA

Return the color as RGBA bytes, in a color.RGBA struct

func (*HSBA) WithoutAlpha

func (h *HSBA) WithoutAlpha() *HSB

Return the color as HSB, without Alpha

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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