Index

ColorSchemeTools.add_alphaFunction
add_alpha(cs::ColorScheme, alpha::Real=0.5)

Make a copy of the colorscheme cs with alpha opacity value alpha.

Example

Make a copy of the PuOr colorscheme and set every element of it to have alpha opacity 0.5

add_alpha(ColorSchemes.PuOr, 0.5)
source
ColorSchemeTools.add_alphaMethod
add_alpha(cs::ColorScheme, r::Range)

Make a copy of the colorscheme cs with alpha opacity values in the range r.

Example

Make a copy of the PuOr colorscheme, set the first element to have alpha opacity 0.5, the last element to have opacity 0.0, with intermediate elements taking values between 0.5 and 1.0.

add_alpha(ColorSchemes.PuOr, 0.5:0.1:1.0)
source
ColorSchemeTools.add_alphaMethod
add_alpha(cs::ColorScheme, f::Function)

Make a copy of the colorscheme cs with alpha opacity values defined by the function.

Example

Make a copy of the PuOr colorscheme, set the opacity of each element to be the result of calling the function on the value. So at value 0.5, the opacity is 1.0, but it's 0.0 at either end.

add_alpha(ColorSchemes.PuOr, (n) -> sin(n * π))
source
ColorSchemeTools.add_alphaMethod
add_alpha(cs::ColorScheme, alpha::Vector)

Make a copy of the colorscheme cs with alpha opacity values in the vector alpha.

Example

Make a copy of the PuOr colorscheme, set the first element to have alpha opacity 1.0, the last element to have opacity 0.0, with intermediate elements taking values between 1.0 and 0.0.

add_alpha(ColorSchemes.PuOr, [1.0, 0.0])
source
ColorSchemeTools.colorscheme_to_imageFunction
colorscheme_to_image(cs, nrows=50, tilewidth=5)

Make an image from a ColorScheme by repeating the colors in nrows rows, repeating each pixel tilewidth times.

Returns the image as an array.

Examples:

using FileIO

img = colorscheme_to_image(ColorSchemes.leonardo, 50, 200)
save("/tmp/cs_image.png", img)

save("/tmp/blackbody.png", colorscheme_to_image(ColorSchemes.blackbody, 10, 100))
source
ColorSchemeTools.colorscheme_to_textMethod
colorscheme_to_text(cscheme::ColorScheme, schemename, filename;
    category="dutch painters",   # category
    notes="it's not really lost" # notes
)

Write a ColorScheme to a Julia text file.

Example

colorscheme_to_text(ColorSchemes.vermeer,
    "the_lost_vermeer",          # name
    "/tmp/the_lost_vermeer.jl",  # file
    category="dutch painters",   # category
    notes="it's not really lost" # notes
    )

and read it back in with:

include("/tmp/the_lost_vermeer.jl")
source
ColorSchemeTools.colorscheme_weightedFunction
colorscheme_weighted(colorscheme, weights, length)

Returns a new ColorScheme of length length (default 50) where the proportion of each color in colorscheme is represented by the associated weight of each entry.

Examples:

colorscheme_weighted(extract_weighted_colors("hokusai.jpg")...)
colorscheme_weighted(extract_weighted_colors("filename00000001.jpg")..., 500)
source
ColorSchemeTools.compare_colorsFunction
compare_colors(color_a, color_b, field = :l)

Compare two colors, using the Luv colorspace. field defaults to luminance :l but could be :u or :v. Return true if the specified field of color_a is less than color_b.

source
ColorSchemeTools.convert_to_schemeMethod
convert_to_scheme(cscheme, img)

Converts img from its current color values to use only the colors defined in the ColorScheme cscheme.

image = nonTransparentImg
convert_to_scheme(ColorSchemes.leonardo, image)
convert_to_scheme(ColorSchemes.Paired_12, image)
source
ColorSchemeTools.extractFunction
extract(imfile, n=10, i=10, tolerance=0.01; shrink=n)

