Programming Puzzles & Code Golf: What color is this?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Programming Puzzles & Code Golf: What color is this?

MartinW
Hi,
i entered a Pharo version to this Code Golf contest: http://codegolf.stackexchange.com/a/32535/26615

"Given three number values - being the Red, Green, and Blue elements of a colour (eight bits per channel, 0 to 255) - your program must output the name of the given colour.“

My answer is:

| color colorNames nearestColorName |
color := Color r: 255 g: 0 b: 0.
colorNames := Color registeredColorNames.
nearestColorName := colorNames detectMin: [ :each | (Color named: each) diff: color].

But, the results are of mixed quality. All darker colors are named as gray, dark gray or very dark gray.

Is it my fault, the fault of Color’s diff: method or the fault of the available color names?

M.
Reply | Threaded
Open this post in threaded view
|

Re: Programming Puzzles & Code Golf: What color is this?

Nicolai Hess
2014-06-25 18:53 GMT+02:00 MartinW <[hidden email]>:
Hi,
i entered a Pharo version to this Code Golf contest:
http://codegolf.stackexchange.com/a/32535/26615

"Given three number values - being the Red, Green, and Blue elements of a
colour (eight bits per channel, 0 to 255) - your program must output the
name of the given colour.“

My answer is:

| color colorNames nearestColorName |
color := Color r: 255 g: 0 b: 0.
colorNames := Color registeredColorNames.
nearestColorName := colorNames detectMin: [ :each | (Color named: each)
diff: color].

But, the results are of mixed quality. All darker colors are named as gray,
dark gray or very dark gray.

Is it my fault, the fault of Color’s diff: method or the fault of the
available color names?

M.



--
View this message in context: http://forum.world.st/Programming-Puzzles-Code-Golf-What-color-is-this-tp4764770.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




Color class>>r: r g: g b: b
    "Return a color with the given r, g, and b components in the range [0.0..1.0]."

:-) Range is [0..1] not [0..255]

Reply | Threaded
Open this post in threaded view
|

Re: Programming Puzzles & Code Golf: What color is this?

MartinW
Nicolai Hess wrote
Color class>>r: r g: g b: b
    "Return a color with the given r, g, and b components in the range
[0.0..1.0]."

:-) Range is [0..1] not [0..255]
Oh, thank you, how embarassing. I correct it to:
color := Color r: 255 g: 0 b: 0 range: 255.

Still the problem remains the same. I tested the code with Color random and only for the post changed to Color r:g:b:.
Reply | Threaded
Open this post in threaded view
|

Re: Programming Puzzles & Code Golf: What color is this?

MartinW
MartinW wrote
Nicolai Hess wrote
Color class>>r: r g: g b: b
    "Return a color with the given r, g, and b components in the range
[0.0..1.0]."

:-) Range is [0..1] not [0..255]
Oh, thank you, how embarassing. I correct it to:
color := Color r: 255 g: 0 b: 0 range: 255.

Still the problem remains the same. I tested the code with Color random and only for the post changed to Color r:g:b:.
And some colors are found to be next to „transparent“ for example
color := Color r: 100 g: 0 b: 0 range: 255.
which clearly has alpha 1.0.
Reply | Threaded
Open this post in threaded view
|

Re: Programming Puzzles & Code Golf: What color is this?

MartinW
MartinW wrote
MartinW wrote
Nicolai Hess wrote
Color class>>r: r g: g b: b
    "Return a color with the given r, g, and b components in the range
[0.0..1.0]."

:-) Range is [0..1] not [0..255]
Oh, thank you, how embarassing. I correct it to:
color := Color r: 255 g: 0 b: 0 range: 255.

Still the problem remains the same. I tested the code with Color random and only for the post changed to Color r:g:b:.
And some colors are found to be next to „transparent“ for example
color := Color r: 100 g: 0 b: 0 range: 255.
which clearly has alpha 1.0.
Ok, i have to get rid of transparent :)
colorNames := Color registeredColorNames copyWithout: #transparent.