├── tests └── basic.js ├── package.json ├── README.md └── ryb2rgb.js /tests/basic.js: -------------------------------------------------------------------------------- 1 | var ryb2rgb = require('../ryb2rgb'); 2 | console.log(ryb2rgb([0, 255, 0])); 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ryb2rgb", 3 | "description": "Convert colors in JavaScript from ryb to rgb", 4 | "author": "Dave Eddy (http://www.daveeddy.com)", 5 | "version": "0.0.0", 6 | "repository": { 7 | "url": "https://github.com/bahamas10/node-ryb2rgb.git", 8 | "type": "git" 9 | }, 10 | "main": "ryb2rgb.js", 11 | "scripts" : { 12 | "test": "for f in tests/*.js; do echo \"$f\"; node \"$f\" || exit 1; echo; done; echo 'Passed'" 13 | }, 14 | "dependencies": {}, 15 | "devDependencies": {}, 16 | "optionalDependencies": {}, 17 | "bin": {}, 18 | "engines": { 19 | "node": "*" 20 | }, 21 | "keywords": [ "color", "rgb", "ryb" ] 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ryb2rgb 2 | ======= 3 | 4 | Convert colors in JavaScript from ryb to rgb 5 | 6 | Example 7 | ------- 8 | 9 | ### ryb2rgb 10 | 11 | ``` js 12 | var ryb2rgb = require('ryb2rgb'); 13 | console.log(ryb2rgb([0, 255, 0])); 14 | ``` 15 | 16 | yields 17 | 18 | ``` js 19 | [255, 255, 0] 20 | ``` 21 | 22 | Usage 23 | ----- 24 | 25 | ``` js 26 | var ryb2rgb = require('ryb2rgb'); 27 | ``` 28 | 29 | or 30 | 31 | ``` html 32 | 33 | // defines ryb2rgb() 34 | ``` 35 | 36 | Installation 37 | ------------ 38 | 39 | npm install ryb2rgb 40 | 41 | Credits 42 | ------- 43 | 44 | Original code https://www.paintassistant.com/rybrgb.html 45 | 46 | Made generic for the web and Node.js 47 | 48 | License 49 | ------- 50 | 51 | MIT 52 | -------------------------------------------------------------------------------- /ryb2rgb.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Original Work 3 | * http://www.paintassistant.com/rybrgb.html 4 | * Modified by Dave Eddy 5 | */ 6 | 7 | ;(function() { 8 | function cubicInt(t, A, B){ 9 | var weight = t*t*(3-2*t); 10 | return A + weight*(B-A); 11 | } 12 | 13 | function getR(iR, iY, iB) { 14 | // red 15 | var x0 = cubicInt(iB, 1.0, 0.163); 16 | var x1 = cubicInt(iB, 1.0, 0.0); 17 | var x2 = cubicInt(iB, 1.0, 0.5); 18 | var x3 = cubicInt(iB, 1.0, 0.2); 19 | var y0 = cubicInt(iY, x0, x1); 20 | var y1 = cubicInt(iY, x2, x3); 21 | return Math.ceil (255 * cubicInt(iR, y0, y1)); 22 | } 23 | 24 | function getG(iR, iY, iB) { 25 | // green 26 | var x0 = cubicInt(iB, 1.0, 0.373); 27 | var x1 = cubicInt(iB, 1.0, 0.66); 28 | var x2 = cubicInt(iB, 0.0, 0.0); 29 | var x3 = cubicInt(iB, 0.5, 0.094); 30 | var y0 = cubicInt(iY, x0, x1); 31 | var y1 = cubicInt(iY, x2, x3); 32 | return Math.ceil (255 * cubicInt(iR, y0, y1)); 33 | } 34 | 35 | function getB(iR, iY, iB) { 36 | // blue 37 | var x0 = cubicInt(iB, 1.0, 0.6); 38 | var x1 = cubicInt(iB, 0.0, 0.2); 39 | var x2 = cubicInt(iB, 0.0, 0.5); 40 | var x3 = cubicInt(iB, 0.0, 0.0); 41 | var y0 = cubicInt(iY, x0, x1); 42 | var y1 = cubicInt(iY, x2, x3); 43 | return Math.ceil (255 * cubicInt(iR, y0, y1)); 44 | } 45 | 46 | function ryb2rgb(color){ 47 | var R = color[0] / 255; 48 | var Y = color[1] / 255; 49 | var B = color[2] / 255; 50 | var R1 = getR(R,Y,B) ; 51 | var G1 = getG(R,Y,B) ; 52 | var B1 = getB(R,Y,B) ; 53 | var ret = [ R1, G1, B1 ]; 54 | return ret; 55 | } 56 | 57 | // export 58 | if (typeof module !== 'undefined') { 59 | module.exports = ryb2rgb; 60 | } else { 61 | window.ryb2rgb = ryb2rgb; 62 | } 63 | })(); 64 | --------------------------------------------------------------------------------