#How to get the closest color to the input rgb value?

19 messages · Page 1 of 1 (latest)

shrewd junco
#

How would I make a method to get the closest color (name) to an rgb value that is given to the method?

south vesselBOT
#

This post has been reserved for your question.

Hey @shrewd junco! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

arctic flint
#

define a bunch of color names with their respective rgb values, compare r, g and b for each name to your input, return the one with the least difference

twin birch
twin birch
#

I can't try it out rn because my IDE doesn't wanna open atm, but they said that it may not compile, so ¯_(ツ)_/¯

#

lemme quickly make it smth more reasonable

twin birch
#

there, that's significantly better (actually works and uses decent code style), and it also has more colours

arctic flint
#

also: what do we know about the == operator?

twin birch
#

mfw I'm used to kotlin and I forgor java's == operator is cringe

#

wait I did a formatting stupid in there

#

oh yeah also, here's a version with final (because good practice) and a private empty constructor (because good practice):