Coder Social home page Coder Social logo

unipalette's Introduction

Unipalette

Usage

unipalette <color palette path> [subcommand]

Subcommands:

  • preview

    Show colors from the palette in the terminal. If --shades is specified, 2 shades ligher and darker will also be displayed.

  • eval <expression>

    Evaluates a color expression from the command line and prints the resulting color. If -c or --colored is specified, then the color will be used to color the text as well. Output formats can be specified with -o using the same characters as in the Syntax section about expanding color references, the default is sRGB hex.

  • expand <path>

    Process the file at or all files ending in .uncol under , expanding color references as explained in the Syntax section, using the palette specified. When processing directories, the resulting expanding file will be written in the same directory as the source file, but without the .uncol extention

Syntax

Color Expressions

Literal colors can either be referred to as LCH triplets or by using CSS color names:

# an lch color
purple=l40c120h300

# a css color
$purple

Operators can affect colors, changing their lightness or saturation.

# purple from above, but 50% more saturated
purple st+50
# purple from above, but 50% less saturated
purple st-50

# purple from above, but 50% darker
purple li-50
# purple from above, but 50% lighter
purple li+50

# set the chroma value directly, making a gray
purple ch10

# set the lightness value directly
purple li=50

Colors can have a specified alpha value as well. By default all colors are opaque.

#  purple from above with 50% transparency
purple a50

Colors can be mixed using the mix operator:

# the color halfway linearly between purple and yellow
purple *0.5* $yellow

Sometimes the mix operator can have surprising results, because it is linear interpolation.

You can compute the complement of a color:

# cyan is the complement of orange
~$orange

Once a function has defined, you can call it to compute a new color:

# a lovely yellow
my_mix($red, $green)

Parenthesis can also be used to group expressions.

Color functions

Functions that operate on colors can be defined in palette files in the following way:

# fn <name>(<args>) = <body>
fn my_mix(a, b) = a *0.5* b
fn const() = $orange

The function body is just any regular color expression. The argument identifiers will be bound with the colors passed in when the function is called. You cannot define a function inside a color reference in a different file, but you can call them.

Color palettes

A color palette file consists of a list of color or function definitions, one per line. # can be used to comment out lines. Once defined, the color can be referred to by name.

purple=l40c120h300
green=$green li+20
color3=purple *0.5* green

Color references in other files

Colors in other files can be referenced using color expressions delimited by ~~! and ! that are expanded using unipalette expand. There are a number of output formatting options.

~~!(alpha specifier)(format specifier)(color expression)!

Format specifier:

  • #: RGB hex code in sRGB color space, with prepended #
  • ~: RGB hex code in linear sRGB color space with prepended #
  • $: CSS RGB triplet rgb(R%, G%, B%)
  • !: CSS LCH triplet lch(L% C H)

Alpha specifier:

  • a: output alpha. When outputting RGB hex codes put the alpha bytes at the end
  • A: output alpha. When outputting RGB hex codes put the alpha bytes at the beginning

unipalette's People

Contributors

andrew-pa avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.