GithubHelp home page GithubHelp logo

mailtruck / tinycolor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bgrins/tinycolor

1.0 3.0 0.0 3.76 MB

Fast, small color manipulation and conversion for JavaScript

Home Page: http://bgrins.github.com/TinyColor/

License: MIT License

tinycolor's Introduction

TinyColor

JavaScript color parsing

Features

  • Color Types Supported ** Hex tinycolor("#000"); tinycolor("000"); tinycolor("#f0f0f6"); tinycolor("f0f0f6"); ** RGB, RGBA tinycolor("rgb (255, 0, 0)"); tinycolor("rgb 255 0 0"); tinycolor("rgba (255, 0, 0, .5)"); tinycolor({ r: 255, g: 0, b: 0 }); ** HSL, HSLA tinycolor("hsl(0, 100%, 50%)"); tinycolor("hsla(0, 100%, 50%, .5)"); tinycolor("hsl(0, 100%, 50%)"); tinycolor("hsl 0 1.0 0.5"); tinycolor({ h: 0, s: 1, l: .5 }"); ** HSV, HSVA tinycolor("hsv(0, 100%, 100%)"); tinycolor("hsva(0, 100%, 100%, .5)"); tinycolor("hsv (0 100% 100%)"); tinycolor("hsv 0 1 1"); tinycolor({ h: 0, s: 100, v: 100 }"); ** Named tinycolor("RED"); tinycolor("blanchedalmond"); tinycolor("darkblue");

  • File Size: The minified size is: The uncompressed size is:

Usage

var t = tinycolor("red");

t.toHex() // "ff0000"
t.toHexString() // "#ff0000"
t.toRgb() // {"r":255,"g":0,"b":0} or {"r":255,"g":0,"b":0,"a":0.5}
t.toRgbString() // "rgb(255, 0, 0)" or "rgba(255, 0, 0, 0.5)"
t.toHsv() // {"h":0,"s":1,"v":1}
t.toHsvString() // "hsv(0, 100%, 100%)"
t.toHsl() // {"h":0,"s":1,"l":0.5}
t.toHslString() // "hsl(0, 100%, 50%)"
t.toName() // "red"

Accepted String Input

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%-100%, or 0-n (where n is either 100, 255, or 360 depending on the value).

HSL and HSV both require either 0%-100% or 0-1. RGB requires either 0-255 or 0%-100%. If you call tinycolor.fromRatio, any input can also accept 0-1 Here are some examples of string input:

red
#fff
fff
#ffffff
ffffff
rgb(255, 0, 0)
rgb 255 0 0
hsl(0, 100, 50)
hsl(0, 100%, 50%)
hsl 0 100 50
hsl 0 100% 50%
hsv(0, 100%, 100%)
hsv(0, 100, 100)
hsv 0 100% 100%
hsv 0 100 100

Accepted Object Input

If you are calling this from code, you may want to use object input. Here are examples of the different types of accepted object inputs:

{ r: 255, g: 0, b: 0 }
{ r: 255, g: 0, b: 0, a: .5 }
{ r: 1, g: 0, b: 0 }
{ h: 0, s: 100, l: 50 }
{ h: 0, s: 100, v: 100 }
etc...

See index.html in the project for a demo.

tinycolor's People

Contributors

bgrins avatar pgooch avatar

Stargazers

Brian Danowski avatar

Watchers

Brian Danowski avatar James Cloos 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.