History of Idiom 154 > diff from v4 to v5
Edit summary for version 5 by programming-idioms.org:
New Java implementation by user [programming-idioms.org]
New Java implementation by user [programming-idioms.org]
↷
Version 4
2016-10-30, 21:20:37
Version 5
2016-10-30, 21:37:24
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 # .
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 # .
Extra Keywords
hexa hexadecimal css avg meanExtra Keywords
hexa hexadecimal css avg meanCode
String r1 = c1.substring(1,3);
String g1 = c1.substring(3,5);
String b1 = c1.substring(5,7);
String r2 = c2.substring(1,3);
String g2 = c2.substring(3,5);
String b2 = c2.substring(5,7);
String r = String.format("%02X", (Integer.parseInt(r1, 16) + Integer.parseInt(r2, 16))/2 );
String g = String.format("%02X", (Integer.parseInt(g1, 16) + Integer.parseInt(g2, 16))/2 );
String b = String.format("%02X", (Integer.parseInt(b1, 16) + Integer.parseInt(b2, 16))/2 );
String c = "#" + r + g