Giter VIP home page Giter VIP logo

colorblind's Introduction

Colorblind

package version npm downloads

A zero-dependencies color blindness simulation library.

It is based on the color blindness simulation research and its Processing library by hx2A.

Demo

Install

$ npm install @bjornlu/colorblind

or use jsDelivr CDN for direct browser usage:

<script src="https://cdn.jsdelivr.net/npm/@bjornlu/[email protected]/dist/colorblind.min.js"></script>

The CDN version sets a global colorblind object which holds the functions below, e.g. colorblind.simulate(rgb, deficiency).

Usage

The library exports one main function:

simulate(rgb: RGB, deficiency: Deficiency): RGB

Simulates a color with applied color blindness deficiency.

rgb is an object with keys r, g and b with values between 0 and 255.

deficiency can be one of protanopia, deuteranopia, tritanopia or achromatopsia.

Example:

import { simulate } from '@bjornlu/colorblind'

simulate({ r: 120, g: 50, b: 30 }, 'protanopia')
// => { r: 61.93899039184746, g: 61.93898965670619, b: 29.683799575796723 }

There's also two functions for extra customization:

simulateDichromatic(rgb: RGB, simMatrix: Array<number>): RGB

simulateMonochromatic(rgb: RGB, simMatrix: Array<number>): RGB

simulateDichromatic accepts a simulation matrix represented as an array of 9 numbers, while simulateMonochromatic accepts array of 3 numbers.

Check out the research for how to calculate simulation matrices.

Additional Notes

  • The library makes no assumption of the color's gamma, hence gamma correction must be applied or removed manually where needed.
  • The algorithm does not use daltonization to calculate the result values.

Contributing

PRs are welcomed for any typos or documentation issues. Edits on the simulation algorithm must be backed up with research and is preferred to be discussed in an issue first.

Prior Research

The library was actually planned to be a rewrite of color-blind to remove the onecolor dependency and to add typings. In the process of understanding how the code works, I found that the original reference was outdated and has a newer version.

I also found out about the LMS version of the daltonize implementation, which happens to be the same technique used in the color blindness simulation research. The only difference was the simulation matrix used for the color deficiencies and its post color correction calculations.

I finally decided to follow the algorithm from the research since it's the only source I found that backs up how the values were calculated. So this means that this library does not use daltonization to calculate the colors.

Since I'm no expert in this field, I would highly appreciate validation on the implementation and whether daltonization would be the better choice.

License

MIT

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.