Skip to content
Prev 360164 / 398506 Next

Mean of hexadecimal numbers

Hm...,

Should these two versions produce the same solution? Unfortunately and 
shame to confess, I don't know much about the colors in R:

myColors <- c("#FF7C00","#00BF40","#FFFF00")
Colors=rgb2hsv(col2rgb(myColors))
apply(Colors,1,mean)

         h         s         v
0.2122974 1.0000000 0.9163399

* * * * *

# Average the 1st two by taking the middle colour of a 3 colour palette
x <- colorRampPalette(c("#FF7C00","#00BF40"), space = "Lab")(3)[2]

# Average in the third by taking the 2nd of a 4 colour palette, so x
# gets twice the weight
colorRampPalette(c(x, "#FFFF00"), space = "Lab")(4)[2]

rgb2hsv(col2rgb(colorRampPalette(c(x, "#FFFF00"), space = "Lab")(4)[2]))

        [,1]
h 0.1597633
s 0.8407960
v 0.7882353

Atte T.


16.4.2016, 19.03, Duncan Murdoch kirjoitti: