gradient

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: BSD-3-Clause, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gradient implements gradients that can be used with Ilysa.

Index

Constants

This section is empty.

Variables

View Source
var DeclaredGradients = map[string]Table{}
View Source
var Rainbow = Table{
	{colorful.Hex("#9e0142"), 0.0},
	{colorful.Hex("#d53e4f"), 0.1},
	{colorful.Hex("#f46d43"), 0.2},
	{colorful.Hex("#fdae61"), 0.3},
	{colorful.Hex("#fee090"), 0.4},
	{colorful.Hex("#ffffbf"), 0.5},
	{colorful.Hex("#e6f598"), 0.6},
	{colorful.Hex("#abdda4"), 0.7},
	{colorful.Hex("#66c2a5"), 0.8},
	{colorful.Hex("#3288bd"), 0.9},
	{colorful.Hex("#5e4fa2"), 1.0},
}

Functions

This section is empty.

Types

type LerpFn added in v0.0.8

type LerpFn func(c1, c2 colorful.Color, t float64) colorful.Color
var DefaultLerpFn LerpFn = colorful.BlendOklab

DefaultLerpFn is the function used by Lerp to interpolate between two colors.

type Point

type Point struct {
	Col colorful.Color
	Pos float64
}

type Set

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

A Set is an ordered set of gradients. Set provides convenience methods such as picking a random gradient from a Set (Set.Rand()) and picking successive gradients from a Set (Set.Next()).

func NewSet

func NewSet(gradients ...Table) Set

NewSet returns a new Set containing gradients.

func (Set) Idx added in v0.0.8

func (s Set) Idx(i int) Table

Idx returns the gradient at the ith position. Idx is syntax sugar for Index.

func (Set) Index

func (s Set) Index(i int) Table

Index returns the gradient at the ith position. If i is out of range, i is "wrapped around" to bring it back in range.

func (Set) Next

func (s Set) Next() Table

Next return successive gradients from the Set each time it is called, starting with the first gradient.

func (Set) Rand

func (s Set) Rand() Table

Rand returns a random gradient from the Set.

type Table

type Table []Point

Table represents a gradient and contains its "points". The position of each keypoint must lie in the range [0,1] and points must be sorted in ascending order.

func FromSet

func FromSet(s colorful.Set) Table

FromSet creates a gradient from a colorful.Set.

func New

func New(colors ...colorful.Color) Table

New returns a gradient with colors equidistant from each other.

func NewPingPong

func NewPingPong(count int, colors ...colorful.Color) Table

NewPingPong returns a gradient consisting of: (1) colors in order; followed by (2) count copies of colors, alternating between:

(a) colors in reverse order, with the first color omitted; and
(b) colors in order, with the first color omitted.

func (Table) Boost added in v0.0.6

func (gt Table) Boost(m float64) Table

Boost returns a new gradient with each color's RGB value multiplied by m. Boost does not affect a color's A or position.

func (Table) Colors

func (gt Table) Colors() []colorful.Color

Colors returns the gradient's colors as a slice of colorful.Colors.

func (Table) Lerp

func (gt Table) Lerp(t float64) colorful.Color

Lerp returns interpolated color at t. By default, the interpolation is done in the Oklab colorspace. Change DefaultLerpFn to change the default. Use LerpIn to interpolate in a specific colorspace.

func (Table) LerpIn added in v0.0.8

func (gt Table) LerpIn(t float64, fn LerpFn) colorful.Color

LerpIn returns the interpolated color at t, with the interpolation done by fn.

func (Table) Reverse

func (gt Table) Reverse() Table

Reverse returns a copy of the gradient with its colors' order reversed.

func (Table) Rotate

func (gt Table) Rotate(n int) Table

Rotate returns a copy of the gradient with its colors rotated to the left by n.

func (Table) RotateRand

func (gt Table) RotateRand() Table

RotateRand returns a new gradient rotated by a random number.

func (Table) Set added in v0.0.8

func (gt Table) Set() colorful.Set

Set returns the gradient's colors as a colorful.Set.

func (Table) ToSet deprecated

func (gt Table) ToSet() colorful.Set

ToSet returns the gradient's colors as a colorful.Set.

Deprecated: use Set() instead.

Jump to

Keyboard shortcuts

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