All Projects → supersimple → chameleon

supersimple / chameleon

Licence: Apache-2.0 License
Chameleon Hex Package

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to chameleon

buffertools-php
Toolbox for working with binary and hex data. Similar to NodeJS Buffer.
Stars: ✭ 60 (+200%)
Mutual labels:  hex
HexPatternView
Create Beautiful hex design View.
Stars: ✭ 44 (+120%)
Mutual labels:  hex
colorsys.rs
Lib for modifying colors and converting to other spaces
Stars: ✭ 28 (+40%)
Mutual labels:  hex
colorsys
🎨 Minimalistic color converter for RGB, HSV, HSL, CMYK, HEX and CSS strings
Stars: ✭ 53 (+165%)
Mutual labels:  hex
hex-to-css-filter
Easy way to generate colors from HEX to CSS Filters
Stars: ✭ 20 (+0%)
Mutual labels:  hex
hex.vim
nifty functions for your Elixir Hex dependencies
Stars: ✭ 24 (+20%)
Mutual labels:  hex
ProceduralHexTerrainGenerator
Procedural Hex Terrain Generator
Stars: ✭ 20 (+0%)
Mutual labels:  hex
expublish
Automates semantic release versioning and best practices for elixir packages.
Stars: ✭ 17 (-15%)
Mutual labels:  hex
gleam compile
Tiny hex package to make the development experience of using gleam in elixir (and especially phoenix projects) better.
Stars: ✭ 29 (+45%)
Mutual labels:  hex
hex-color-regex
Regular expression for matching hex color values from string.
Stars: ✭ 29 (+45%)
Mutual labels:  hex
graphmath
An Elixir library for performing 2D and 3D mathematics.
Stars: ✭ 72 (+260%)
Mutual labels:  hex
agala
Full featured messaging bot framework.
Stars: ✭ 70 (+250%)
Mutual labels:  hex
utils.js
👷 🔧 zero dependencies vanilla JavaScript utils.
Stars: ✭ 14 (-30%)
Mutual labels:  hex
hexagonTab
Hexagon bookmarks accented with a chosen colour. Customise the layout, style, background and bookmarks with hexagonTab.
Stars: ✭ 65 (+225%)
Mutual labels:  hex
hexlightning
台灣人自己的黑名單機器人,更多的創意同時打造一個可以被信任的服務。
Stars: ✭ 34 (+70%)
Mutual labels:  hex
ColorMinePortable
ColorMinePortable
Stars: ✭ 37 (+85%)
Mutual labels:  hex
simple graphql client
SimpleGraphqlClient is a graphql client, focused on simplicity and ease of use.
Stars: ✭ 17 (-15%)
Mutual labels:  hex
elixir-queue
Queue data structure for Elixir-lang
Stars: ✭ 18 (-10%)
Mutual labels:  hex
elixir git hooks
🪝 Add git hooks to Elixir projects
Stars: ✭ 98 (+390%)
Mutual labels:  hex
colors-convert
🦚 A simple colors library
Stars: ✭ 15 (-25%)
Mutual labels:  hex

Chameleon

Chameleon

Build Status Module Version Hex Docs Total Download License Last Updated

Chameleon is a utility that converts colors from one model to another. It currently supports: Hex, RGB, CMYK, HSL, HSV, Pantone, and Keywords.

Use

Chameleon represents colors using Elixir structs. Create a color using one of the provided structs:

iex> Chameleon.RGB.new(255, 0, 0)
%Chameleon.RGB{b: 0, g: 0, r: 255}

Once you have a color, Chameleon can convert that color to another colorspace or format:

iex> Chameleon.RGB.new(255, 0, 0) |> Chameleon.convert(Chameleon.HSV)
%Chameleon.HSV{h: 0, s: 100, v: 100}

iex> Chameleon.RGB.new(255, 0, 0) |> Chameleon.convert(Chameleon.Hex)
%Chameleon.Hex{hex: "FF0000"}

Chameleon can also convert strings:

iex> Chameleon.convert("#ff0000", Chameleon.RGB)
%Chameleon.RGB{b: 0, g: 0, r: 255}

iex> Chameleon.convert("red", Chameleon.CMYK)
%Chameleon.CMYK{c: 0, k: 0, m: 100, y: 100}

If Chameleon doesn't know how to convert the color, you'll get an error:

iex> Chameleon.convert("#112233", Chameleon.Pantone)
{:error, "No pantone match could be found for that color value."}

Adding color types

Chameleon uses Elixir protocols internally to perform the conversions. This makes it possible to add support for new colorspaces and formats in your own code. To do this, first create a struct for your color:

defmodule MyApp.FancyColor do
  @enforce_keys [:c1, :c2, :c3]
  defstruct @enforce_keys

  def new(c1, c2, c3), do: %__MODULE__{c1: c1, c2: c2, c3: c3}
end

Next, implement the color protocol. Your color can implement as many or as few color space protocols as you need. For example:

defimpl Chameleon.Color.RGB do
  def from(your_color_struct), do: MyApp.FancyColor.to_rgb(your_color_struct)
end

When Chameleon doesn't find a direct conversion from one color to another, it will attempt to convert through RGB. By supporting RGB conversions, your color type will be convertible between many color types. Of course, color conversion is frequently a lossy operation and you may want to implement more conversion modules.

Caveat(s)

Pantone is designed to be used on printed work only. As such, it is disingenuous to say a pantone value can be translated to a hex value since hex values will look different depending on the device displaying them. However, if you have a pantone value and want to find a device-displayable analog, this library will work.

Installation

The package can be installed by adding chameleon to your list of dependencies in mix.exs:

def deps do
  [
    {:chameleon, "~> 2.2.0"}
  ]
end

Contribution

Contributions are welcomed. Please open a pull request or file an issue with your ideas. Some ideas would be:

  • Add a new color model for conversion
  • Add functionality to generate complementary colors
  • Handle errors for invalid input values

Copyright and License

Copyright (c) 2017 Todd Resudek

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].