"Pleasant" means a high enough contrast for reading, but also might include colors that don't clash with one another.
Do your best. No harsh judgement. π
Any languages/approaches welcome.
"Pleasant" means a high enough contrast for reading, but also might include colors that don't clash with one another.
Do your best. No harsh judgement. π
Any languages/approaches welcome.
For further actions, you may consider blocking this person and/or reporting abuse
S3CloudHub -
Anas Hussain -
codingKrills -
Prasanna Venketesh -
Top comments (20)
Basically rotate the HSL components (
(value+0.5)%1
). The complicated part is converting a rgb() to hsl().Note that only changing the luminosity part (
hsl[2]
) is vital. Disabling the other parts (hue and saturation) also creates pleasant results, just less colorful.So this returns black or white, but what if the ideal solution returned, perhaps a very dark version of the background color. Like, dark blue on light blue might be more pleasant than black on light blue etc.
Would this work then? get color, convert color to HSL, return L - 100 % 100
I decided to use machine learning...
14 hours later π¬, here's a work in progress for a script that randomly generates a background color, then generates the foreground color from a neural net that learns from your selections.
Edit:
Converted to codepen by @rhymes :
The gist is still here but I'll take the embed out since gist embeds load slowly and take up a lot of screen real estate.
Edit 2: I cleaned up the code in both places so hopefully it's more readable now. The bulk of the neural stuff happens in regenerateColors() and trainOnCurrentColors().
I put it in a Codepen for you:
fork it to your account :-)
Amazing
This would be great if my color choices had any logic to them πππ
No, seriously this is amazing β€οΈ
"Pleasure" is a little bit subjective. Basically I based with the complementary color to be sure that the text is possible to read:
React example with random color of background color + complementary for text:
I mainly was having fun with research for this. Color theory, the parts of RGB color, playing with jQuery...
Known bug: the contrast for Cyan sucks.
Known feature enhancement: provide better suggestions than just white or black π
I implemented this in python:
I wasn't sure what we should do with "pleasant", so I just created little functions to adjust the color
The logic is that if there is an RGB close to FF, then, max that out. If there is one close to 00, then zero that out. If it is in between, lighten it. If the background is black or white, return the opposite.
for example
splitColor('ff00aa')
returns"ff0078"
splitColor('ffffff')
returns"000000"
There are some edge cases that I did not address - every one that is a combination of extremes. I did not create this in codepen, and now I am kicking myself for just whipping it up in the javascript console while I was debugging something else!
I once attempted this problem for setting up a color scheme for a website. Turns out "pleasant" depends on the size of inner/outer elements. The problem is called "color relativity". People don't physically identify colors based on RGB wavelengths, instead we look at contrast with surrounding context. If there is very little contrast, we can perceive very slight differences in absolute color value. If there is very high contrast, we can only perceive significant differences. Also context can "shift" colors to look the same. For example:
High contrast: At night, with house or street lights. Most people become nearly color blind.
Low contrast: Snow blind. People can visually identify physical shapes of hills, roads, trees etc. despite everything being white.
I made a black and white version. I'll try to work on it a bit more later
(Click on the background to change the color)
examples.achickandaclick.org/color...
Caveat: this was already done :P and I hope that the rgb(0,0,0) text being only one color (non-color: black is really no color) is considered pleasant :) That being said; the input of a hex generates a color in the box with black text showing the rgb of the hex color. I used js, jquery, html and css :) Namaste!
ps there are two functions