Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mimosinnet/p6-color-rangetocolor

Translate value in a range to hex color
https://github.com/mimosinnet/p6-color-rangetocolor

color-codes linear-transformation perl6

Last synced: 8 days ago
JSON representation

Translate value in a range to hex color

Awesome Lists containing this project

README

        

[![Build Status](https://img.shields.io/travis/dmlc/xgboost.svg?label=build&logo=travis&branch=master)](https://travis-ci.com/mimosinnet/P6-Color-RangeToColor)

# Name

Color::RangeToColor - Given a range from $lower-value to $upper-value and a $value in that range, translate the value to an Hex color code from red to green.

# Synopsis

The following example: (a) defines a range from $lower-value to $upper-value and a $value within that range; (b) transform the values to the range of default color codes; (c) creates HTML file to show color range and the value within the color range; (d) displays the file with elinks

use Color::RangeToColor :get_color_code;

my ($value, $lower-value, $upper-value) = ( 10, 1, 30 );
my ($line1, $line2);

my $color-start = ' ';
my $line-end = '&nbsp
';

for ($lower-value..$upper-value) -> $v {
my $color = get_color_code( value => $v.Rat, :$lower-value, :$upper-value );
$line1 ~= "$color-start $color $color-end";
}

for ($lower-value..$upper-value) -> $v {
my $color = get_color_code( value => $v.Rat, :$lower-value, :$upper-value );
if $v eq $value {
$line2 ~= "$color-start $color" ~ '">O';
next;
}
$line2 ~= "$color-start $color $color-end";
}

spurt '/tmp/borrem.html', "$line1 $line-end $line2 $line-end $line1 $line-end";

run ;

The folder _examples_ includes this code.

# Description

This module gives the hex color code (from red to green) of a given value considering the range of the scale. The color code in the red-green gradient is obtained using a linear transformation of the value. There are some examples in the examples' directory.

# Functions

The module defines these funtions:

get_color_code( Rat :$value, Numeric :$lower-value, Numeric :$upper-value --> Str )

Obtains the color code of a $value in a scale from $lower-value to $upper-value

gradient_generator( Str :$initial-color = '#FF0000', Str :$final-color = '#00FF00', Int :$gradient = 10)

Creates a gradient of $gradient items from $initial-color to $final-color with pre-defined default values.

# Installation

zef install -v https://github.com/mimosinnet/P6-Color-RangeToColor.git

# Support

Suggestions/patches are welcomed via github at

# License

Please see the [LICENSE](https://github.com/mimosinnet/P6-Color-RangeToColor/blob/master/LICENCE) file in the distribution.

© Joan Pujol (Mimosinnet)