gradient

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 5 Imported by: 3

README

Gradient

Installation
go get github.com/iskaa02/qalam/gradient
Usage
g,err:=gradient.NewGradient("cyan","red")
// if the passed colors are not valid an error is returned
// supports all css valid colors
if err != nil{
}
g.Print("Example gradient from Cyan to Red")

outputs the following

gradient Example

Methods
  • Apply() Apply the gradient without printing

  • Print() Apply the gradient and print

  • Multiline Apply the gradient to multi-line string

	g,_ := gradient.
	NewGradient("#FEAC5E", "#C779D0", "#4BC0C8")
	fmt.Println(g.Mutline(`
 $$$$$$\            $$\
$$  __$$\           $$ |
$$ /  $$ | $$$$$$\  $$ | $$$$$$\  $$$$$$\$$$$\
$$ |  $$ | \____$$\ $$ | \____$$\ $$  _$$  _$$\
$$ |  $$ | $$$$$$$ |$$ | $$$$$$$ |$$ / $$ / $$ |
$$ $$\$$ |$$  __$$ |$$ |$$  __$$ |$$ | $$ | $$ |
\$$$$$$ / \$$$$$$$ |$$ |\$$$$$$$ |$$ | $$ | $$ |
 \___$$$\  \_______|\__| \_______|\__| \__| \__|
     \___|
	`))

multi-line text

Gradient Builders

gradient builder enable more customization on the gradients

Basic
g,_:=gradient.NewGradientBuilder().Build()
g.Print("A Basic Gradient Example")

Basic Gradient

Custom Colors

Colors() method accept anything that implement color.Color interface

g,_:= colorgrad.NewGradient().
    Colors(
        color.RGBA{0, 206, 209, 255},
        color.RGBA{255, 105, 180, 255},
        colorful.Color{R: 0.274, G: 0.5, B: 0.7},
        colorful.Hsv(50, 1, 1),
        colorful.Hsv(348, 0.9, 0.8),
    ).
    Build()
g.Print("Custom Color Gradient Example")    

Custom Color gradient

CSS Colors

HtmlColors() method accepts named colors, hexadecimal (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb(), rgba(), hsl(), hsla(), hwb(), and hsv().

g,_:= colorgrad.NewGradient().
    HtmlColors("#C41189", "hotpink", "rgb(90%,45%,97%)").
    Build()
g.Print("CSS colors Gradient Example")

CSS Color gradient

More Styles

ANSIstyle() accept any ansi code provided by the qalam package.

g, _ := gradient.NewGradientBuilder().
	HtmlColors("#00DBDE", "#FC00FF").
	ANSIstyle("bold", "underline").
	Build()
g.Print("Gradient Example with Extra styles")

gradient with extra style example

More
Preset Gradients

gradient package ships with Prebuilt gradients

  • Rainbow
  • Summer
  • Vice
// each one of those functions take asni style as parameter
// and returns a gradient
gradient.Rainbow("underline")
.Print("Rainbow Example Gradient\n")
gradient.Summer("bold").
.Print("Summer Example Gradient\n")
gradient.Vice("italic").
Print("Vice Example Gradient")

Preset example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlendMode

type BlendMode int
const (
	BlendHcl BlendMode = iota
	BlendHsv
	BlendLab
	BlendLinearRgb
	BlendLuv
	BlendRgb
	BlendOklab
)

type GradBuilder

type GradBuilder struct {
	// contains filtered or unexported fields
}

func NewGradientBuilder

func NewGradientBuilder() *GradBuilder

NewGradientBuilder return Gradient Builder for more customization

func (*GradBuilder) ANSIstyle

func (g *GradBuilder) ANSIstyle(styles ...string) *GradBuilder

ANSIstyle accept ansi styles provided

func (*GradBuilder) Build

func (g *GradBuilder) Build(c ...string) (Gradient, error)

func (*GradBuilder) Colors

func (g *GradBuilder) Colors(c ...color.Color) *GradBuilder

Colors accept anything that implement color.Color interface.

func (*GradBuilder) Domain

func (g *GradBuilder) Domain(d ...float64) *GradBuilder

Changes the ratio between colors, default: [0,1]

func (*GradBuilder) HtmlColors

func (g *GradBuilder) HtmlColors(c ...string) *GradBuilder

HtmlColors accepts any valid css color including named colors, hexadecimal (#rgb, #rgba, #rrggbb, #rrggbbaa), rgb(), rgba(), hsl(), hsla(), hwb(), and hsv().

func (*GradBuilder) Mode

func (g *GradBuilder) Mode(m BlendMode) *GradBuilder

Mode change the belnding mode for the gradient default is BlendRgb available modes: BlendRgb,BlendLinearRgb,BlendHcl,BlendHsv,BlendLab,BlendLuv,BlendOklab

type Gradient

type Gradient struct {
	// contains filtered or unexported fields
}

func NewGradient

func NewGradient(c ...string) (Gradient, error)

NewGradient take any valid css color

func Rainbow

func Rainbow(otherStyle ...string) Gradient

Rainbow Pre-defiend gradient Rainbow

func Summer

func Summer(otherStyle ...string) Gradient

Summer pre-defiend gradient [#fdbb2d,#22c1c3]

func Vice

func Vice(otherStyle ...string) Gradient

Vice Pre-defiend gradient [#5ee7df,#b490ca]

func (Gradient) Apply

func (g Gradient) Apply(s string) string

Apply Gradinet to provided string

func (Gradient) Mutline

func (g Gradient) Mutline(s string) string

Mutline Apply gradient to mutline string

func (Gradient) Print

func (g Gradient) Print(s string)

Apply Gradient to string and print it

Jump to

Keyboard shortcuts

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