Logo

Programming-Idioms

History of Idiom 154 > diff from v29 to v30

Edit summary for version 30 by daxim:
New Perl implementation by user [daxim]

Version 29

2018-08-03, 21:00:46

Version 30

2019-09-27, 21:38:49

Idiom #154 Halfway between two hex color codes

Find color c, the average between colors c1, c2.

c, c1, c2 are strings of hex color codes: 7 chars, beginning with a number sign # .
Assume linear computations, ignore gamma corrections.

Illustration

Idiom #154 Halfway between two hex color codes

Find color c, the average between colors c1, c2.

c, c1, c2 are strings of hex color codes: 7 chars, beginning with a number sign # .
Assume linear computations, ignore gamma corrections.

Illustration
Extra Keywords
hexa hexadecimal css avg mean radix base
Extra Keywords
hexa hexadecimal css avg mean radix base
Imports
use List::SomeUtils qw(pairwise);
Code
my @c1 = unpack 'xA2A2A2', $c1;
my @c2 = unpack 'xA2A2A2', $c2;
my $c = sprintf '#%02X%02X%02X', pairwise { (hex($a) + hex($b)) / 2 } @c1, @c2
Doc URL
https://p3rl.org/List::SomeUtils#pairwise