9
Given 3 bytes or RGB as input, calculate the nearest CMYK values, and output them.
- create either a function with parameters and return value or a program that operates on stdin/stdout
- use the color profile of your choice, but provide a reference
- input may be either separate numeric values in range [0;255] or a 6 digit hex string
- output should be separate numeric values ranging either [0;1] or [0;100]
- standard code golf: no loopholes, shortest code wins
- extravagant ideas are welcome
sample data:
input output
108,174,106 [0.3793103448275862, 0.0, 0.3908045977011494, 0.3176470588235294]
0,0,0 0,0,0,1
170,255,238 33,0,7,0
0x0088ff 1,0.4667,0,0
[250,235,215] [0,6,14,1.96]
#123456 .7907,.3953,0,.6627
- Uncalibrated mapping is fine and probably the easiest
- No input validation required; floats are allowed (ranging from 0 to 255), but may also be rounded
- Output format should be either clearly commented or obvious; i.e.:
- CMYK in that order
- does not matter if percentage [0;100] or pure numbers [0;1]
- Testing should include the trivial example [0,0,0].
This site has the most digits of online tools that I could find. Does anyone know a tool that gives more than 4 digits?
Can the input be floats between 0 to 1? – Leaky Nun – 2016-06-30T07:19:55.087
4Could you give some example inputs/outputs? – Kevin Cruijssen – 2016-06-30T07:21:37.050
Also, welcome to PPCG. :) Usually we put challenges first in the Sandbox for Proposed Challenges for ± 72 hours. That way people can give feedback and your challenge will overall improve before you post it here.
– Kevin Cruijssen – 2016-06-30T07:23:22.2608@KevinCruijssen Just a side note, but I don't think that's how you use ±... – Leaky Nun – 2016-06-30T07:23:50.480
@LeakyNun In my understanding it means something like More or less / roughly in the English language see the adverb section here for some examples. I personally prefer it over ≈. Although according to Wikipedia it is mostly used in mathematics and such, in that case the usage is indeed wrong.
– Kevin Cruijssen – 2016-06-30T07:28:09.377@KevinCruijssen Oh, thanks for teaching. – Leaky Nun – 2016-06-30T07:29:15.880
1Welcome to the site! This is a decent challenge, but it's a little bit unclear. I'm voting to close as unclear what you're asking, but if you explain the algorithm to convert them and provide some test-cases, I will retract my vote. – James – 2016-06-30T15:18:46.000
2@KevinCruijssen In the adverb section, it says South African. It's not used that way in standard English. We use
~
. – mbomb007 – 2016-06-30T16:24:31.2171The close vote message is a bit misleading, because it stems from our Q&A roots, but it was indeed "put on hold as unclear what you're asking". There were a couple of requests for clarification in the comments which weren't addressed: specifically whether inputs and outputs as floats between 0 and 1 are allowed (or whether it has to be integers from 0 to 255), how the conversion actually works, and whether you could include some test cases. – Martin Ender – 2016-07-01T13:30:32.957
Is it required to always have a 0 in at least one of
CMY
? – l4m2 – 2018-03-21T17:58:00.980@l4m2 I don´t think so; but I guess that there are RGBs for which the result does not contain a
0
. – Titus – 2018-03-23T15:24:06.530