Skip to content

Commit

Permalink
Merge pull request #1 from kaanon/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
kaanon committed Jan 5, 2016
2 parents d5106e4 + 67f05ef commit 13d6fa3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 28 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,37 @@ Color utility. Provides functionality to determine the name of a color.
Also provides hue, saturation, value, lightness (or brightness) and can be exported as a css declaration.

## Installation
`bower install colorficial`

TBD
`npm install --save colorficial`

## Usage

### Instantiation

```javascript
var c = new Color(255,100,100);
var c = new Color([255,100,100]);

// Client Side with Bower
var Color = require('../../bower_components/colorficial/dist/color');
// Server Side with node.js
var Color = require('colorficial');

var c = new Color(255,100,100); //red, green, blue
var c = new Color([255,100,100]); // [red, green, blue]
var c = new Color('#FF9922');
var c = new Color({r: 255, g: 100, b: 100});
var c = new Color({red: 255, green: 100, blue: 100});
```
### "is" Methods


### Name Methods
```javascript
var c = new Color([11, 170, 181]);

c.name();
// blue
c.names();
// ["blue","green"]

c.is('red');
// false
Expand Down Expand Up @@ -98,11 +110,13 @@ c.toString()
- black
- white

## Gotchas
Teal (blue/green) and dark pink are pretty 💩. Still working on that.

## TODO
- bower support
- npm support
- more color names
- more color names (extendable?)

## License

[MIT](http://opensource.org/licenses/MIT) © [Kaanon MacFarlane](http://kaanon.com)
4 changes: 2 additions & 2 deletions dist/color.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/colorficial-color.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/is-color-color.map

This file was deleted.

20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
{
"name": "colorficial",
"version": "0.1.0",
"author":"Kaanon MacFarlane <[email protected]>",
"main":"dist/color.js",
"description": "Javascript Class for determining color names",
"devDependencies": {
"babel-core": "^6.3.17",
"babel-loader": "^6.2.0",
"babel-polyfill": "^6.3.14",
"babel-plugin-transform-runtime": "^6.3.13",
"babel-preset-es2015": "^6.3.13",
"gulp-util": "^3.0.7",
"jshint": "^2.5.6",
"webpack": "^1.12.9",
"gulp-nodemon": "^2.0.4",
"gulp":"*"
},
"description": "Javascript Class for determining color names"
"keywords": [
"color",
"color name",
"match",
"brightness",
"hue",
"value",
"saturation",
"is color",
"is",
"lightness"
],
"license": "MIT"
}
33 changes: 18 additions & 15 deletions src/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ class Color {

get hue(){
if(!this._hue){
this.initializeHSLV();
this.__initializeHSLV();
}
return this._hue;
}

get saturation(){
if(!this._saturation){
this.initializeHSLV();
this.__initializeHSLV();
}
return this._saturation;
}

get lightness(){
if(!this._lightness){
this.initializeHSLV();
this.__initializeHSLV();
}
return this._lightness;
}
Expand All @@ -94,7 +94,7 @@ class Color {

get value(){
if(!this._value){
this.initializeHSLV();
this.__initializeHSLV();
}
return this._value;
}
Expand Down Expand Up @@ -190,24 +190,24 @@ class Color {
* @return {number}
*/
distance(rgb){
var xyz1 = this.rgb_to_xyz(this.red, this.green, this.blue),
xyz2 = this.rgb_to_xyz.apply(this,rgb),
lab1 = this.xyz_to_lab.apply(this, xyz1),
lab2 = this.xyz_to_lab.apply(this, xyz2),
difference = this.de_1994(lab1, lab2);
var xyz1 = this.__rgb_to_xyz(this.red, this.green, this.blue),
xyz2 = this.__rgb_to_xyz.apply(this,rgb),
lab1 = this.__xyz_to_lab.apply(this, xyz1),
lab2 = this.__xyz_to_lab.apply(this, xyz2),
difference = this.__de_1994(lab1, lab2);
return difference;
}

/**
* http://www.emanueleferonato.com/2009/08/28/color-differences-algorithm/
* http://www.emanueleferonato.com/2009/09/08/color-difference-algorithm-part-2/
* @method rgb_to_xyz
* @method __rgb_to_xyz
* @param {[type]} red [description]
* @param {[type]} green [description]
* @param {[type]} blue [description]
* @return {[type]}
*/
rgb_to_xyz(r, g, b){
__rgb_to_xyz(r, g, b){
var _red = r/255,
_green = g/255,
_blue = b/255,
Expand Down Expand Up @@ -243,7 +243,7 @@ class Color {
return [x,y,z];
}

xyz_to_lab(x, y, z){
__xyz_to_lab(x, y, z){
var _x = x/95.047,
_y = y/100,
_z = z/108.883,
Expand Down Expand Up @@ -273,7 +273,7 @@ class Color {
return [l, a, b];
}

de_1994( lab1, lab2){
__de_1994( lab1, lab2){
var c1 = Math.sqrt(lab1[1]*lab1[1]+lab1[2]*lab1[2]),
c2 = Math.sqrt(lab2[1]*lab2[1]+lab2[2]*lab2[2]),
dc = c1-c2,
Expand Down Expand Up @@ -461,7 +461,7 @@ class Color {
}

//Reference: http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
initializeHSLV(){
__initializeHSLV(){
var r = this.red / 255,
g = this.green / 255,
b = this.blue /255;
Expand Down Expand Up @@ -500,5 +500,8 @@ class Color {
return '[' + [this.red,this.green,this.blue].join(', ') + ']';
}
};

module.exports = Color;
window.Color = Color;
if(typeof window !== 'undefined'){
window.Color = Color;
}

0 comments on commit 13d6fa3

Please sign in to comment.