1.1.4 • Published 8 years ago

color.proto.js v1.1.4

Weekly downloads
2
License
CC-BY-NC-SA-3.0
Repository
github
Last release
8 years ago

Color.proto.js

1.1

A JavaScript prototype to manipulate colors.

var myBlue = new Color("#3366ff");
// Saturates the color 10%, then darken it 5% and then outputs it as in "rgba" format
myBlue.saturate(10).darken(5).rgba

Constructor

The Color can be constructed from colors in hex, rgb, rgba, hsl, hsla, hsv (hsb), hsva (hsba), cmyk, cmyka, any valid keyword, any predefined color name (from the library), or red green and blue values (255 based).

new Color("#3366ff");
new Color("rgb(51,102,255)");
new Color("rgba(51,102,255,1)");
new Color("hsl(225,100,60)");
new Color("hsla(225,100,60,1)");
new Color("hsv(225,80,100)");
new Color("hsva(225,80,100,1)");
new Color("cmyk(80,60,0,0)");
new Color("cmyka(80,60,0,0,1)");
new Color("blue");
new Color(51, 102, 255);
new Color(51, 102, 255, 1);
Color.library.myBlue = "#3366ff";
new Color("myBlue");

Members

Here are the members of Color objects:

red

The "red" value of the color (between 0 and 255).

blue

The "blue" value of the color (between 0 and 255).

green

The "green" value of the color (between 0 and 255).

alpha

The "alpha" value (opacity) of the color (between 0 and 1).

hue

The "hue" value of the color (between 0 and 360 degrees).

lightness

The "lightness" value of the color (between 0% and 100%).

brightness

The "brightness" value of the color (between 0% and 100%).

saturation

The "saturation" value of the color (between 0% and 100%).

cyan

The "cyan" value of the color (between 0% and 100%).

magenta

The "magenta" value of the color (between 0% and 100%).

yellow

The "yellow" value of the color (between 0% and 100%).

black

The "black" value of the color (between 0% and 100%).

rgb

The color as a string in "rgb" format.

rgba

The color as a string in "rgba" format.

hex

The color as a string in "hex" format.

hsl

The color as a string in "hsl" format.

hsla

The color as a string in "hsla" format.

hsv

The color as a string in "hsv" format.

hsva

The color as a string in "hsva" format.

cymk

The color as a string in "cmyk" format.

cmyka

The color as a string in "cmyka" foramt.

Methods

Here are the methods of Color objects. These methods return a new object, they do not modify the current one.

clone()

Returns a copy of this color.

grayscale([method])

Returns the grayscale version of this color.

saturate(amount)

Returns a color with it's saturation increased by the specified amount (percentage).

desaturate(amount)

Returns a color with it's saturation decrease by the specified amount (percentage).

darken(amount)

Returns a color with it's lightness decrease by the specified amount (percentage).

lighten(amount)

Returns a color with it's lightness increase by the specified amount (percentage).

shift(amount)

Returns a color with it's hue shifted by the specified amount (between -360 degrees and 360 degrees).

inverse()

Returns the inverse color.

accent()

Returns an a color that is 12.5% brighter and 12.5% more saturated.

blend(color [, percentage])

Returns a color that is a blend between this color and the specified color. You can specify how much blending occurs, 1% = closes to this color, 50% = half way between the colors, 99% = closest to the specified color.

palette(amount)

Returns a color in the same monochromatic palette as this color, specify an amount (0 = white, 500 = this color, 1000 = black).

toString()

Returns this color as an rgb (or rgba) string.

fromString(string)

Creates this color from a parsed string in any format (same as constructor).

toObject()

Returns this color (all of it's members) as a literal object.

fromObject(object)

Creates this color from a literal object, based on the available members.

Library

You can access and add to the color library using Color.library.

Define a color

Define a color named "primary":

Color.library.primary = "#3366ff";
Get a color

Get the "primary" color:

var myColor = Color.library.primary;
Get all predefined colors as an object
var myColors = Color.library;

License

This software is property of Dustin Poissant.

This software is distributed AS-IS with no warranties/guarantees either expressed or implied.

This software is Licensed under CC BY-NC-SA 3.0 US.

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago