History of Idiom 154 > diff from v8 to v9
Edit summary for version 9 by programming-idioms.org:
[Go] Fixed imports
[Go] Fixed imports
↷
Version 8
2016-10-30, 21:54:35
Version 9
2016-10-30, 21:55:06
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
r1, _ := strconv.ParseInt(c1[1:3], 16, 0)
r2, _ := strconv.ParseInt(c2[1:3], 16, 0)
r := (r1 + r2) / 2
g1, _ := strconv.ParseInt(c1[3:5], 16, 0)
g2, _ := strconv.ParseInt(c2[3:5], 16, 0)
g := (g1 + g2) / 2
b1, _ := strconv.ParseInt(c1[5:7], 16, 0)
b2, _ := strconv.ParseInt(c2[5:7], 16, 0)
b := (b1 + b2) / 2
c := fmt.Sprintf("#%02X%02X%02X", r, g, b)
Code
r1, _ := strconv.ParseInt(c1[1:3], 16, 0)
r2, _ := strconv.ParseInt(c2[1:3], 16, 0)
r := (r1 + r2) / 2
g1, _ := strconv.ParseInt(c1[3:5], 16, 0)
g2, _ := strconv.ParseInt(c2[3:5], 16, 0)
g := (g1 + g2) / 2
b1, _ := strconv.ParseInt(c1[5:7], 16, 0)
b2, _ := strconv.ParseInt(c2[5:7], 16, 0)
b := (b1 + b2) / 2
c := fmt.Sprintf("#%02X%02X%02X", r, g, b)
Comments bubble
Comments bubble