Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mimosinnet/p6-color-rangetocolor
- Owner: mimosinnet
- License: artistic-2.0
- Created: 2019-09-07T14:01:19.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-07T01:23:42.000Z (almost 3 years ago)
- Last Synced: 2024-10-11T20:42:56.775Z (about 1 month ago)
- Topics: color-codes, linear-transformation, perl6
- Language: Raku
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 = ' 
';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)