Giter VIP home page Giter VIP logo

prizm's Introduction

Welcome!

Hackage Version Travis CI Status

prizm is a Haskell library for transforming colors. Specifically, providing functions for transforming between different color spaces (CIE and sRGB), interpolating colors and adjusting the tint, shade, hue, or lightness of a color.

The inspiration for this library came from a desire to blend two colors represented in the sRGB color space. My research about color blending and color space representation in the computer led me to the conclusion that the CIE L*Ch color space is the most effective for blending because it most accurately represents how the human eye sees hue and therefore preserves (and blends) hue the most accurately.

Quickstart

{-# LANGUAGE ScopedTypeVariables #-}

import           Data.Convertible
import           Data.Prizm.Color
import           Data.Prizm.Color.CIE as CIE

main :: IO ()
main = do
  -- Convert RGB colors to the CIE.LCH color space
  let green :: CIE.LCH = convert $ mkRGB 102 255 0
      pink  :: CIE.LCH = convert $ mkRGB 255 0 255

      -- Blend with a weight of 50%
      blended50 = pink <~> green

      -- Blend with a weight of 20%
      blended20 = interpolate 20 (pink,green)

  -- Print the CIE.LCH representation
  putStrLn $ show blended50

  -- Print the RGB representation of the blended color
  putStrLn . show $ ((convert blended20) :: RGB)

  -- Print the RGB color in a hexadecimal encoding
  putStrLn . show $ ((convert blended20) :: HexRGB)

      

Supported Algorithms

  • sRGB <-> CIE XYZ
  • CIE XYZ <-> CIE L*ab
  • CIE L*ab <-> CIE L*Ch

Supported Functions

  • Color interpolation
  • Tinting / Darkening
  • Lightness
  • Hue
  • Chroma/Saturation

Examples

Example blending with CIELCH converted back to RGB.

References

prizm's People

Contributors

ixmatus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

prizm's Issues

Foldable and Traversable instances

I had a use for this package today, but had to use standalone deriving to produce Foldable and Traversable instances for the CIELAB and RGB types in particular.

Since you've already gone and put in Applicative and Functor you may want to add those instances.

Also, there is a legal Monad for them. e.g.

CIELAB x y z >>= f = CIELAB x' y' z' where
  CIELAB x' _ _ = f x
  CIELAB _ y' _ = f y
  CIELAB _ _ z' = f z

And MonadFix, MonadZip instances are also law abiding if you want to go overboard. :)

Similar instances apply to the other colorspace types.

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.