{"id":20091270,"url":"https://github.com/supersimple/chameleon","last_synced_at":"2025-05-06T03:31:08.939Z","repository":{"id":26799886,"uuid":"108355424","full_name":"supersimple/chameleon","owner":"supersimple","description":"Chameleon Hex Package","archived":false,"fork":false,"pushed_at":"2022-01-25T15:49:25.000Z","size":853,"stargazers_count":26,"open_issues_count":2,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-16T09:35:53.446Z","etag":null,"topics":["elixir","hacktoberfest","hex"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/supersimple.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-26T03:12:03.000Z","updated_at":"2023-11-12T17:52:48.000Z","dependencies_parsed_at":"2022-07-27T08:52:23.802Z","dependency_job_id":null,"html_url":"https://github.com/supersimple/chameleon","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supersimple%2Fchameleon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supersimple%2Fchameleon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supersimple%2Fchameleon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supersimple%2Fchameleon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supersimple","download_url":"https://codeload.github.com/supersimple/chameleon/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224484213,"owners_count":17318926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","hacktoberfest","hex"],"created_at":"2024-11-13T16:29:24.139Z","updated_at":"2024-11-13T16:29:24.820Z","avatar_url":"https://github.com/supersimple.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chameleon\n\n![Chameleon](./assets/logo.png)\n\n[![Build Status](https://semaphoreci.com/api/v1/supersimple/chameleon/branches/master/badge.svg)](https://semaphoreci.com/supersimple/chameleon)\n[![Module Version](https://img.shields.io/hexpm/v/chameleon.svg)](https://hex.pm/packages/chameleon)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/chameleon/)\n[![Total Download](https://img.shields.io/hexpm/dt/chameleon.svg)](https://hex.pm/packages/chameleon)\n[![License](https://img.shields.io/hexpm/l/chameleon.svg)](https://github.com/supersimple/chameleon/blob/master/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/supersimple/chameleon.svg)](https://github.com/supersimple/chameleon/commits/master)\n\n\u003c!-- MDOC !--\u003e\n\nChameleon is a utility that converts colors from one model to another.\nIt currently supports: Hex, RGB, CMYK, HSL, HSV, Pantone, and Keywords.\n\n## Use\n\nChameleon represents colors using Elixir structs. Create a color using one\nof the provided structs:\n\n```elixir\niex\u003e Chameleon.RGB.new(255, 0, 0)\n%Chameleon.RGB{b: 0, g: 0, r: 255}\n```\n\nOnce you have a color, Chameleon can convert that color to another colorspace or\nformat:\n\n```elixir\niex\u003e Chameleon.RGB.new(255, 0, 0) |\u003e Chameleon.convert(Chameleon.HSV)\n%Chameleon.HSV{h: 0, s: 100, v: 100}\n\niex\u003e Chameleon.RGB.new(255, 0, 0) |\u003e Chameleon.convert(Chameleon.Hex)\n%Chameleon.Hex{hex: \"FF0000\"}\n```\n\nChameleon can also convert strings:\n\n```elixir\niex\u003e Chameleon.convert(\"#ff0000\", Chameleon.RGB)\n%Chameleon.RGB{b: 0, g: 0, r: 255}\n\niex\u003e Chameleon.convert(\"red\", Chameleon.CMYK)\n%Chameleon.CMYK{c: 0, k: 0, m: 100, y: 100}\n```\n\nIf Chameleon doesn't know how to convert the color, you'll get an error:\n\n```elixir\niex\u003e Chameleon.convert(\"#112233\", Chameleon.Pantone)\n{:error, \"No pantone match could be found for that color value.\"}\n```\n\n## Adding color types\n\nChameleon uses Elixir protocols internally to perform the conversions. This\nmakes it possible to add support for new colorspaces and formats in your own\ncode. To do this, first create a struct for your color:\n\n```elixir\ndefmodule MyApp.FancyColor do\n  @enforce_keys [:c1, :c2, :c3]\n  defstruct @enforce_keys\n\n  def new(c1, c2, c3), do: %__MODULE__{c1: c1, c2: c2, c3: c3}\nend\n```\n\nNext, implement the color protocol. Your color can implement as many or as few color space protocols as you need.\nFor example:\n\n```elixir\ndefimpl Chameleon.Color.RGB do\n  def from(your_color_struct), do: MyApp.FancyColor.to_rgb(your_color_struct)\nend\n```\n\nWhen 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.\n\n## Caveat(s)\n\nPantone is designed to be used on printed work only. As such, it is disingenuous to say a\npantone value can be translated to a hex value since hex values will look different depending\non the device displaying them. However, if you have a pantone value and want to find a\ndevice-displayable analog, this library will work.\n\n\u003c!-- MDOC !--\u003e\n\n## Installation\n\nThe package can be installed by adding `chameleon` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:chameleon, \"~\u003e 2.2.0\"}\n  ]\nend\n```\n\n## Contribution\n\nContributions are welcomed. Please open a pull request or file an issue with your ideas.\nSome ideas would be:\n\n- Add a new color model for conversion\n- Add functionality to generate complementary colors\n- Handle errors for invalid input values\n\n## Copyright and License\n\nCopyright (c) 2017 Todd Resudek\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License. You may obtain a copy\nof the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\nLicense for the specific language governing permissions and limitations\nunder the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupersimple%2Fchameleon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupersimple%2Fchameleon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupersimple%2Fchameleon/lists"}