History of Idiom 154 > diff from v2 to v3
Edit summary for version 3 by programming-idioms.org:
[Go] Better wording concision -> conciseness
[Go] Better wording concision -> conciseness
↷
Version 2
2016-10-30, 01:22:55
Version 3
2016-10-30, 21:13:15
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 css avg meanExtra Keywords
hexa 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