gerph.org


ColourFade module

I use a simple module to provide a fade between colours. Having been used in a few projects, it has been generalised so that it can be used by others. I decided to make it freely available. If it iss no use to anyone then it hurts no one; if it helps others then that's great.
First release of the module
Version: 0.08 (2013-05-16)
Features: Example use:
my $fade = new ColourFade(
        { 'colour' => 0xffff44, 'value' => 0    },  # Yellow
        { 'colour' => 0x44cc44, 'value' => 10   },  # Green
        { 'colour' => 0xccccff, 'value' => 20   },  # Blue
        { 'colour' => 0x40cccc, 'value' => 30   },  # Light cyan
        { 'colour' => 0xA15999, 'value' => 40   },  # Light purple
        { 'colour' => 0xcc4444, 'value' => 90   },  # Red
        { 'colour' => 0xffcccc, 'value' => 200  },  # Pink
        { 'colour' => 0xffffff, 'value' => 400  },  # White
    );

for my $val (0..20)
{
    printf "Colour %d: %06x\n", $val, $fade->colour($val);
}
     
Example fades
The following example fades are taken from the built in test code.

Integer table

-15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

Fractional table

-0.15 -0.14 -0.13 -0.12 -0.11 -0.10 -0.09 -0.08 -0.07 -0.06 -0.05 -0.04 -0.03 -0.02 -0.01
0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16
0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.30 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38

Logarithmic table

0.0001 0.0002 0.0003 0.0006 0.0010 0.0018 0.0032 0.0056 0.0100 0.0178 0.0316 0.0562 0.1000
0.1778 0.3162 0.5623 1.00 1.78 3.16 5.62 10
17 31 56 100 177 316 562 1000 1778 3162 5623

This page is maintained by Justin Fletcher (gerph@gerph.org).
This site is copyright Justin Fletcher. The accuracy of anything on this site is entirely limited by his belief system and memory at the time of publication - neither of which should be relied on. The opinions are entirely his, except where he's changed his mind. Quotations are copyright their respective authors and whereever possible attributions have been included.