Package 'painter'

Title: Creation and Manipulation of Color Palettes
Description: Functions for creating color palettes, visualizing palettes, modifying colors, and assigning colors for plotting.
Authors: Brody Sandel [aut, cre]
Maintainer: Brody Sandel <[email protected]>
License: GPL-3
Version: 0.1.0
Built: 2024-11-01 11:16:05 UTC
Source: https://github.com/cran/painter

Help Index


Assign colors using one or two numeric vectors

Description

These functions are intended to be used to color plotting symbols according to some numeric values or pair of numeric values associated with each point

Usage

ColorBy(x, palette)
ColorBy2(x,y,palette1, palette2, mode = "RGB")

Arguments

x

A vector of numeric values to color the points by

y

A vector of numeric values to color the points by, must be of the same length as x

palette

A vector of colors

palette1

A vector of colors

palette2

A vector of colors

mode

Specifies whether color mixtures should be in "RGB" or "HSV" mode

Value

A vector of colors of the same length as x

Author(s)

Brody Sandel

Examples

x = runif(100)
y = runif(100)

colors = ColorBy(x,rainbow(100))
plot(x,y,col=colors,pch=16,cex=2)

colors = ColorBy2(x,y,SetSaturation("Red",seq(0,1,0.1)),SetSaturation("Blue",seq(0,1,0.1)))
plot(x,y,col=colors,pch=16,cex=2)

Generate the complement (opposite hue) of a color, or generate a palette from a color and its complement.

Description

Given a color, Complement() maintains the same value and saturation, but returns a color of the opposite hue. ComplementPalette() creates a color palette that ramps between a color and its complement.

Usage

Complement(color)
ComplementPalette(color,n=100)

Arguments

color

A color or (for Complement) possibly a vector of colors

n

The number of colors to produce

Value

For Complement(), a vector of colors with the same length as color. For ComplementPalette() a vector of n colors

Author(s)

Brody Sandel

Examples

TestPalette(Complement(terrain.colors(100)))
TestPalette(ComplementPalette("blue"))

Extract the opacity, hue, saturation or value from a color or vector of colors

Description

These functions simply extact information about a given color or vector of colors, given either as names (e.g. "red") or hex codes (e.g. "FF0000")

Usage

GetOpacity(color)
GetHue(color)
GetSaturation(color)
GetValue(color)

Arguments

color

A color or vector of colors

Value

Numeric value(s) between 0 and 1, with the same length as color

Author(s)

Brody Sandel

Examples

GetValue("red")
GetOpacity("blue")
GetHue(rainbow(100))

Create mixtures of color pairs, in either RGB or HSV mode.

Description

Creates a mixture between pairs of colors by averaging their red/green/blue components (RGB mode), or hue/saturation/value components (HSV mode)

Usage

Mix(color1, color2, mode = "RGB",circular = TRUE)

Arguments

color1

A color or vector of colors, either specified by name (e.g. "red") or hex code (e.g. "FF0000")

color2

A second color or vector of colors. If color1 and color2 are not the same length, but one is an integer multiple of the other, the shorter one will be recycled.

mode

Either "RGB" or "HSV", specifies whether to find the intermediate color in RGB space or HSV space.

circular

If using mode = "HSV", specifies whether to ramp between hues using circular means. This is usually a good idea because hues are essentially circular (a hue of 0.01 is very similar to 0.99).

Value

A color

Author(s)

Brody Sandel

Examples

TestPalette(Mix("Red","Yellow"))

TestPalette(c("Red",Mix("Red","Yellow"),"Yellow"))
TestPalette(c("salmon",Mix("salmon","turquoise"),"turquoise"))
TestPalette(c("salmon",Mix("salmon","turquoise",mode = "HSV"),"turquoise"))
TestPalette(Mix(rainbow(10),terrain.colors(10)))

Generates a color palette (a vector of colors) between two specified colors.

Description

Generates a vector of n colors that ramp between the two specified colors, evenly spaced in either RGB space (mode = "RGB") or HSV space (mode = "HSV")

Usage

Palette(color1, color2, n, mode = "RGB",circular = TRUE)

Arguments

color1

A color, either specified by name (e.g. "red") or hex code (e.g. "FF0000")

color2

A second color

n

The number of colors to produce

mode

Either "RGB" or "HSV", specifies whether to ramp between the colors in RGB space or HSV space.

circular

If using mode = "HSV", specifies whether to ramp between hues using circular means. This is usually a good idea because hues are essentially circular (a hue of 0.01 is very similar to 0.99), but produces results with a clear break if the span of hues covers more than half of the circle.

Value

A vector of n colors.

Author(s)

Brody Sandel

Examples

TestPalette(Palette("Green","Red",100))
TestPalette(Palette("Green","Red",100,"HSV"))

Modify the opacity, hue, saturation or value of color(s)

Description

Change the charactistics of a color or vector of colors

Usage

SetOpacity(color,opacity)
SetHue(color,hue)
SetSaturation(color,saturation)
SetValue(color,value)

Arguments

color

a vector of colors

opacity

a vector of new opacity values

hue

a vector of new hues

saturation

a vector of new saturations

value

a vector of new values

Details

These functions accept colors specified by name (e.g. "red") or hex codes (e.g. "FF0000"). If the color argument and the other argument both have length n, then each color will be assigned the corresponding new opacity, hue, saturation or value. Otherwise, at least one of the arguments should have length 1, in which case each it will be recycled to length n.

Value

A vector of colors of length n.

Author(s)

Brody Sandel

Examples

TestPalette(SetOpacity("red",seq(0,1,0.02)))
TestPalette(SetHue("red",seq(0,1,0.02)))
TestPalette(SetSaturation("red",seq(0,1,0.02)))
TestPalette(SetValue("red",seq(0,1,0.02)))

x = runif(200)
y = runif(200)
color = SetHue("red",x)
color = SetValue(color,y)
plot(x,y,col = color,pch = 16,cex = 2)

Tools for seeing a palette, and how it spans HSV space.

Description

TestPalette() simply produces a row of bars of colors, with as many bars as there are elements of the supplied color vector. VisPalette() displays the HSV values of the palette.

Usage

TestPalette(color)
VisPalette(color)

Arguments

color

A vector of colors.

Value

Nothing is returned.

Author(s)

Brody Sandel

Examples

pal = Palette("Red","Blue",100)
TestPalette(pal)
VisPalette(pal)