Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fponticelli/thx.color
General purpose color library for Haxe
https://github.com/fponticelli/thx.color
Last synced: about 12 hours ago
JSON representation
General purpose color library for Haxe
- Host: GitHub
- URL: https://github.com/fponticelli/thx.color
- Owner: fponticelli
- License: mit
- Created: 2012-12-31T03:27:58.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-09-22T17:43:50.000Z (almost 7 years ago)
- Last Synced: 2024-03-11T10:34:33.985Z (4 months ago)
- Language: Haxe
- Homepage: http://thx-lib.org
- Size: 1.38 MB
- Stars: 38
- Watchers: 7
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-haxe-generative - thx.color
README
# thx.color
[![Build Status](https://travis-ci.org/fponticelli/thx.color.svg)](https://travis-ci.org/fponticelli/thx.color)
Color library for Haxe. Supports the following color spaces:
* Lab (AKA Lab)
* LCh (AKA HCL)
* Luv (or LUV)
* Cmy
* Cmyk
* CubeHelix
* Grey
* Hsl(a)
* Hsv(a) (AKA HSB)
* HunterLab
* Rgb(a)
* Rgbx(a) (an high resolution version of RGB)
* Temperature
* Xyz
* Yuv
* YxyWith conversion from/to any color space (notice that you can lose some information in the conversion).
## intro
API uses abstracts to make it easy to create colors from strings and numbers.
```haxe
var rgb : Rgb = "#cf8700";
trace(rgb.green);
```Some examples from [Demo](https://github.com/fponticelli/thx.color/raw/master/demo/Demo.hx).
### Hsl Rainbow
```haxe
var left : Hsl = 'hsl(0,100%,0%)',
right : Hsl = 'hsl(359.99,100%,0%)';
return function(x : Float, y : Float) : Rgb {
return left.interpolate(right, x).lighter(y);
};
```![Alt text](https://github.com/fponticelli/thx.color/raw/master/images/rainbowhsl.png?raw=true "Hsl Rainbow")
### Hsv Interpolation
```haxe
var left : Hsv = 'hsv(160deg,100%,63%)',
right : Hsv = 'hsv(345deg,88%,77%)';
return function(t : Float) : Rgb
return (left : Hsv).interpolate(right, t);
```![Alt text](https://github.com/fponticelli/thx.color/raw/master/images/interpolatehsv.png?raw=true "Hsv Interpolation")
### Lighter Rgb
```haxe
var left : Rgb = '#0000ff';
return left.lighter;
```![Alt text](https://github.com/fponticelli/thx.color/raw/master/images/lighterrgb.png?raw=true "Lighter Rgb")
### Named Colors Table
```haxe
var columns = 5,
colors = Color.names.keys().toArray().filter(function(n) return n.indexOf(' ') < 0),
cellw = w / columns,
cellh = h / Math.ceil(colors.length / columns);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = '${Math.round(cellh*0.4)}px Verdana, sans-serif';
colors.mapi(function(name, i) {
var col = i % columns,
row = Math.floor(i / columns),
color = Color.names.get(name);ctx.fillStyle = color.toString();
ctx.fillRect(col * cellw, row * cellh, cellw, cellh);ctx.fillStyle = color.toRgbx()
.toPerceivedGrey()
.contrast()
.toRgb().toString();
ctx.fillText(
name,
Math.round(col * cellw + cellw / 2) + 0.5,
Math.round(row * cellh + cellh / 2) + 0.5,
cellw);
});
```To run [Demo](/demo/Demo.hx), you need `nodejs` and the Canvas library (`npm install canvas`);
*Note:* API might still change before version 1.
## install
From the command line just type:
```bash
haxelib install thx.color
```To use the `dev` version do:
```bash
haxelib git thx.color https://github.com/fponticelli/thx.color.git
```