-2

I'm trying to get the average color (rgba) of a single arbitrary character in Javascript. I'm aware this may produce different results on different setups; that's fine and expected behavior. How can this be done?

GameKyuubi
  • 681
  • 1
  • 10
  • 25

1 Answers1

-2

You might be thinking about how browsers interpret a string value of the bgColor property like a color by splitting the string into three hex values. Which is why element.bgColor = "chucknorris" changes the element's background colour to RGB(192, 0, 0).

See the below answer for more examples and a description of why it happens.

Why does HTML think “chucknorris” is a color?

stewartmcgown
  • 516
  • 4
  • 16
  • is there something worthy of a downvote in my answer? – stewartmcgown Nov 19 '19 at 21:08
  • I am not thinking of this. I mean literally how do I figure out the average color of an arbitrary character chosen at random, like "A" or "" – GameKyuubi Nov 19 '19 at 22:47
  • no need for a downvote though! You could have phrased your question a bit better. You'll need to choose a font to inspect in order to get the average colour. Characters are not stored as 'pixel-maps' inside JavaScript. – stewartmcgown Nov 19 '19 at 23:16
  • I'm not the one who downvoted you! Though I can see why you would think that, I would assume the same :) I can give you a second and then remove it later to prove it if you like lol – GameKyuubi Nov 19 '19 at 23:53
  • Could it be drawn and measured in a canvas? – GameKyuubi Nov 20 '19 at 00:23