dcrck

dcrck

Ultraviolet - chroma.js-like color manipulation library

Ultraviolet is an Elixir color manipulation library designed to work like chroma-js. It does not have full parity with chroma-js, but it includes most of the common operations and features.

Getting started

Here are a few things it can do:

  • read colors from a wide range of inputs
  • analyze and manipulate colors
  • convert colors into a wide range of formats
  • linear, bezier, and custom interpolation in different color spaces

Here’s an example of a simple read / manipulate / output chain

{:ok, color} = Ultraviolet.new("pink")

color
|> Ultraviolet.Color.darken!()
|> Ultraviolet.Color.saturate!(2)
|> Ultraviolet.Color.hex()
#=> "#ff6d93"

Aside from that, ultraviolet can help you generate nice colors using various methods. These colors can be used, for example, as a color palette for maps or data visualization.

{:ok, scale} = Ultraviolet.scale(["#fafa6e", "#2a4858"], space: :lch)
colors = Ultraviolet.Scale.take(scale, 6)

This library has a lot more to offer, though; the documentation contains more examples of how to use it.


Background

I’m working on a project that requires creating nice-looking gradients and other cover images. I explored a number of related tools online, such as Cool Backgrounds and Trianglify. I noticed that pretty much all of them use chroma-js for color manipulation, so I took a look at the library. I was pleasantly surprised: the API is functional and well-documented with plenty of examples and test cases. I also noticed that there wasn’t a fully-featured color manipulation library in Elixir yet, so I felt the urge to try porting some of chroma.js over to Elixir to use with the project (a Phoenix website).

That was last Thursday. Since then, I’ve brought over most of the core chroma-js functionality, but made some API adjustments so it better fits the “Elixir style”. It’s not quite “finished” yet, and I probably need to do more testing and fine-tuning, but I feel like it’s robust and stable enough that I can release it as a library. If you need to manipulate colors for your app, please give ultraviolet a try and let me know what you think!

Acknowledgements

Huge thanks to the chroma.js creator for making such a wonderful and well-documented library. If you haven’t seen the chroma-js documentation, I’d recommend giving it a read.

Where Next?

Popular in Libraries Top

pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New
deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
sabiwara
Dune is a sandbox for Elixir and aims to safely evaluate user-provided code. You can try it out using this basic Elixir playground made ...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New
archan937
It is a well-know topic within the Elixir community: “To mock or not to mock? :)” Every alchemist probably has his / her own opinion con...
New
aditya7iyengar
Rummage.Ecto and Rummage.Phoenix provide ways to perform Searching, Sorting and Pagination over Ecto queries and Phoenix collections. Fo...
New
Eiji
ExApi is a library that I’m developing now and hope release soon This library will allow to: list all apis list all api implementation...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Sub Categories:

We're in Beta

About us Mission Statement