tinycolor: Create a tinycolor.

Description Usage Arguments Details Value Examples

Description

Create a vector of valid colors from Hex, 8-bit Hex, Rgb, Rgba, Hsl, Hsla, Hsv, Hsva, and so on.

Usage

1
2
3
tinycolor(x, na.rm = FALSE)

from_ratio(x, hex = FALSE, na.rm = FALSE)

Arguments

x

a any type color string or a javascript color object specifying.

na.rm

a logical value indicating whether NA values should be stripped before the computation proceeds.

Details

The string parsing is very permissive. It is meant to make typing a color as input as easy as possible. All commas, percentages, parenthesis are optional, and most input allow either 0-1, 0 Hsl and Hsv both require either 0 Rgb input requires either 0-255 or 0

Value

a valid color string.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Hex colors
tinycolor("000") # "#000000"
tinycolor("#000") # "#000000"
tinycolor("f0f0f6") # "#F0F0F6"
tinycolor("#f0f0f6") # "#F0F0F6"
tinycolor("#f0f0f688") # "RGBA(240, 240, 246, 0.53)"
# Rgb colors
tinycolor("rgb (255, 0, 0)") # "RGB(255, 0, 0)"
tinycolor("rgb 255 0 0") # "RGB(255, 0, 0)"
tinycolor("rgba (255, 0, 0, 0.5)") # "RGBA(255, 0, 0, 0.5)"
tinycolor("{ r: 255, g: 0, b: 0 }") # "RGB(255, 0, 0)"
# Hsl colors
tinycolor("hsl(0, 100%, 50%)") # "HSL(0, 100%, 50%)"
tinycolor("hsla(0, 100%, 50%, 0.5)") # "HSLA(0, 100%, 50%, 0.5)"
tinycolor("{ h: 0, s: 1, l: 0.5 }") # "HSL(0, 100%, 50%)"
# Hsv colors
tinycolor("hsv(0, 100%, 100%)") # "HSV(0, 100%, 100%)"
tinycolor("hsva(0, 100%, 100%, 0.5)") # "HSVA(0, 100%, 100%, 0.5)"
tinycolor("{ h: 0, s: 100, v: 100 }") # "HSV(0, 100%, 100%)"
# Name colors
tinycolor("RED") # "#FF0000"
tinycolor("blanchedalmond") # "#FFEBCD"
tinycolor("darkblue") # "#00008B"
# From ratio
from_ratio("{r: 1, g: 0, b: 0 }") # "RGB(100%, 0%, 0%)"
from_ratio("{ h: 1, s: 0, l: 0 }") # "HSL(0, 0%, 0%)"
from_ratio("{ h: 0.5, s: 0.5, v: 0.5 }") # "HSV(180, 50%, 50%)"

houyunhuang/tinycolor documentation built on June 6, 2019, 7:43 p.m.