palette

package
v0.0.0-...-e7516ef Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package palette summarizes the colors of a website.

Index

Constants

This section is empty.

Variables

View Source
var Painters = map[string]Painter{
	"band (horizontal)": &BandPainter{},
	"band (vertical)":   &BandPainter{vertical: true},
	"circle":            &CirclePainter{},
	"circle (reverse)":  &CirclePainter{reverse: true},
}

Painters is a map of Painter implementations with names as keys.

Functions

This section is empty.

Types

type BandPainter

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

BandPainter draws a rectangle for each color. The width is based on the score of each color.

func (*BandPainter) Paint

func (painter *BandPainter) Paint(p *Palette, s *svg.SVG, job PaintJob)

Paint implements Painter

type CirclePainter

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

CirclePainter draws a circle for each color. The radius is based on the score of each color. Only circles, no ellipses are drawn: use width == height

func (*CirclePainter) Paint

func (painter *CirclePainter) Paint(p *Palette, s *svg.SVG, job PaintJob)

Paint implements Painter

type ColorScore

type ColorScore struct {
	Score int
	Color *colorful.Color
}

ColorScore is the resulting score for a specific color.

func (ColorScore) String

func (c ColorScore) String() string

type PaintJob

type PaintJob struct {
	// Maximum width and height in pixels
	Width, Height int
	// Maximum amount of unique colors to keep
	Max int
}

PaintJob contains common options for all Painters.

type Painter

type Painter interface {
	Paint(p *Palette, s *svg.SVG, job PaintJob)
}

Painter interface for drawing SVGs based on a Palette and PaintJob

type Palette

type Palette []*ColorScore

Palette is a list of Colors sorted by score. The score is calculated by anything that implements the palette.Score interface.

func Group

func Group(cml *css.CML, scorer Scorer) Palette

Group a CML (ColorMention list) as a Palette. Mentions are grouped by color and scored with the specified Scorer implementation. If scorer is nil, it will fall back on palette.SumScore

func New

func New(ctx context.Context, url string, scorer Scorer) (Palette, error)

New creates a Palette from a websites CSS colors. Colors are sorted by their score.

func (Palette) Len

func (p Palette) Len() int

func (Palette) Less

func (p Palette) Less(i, j int) bool

func (*Palette) Paint

func (pal *Palette) Paint(painter Painter, job PaintJob) []byte

Paint a Palette using a Painter and PaintJob.

func (Palette) ScoreSum

func (p Palette) ScoreSum() int

ScoreSum returns the sum of the score of all ColorScores.

func (Palette) String

func (p Palette) String() string

func (Palette) Swap

func (p Palette) Swap(i, j int)

func (Palette) Trim

func (p Palette) Trim(max int) Palette

Trim returns a new Palette with max amount of colors. Boring colors are ignored if possible.

type Scorer

type Scorer interface {
	Score(cml *css.CML, cm *css.ColorMention) int
}

Scorer must return a score for a single ColorMention. It is used by palette.Group to weigh and sort colors. The CML containing the ColorMention is also passed to allow access to the URL.

type SumScore

type SumScore struct{}

SumScore returns a score of 1 for every ColorMention. This way colors are simply scored by their frequency.

func (*SumScore) Score

func (sc *SumScore) Score(cml *css.CML, cm *css.ColorMention) int

Score implements palette.Scorer

Jump to

Keyboard shortcuts

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