extract() extracts the most common colors from an image from the image file imfile by finding n dominant colors, using i iterations. You can (and probably should) shrink larger images before running this function.

Returns a ColorScheme.

source
ColorSchemeTools.extract_weighted_colorsFunction
extract_weighted_colors(imfile, n=10, i=10, tolerance=0.01; shrink = 2)

Extract colors and weights of the clusters of colors in an image file. Returns a ColorScheme and weights.

Example:

pal, wts = extract_weighted_colors(imfile, n, i, tolerance; shrink = 2)
source
ColorSchemeTools.get_indexed_list_colorMethod
get_indexed_list_color(indexedlist, n)

Get the color at a point n given an indexed list of triples like this:

gist_rainbow = (
       (0.000,   (1.00, 0.00, 0.16)),
       (0.030,   (1.00, 0.00, 0.00)),
       (0.215,   (1.00, 1.00, 0.00)),
       (0.400,   (0.00, 1.00, 0.00)),
       (0.586,   (0.00, 1.00, 1.00)),
       (0.770,   (0.00, 0.00, 1.00)),
       (0.954,   (1.00, 0.00, 1.00)),
       (1.000,   (1.00, 0.00, 0.75))
    )

To make a ColorScheme from this type of list, use:

make_colorscheme(gist_rainbow)
source
ColorSchemeTools.get_linear_segment_colorMethod
get_linear_segment_color(dict, n)

Get the RGB color for value n from a dictionary of linear color segments.

This following is a dictionary where red increases from 0 to 1 over the bottom half, green does the same over the middle half, and blue over the top half:

cdict = Dict(:red  => ((0.0,  0.0,  0.0),
                       (0.5,  1.0,  1.0),
                       (1.0,  1.0,  1.0)),
            :green => ((0.0,  0.0,  0.0),
                       (0.25, 0.0,  0.0),
                       (0.75, 1.0,  1.0),
                       (1.0,  1.0,  1.0)),
            :blue =>  ((0.0,  0.0,  0.0),
                       (0.5,  0.0,  0.0),
                       (1.0,  1.0,  1.0)))

The value of RGB component at every value of n is defined by a set of tuples. In each tuple, the first number is x. Colors are linearly interpolated in bands between consecutive values of x; if the first tuple is given by (Z, A, B) and the second tuple by (X, C, D), the color of a point n between Z and X will be given by (n - Z) / (X - Z) * (C - B) + B.

For example, given an entry like this:

:red  => ((0.0, 0.0, 0.0),
          (0.5, 1.0, 1.0),
          (1.0, 1.0, 1.0))

and if n = 0.75, we return 1.0; 0.75 is between the second and third segments, but we'd already reached 1.0 (segment 2) when n was 0.5.

source
ColorSchemeTools.image_to_swatchMethod
image_to_swatch(imagefilepath, samples, destinationpath;
    nrows=50,
    tilewidth=5)

Extract a ColorsSheme from the image in imagefilepath to a swatch image PNG in destinationpath. This just runs sortcolorscheme(), colorscheme_to_image(), and save() in sequence.

Specify the number of colors. You can also specify the number of rows, and how many times each color is repeated.

image_to_swatch("monalisa.jpg", 10, "/tmp/monalisaswatch.png")
source
ColorSchemeTools.lerpFunction
lerp((x, from_min, from_max, to_min=0.0, to_max=1.0)

Linear interpolation of x between from_min and from_max.

Example

ColorSchemeTools.lerp(128, 0, 256)
0.5
source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(f1::Function, f2::Function, f3::Function, f4::Function;
    model    = :RGBA,
    length   = 100,
    category = "",
    notes    = "functional ColorScheme")

Make a colorscheme with transparency using functions. Each argument is a function that returns a value for the red, green, blue, and alpha components for the values between 0 and 1.

model is the color model, and can be :RGBA, :HSVA, or :LCHabA.

Use length keyword to set the number of colors in the colorscheme.

The default color mo del is :RGBA, and the functions should return values in the appropriate range:

  • f1 - [0.0 - 1.0] - red
  • f2 - [0.0 - 1.0] - green
  • f3 - [0.0 - 1.0] - blue
  • f4 - [0.0 - 1.0] - alpha

For the :HSVA color model:

  • f1 - [0.0 - 360.0] - hue
  • f2 - [0.0 - 1.0] - saturataion
  • f3 - [0.0 - 1.0] - value (brightness)
  • f4 - [0.0 - 1.0] - alpha

For the :LCHabA color model:

  • f1 - [0.0 - 100.0] - luminance
  • f2 - [0.0 - 100.0] - chroma
  • f3 - [0.0 - 360.0] - hue
  • f4 - [0.0 - 1.0] - alpha

Examples

csa = make_colorscheme1(
    n -> red(get(ColorSchemes.leonardo, n)), 
    n -> green(get(ColorSchemes.leonardo, n)), 
    n -> blue(get(ColorSchemes.leonardo, n)), 
    n -> 1 - identity(n))
source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(colorlist, steps)

Make a new colorscheme consisting of the colors in the array colorlist.

make_colorscheme([RGB(1, 0, 0), HSB(285, 0.7, 0.7), colorant"darkslateblue"], 20)
source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(dict;
    length=100,
    category="",
    notes="")

Make a new ColorScheme from a dictionary of linear-segment information. Calls get_linear_segment_color(dict, n) with n for every length value between 0 and 1.

source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(f1::Function, f2::Function, f3::Function;
    model    = :RGB,
    length   = 100,
    category = "",
    notes    = "functional ColorScheme")

Make a colorscheme using functions. Each argument is a function that returns a value for the red, green, and blue components for the values between 0 and 1.

model is the color model, and can be :RGB, :HSV, or :LCHab.

Use length keyword to set the number of colors in the colorscheme.

The default color model is :RGB, and the functions should return values in the appropriate range:

  • f1 - [0.0 - 1.0] - red
  • f2 - [0.0 - 1.0] - green
  • f3 - [0.0 - 1.0] - blue

For the :HSV color model:

  • f1 - [0.0 - 360.0] - hue
  • f2 - [0.0 - 1.0] - saturataion
  • f3 - [0.0 - 1.0] - value (brightness)

For the :LCHab color model:

  • f1 - [0.0 - 100.0] - luminance
  • f2 - [0.0 - 100.0] - chroma
  • f3 - [0.0 - 360.0] - hue

Example

Make a colorscheme with the red component defined as a sine curve running from 0 to π and back to 0, the green component is always 0, and the blue component starts at π and goes to 0 at 0.5 (it's clamped to 0 after that).

make_colorscheme(n -> sin(n * π), n -> 0, n -> cos(n * π))
source
ColorSchemeTools.make_colorschemeMethod
make_colorscheme(indexedlist;
    length=length(indexedlist),
    category="",
    notes="")

Make a ColorScheme using an 'indexed list' like this:

gist_rainbow = (
       (0.000, (1.00, 0.00, 0.16)),
       (0.030, (1.00, 0.00, 0.00)),
       (0.215, (1.00, 1.00, 0.00)),
       (0.400, (0.00, 1.00, 0.00)),
       (0.586, (0.00, 1.00, 1.00)),
       (0.770, (0.00, 0.00, 1.00)),
       (0.954, (1.00, 0.00, 1.00)),
       (1.000, (1.00, 0.00, 0.75))
)

make_colorscheme(gist_rainbow)

The first element of each item is the point on the colorscheme.

Use length keyword to set the number of colors in the colorscheme.

source
ColorSchemeTools.sortcolorschemeFunction
sortcolorscheme(colorscheme::ColorScheme, field; kwargs...)

Sort (non-destructively) a colorscheme using a field of the LUV colorspace.

The less than function is lt = (x,y) -> compare_colors(x, y, field).

The default is to sort by the luminance field :l but could be by :u or :v.

Returns a new ColorScheme.

source