Back to godoc.org

Package gradient

v0.0.0 (0022984)
Latest Go to latest
Published: May 13, 2020 | License: BSD-3-Clause | Module: golang.org/x/exp

Overview

Package gradient provides linear and radial gradient images.

Index

Package Files

type Gradient

type Gradient struct {
	Shape  Shape
	Spread Spread

	// Pix2Grad transforms coordinates from pixel space (the arguments to the
	// Image.At method) to gradient space. Gradient space is where a linear
	// gradient ranges from x == 0 to x == 1, and a radial gradient has center
	// (0, 0) and radius 1.
	//
	// This is an affine transform, so it can represent elliptical gradients in
	// pixel space, including non-axis-aligned ellipses.
	//
	// For a linear gradient, the bottom row is ignored.
	Pix2Grad f64.Aff3

	Ranges []Range

	// First and Last are the first and last stop's colors.
	First, Last color.RGBA64
}

Gradient is a very large image.Image (the same size as an image.Uniform) whose colors form a gradient.

func (*Gradient) At

func (g *Gradient) At(x, y int) color.Color

At satisfies the image.Image interface.

func (*Gradient) Bounds

func (g *Gradient) Bounds() image.Rectangle

Bounds satisfies the image.Image interface.

func (*Gradient) ColorModel

func (g *Gradient) ColorModel() color.Model

ColorModel satisfies the image.Image interface.

func (*Gradient) Init

func (g *Gradient) Init(shape Shape, spread Spread, pix2Grad f64.Aff3, stops []Stop)

Init initializes g to a gradient whose geometry is defined by shape and pix2Grad and whose colors are defined by spread and stops.

type Range

type Range struct {
	Offset0 float64
	Offset1 float64
	Width   float64
	R0      float64
	R1      float64
	G0      float64
	G1      float64
	B0      float64
	B1      float64
	A0      float64
	A1      float64
}

Range is the range between two stops.

func AppendRanges

func AppendRanges(a []Range, stops []Stop) []Range

AppendRanges appends to a the ranges defined by a's implicit final stop (if any exist) and stops.

func MakeRange

func MakeRange(s0, s1 Stop) Range

MakeRange returns the range between two stops.

type Shape

type Shape uint8

Shape is the gradient shape.

const (
	ShapeLinear Shape = iota
	ShapeRadial
)

type Spread

type Spread uint8

Spread is the gradient spread, or how to spread a gradient past its nominal bounds (from offset being 0.0 to offset being 1.0).

const (
	// SpreadNone means that offsets outside of the [0, 1] range map to
	// transparent black.
	SpreadNone Spread = iota
	// SpreadPad means that offsets below 0 and above 1 map to the colors that
	// 0 and 1 would map to.
	SpreadPad
	// SpreadReflect means that the offset mapping is reflected start-to-end,
	// end-to-start, start-to-end, etc.
	SpreadReflect
	// SpreadRepeat means that the offset mapping is repeated start-to-end,
	// start-to-end, start-to-end, etc.
	SpreadRepeat
)

func (Spread) Clamp

func (s Spread) Clamp(x float64) float64

Clamp clamps x to the range [0, 1]. If x is outside that range, it is converted to a value in that range according to s's semantics. It returns -1 if s is SpreadNone and x is outside the range [0, 1].

type Stop

type Stop struct {
	Offset float64
	RGBA64 color.RGBA64
}

Stop is an offset and color.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier