Color scheme trasformations - web

Given a set of colors, say colors on this webpage, and another palette of an equal number of colors, what would be a good way to map the former to the latter while:
preserving contrast between individual colors
preserving the relative intensity of the colors (not sure how important this would be)
Essentially, this webpage should be rendered in the new color palette while still legible.
What color space would be appropriate for this task?
Can you also point me to any related work?
Update: The mapping can surely be done manually but I intend to automate the mapping for any given set of colors and palette and so I'm looking for an algorithmic approach or rather an understanding of what properties need to be preserved in favor of legibility and beauty.

In general, I think it is better to transform colours into HSV, and then transform hue (and than back to original encoding). We use brightness (dark elements) and saturation (unselected buttons, etc) as semantic element, so it is better to preserve it.
In such way you maintain also the contrast.
But: normal HSV is not really a true physiological HSV: the most used formula are just set for gamut of RGB, and to give maximum range and being the parameter independent. On reality maximum V depend on H (if one want to compare V between different colours), and other effect.
And These and other visual effects (not in any HSV) will effect the visual result, so you may do it programmatically (e.g. JavaScript which read and override all colours, but this is a topic for other questions), but if you do a website professionally, you must still manually tweak some elements.
Note: last version of CSS, and many CSS preprocessors allow you to use HSV values, and apply programmatically saturation, light and hue changes.

Related

How can I even out colors so text is readable against them at any given hue and lightness?

Anyone who frequently does UI likely knows that for a given color hsl(H, 100%, 50%) (syntax is CSS) not all values of H will produce a color suitable to be placed under arbitrarily black or white text. The specific fact I'm noting is that certain colors (green) appear especially bright and other (blue) appear especially dark.
Well suppose I would like a user to be able to enter a color hue and have the color always appear with a consistent brightness so that one of either white or black text is guaranteed to always be readable on top of it. I would like all colors to also maintain the most vivid level of saturation they can given the constraint on brightness.
Here is a quick example of what I've tried so far. I start with a grid of squared like this rendered using a bunch of html div elements. Essentially these are hue values roughly from 0 to 360 along the horizontal axis and lightness values from roughly 0% to 100% along the vertical axis. All saturation value are set to 100%.
Using a JS library library called chroma.js, I now process all colors using the color.luminance function, whose definition seems to be to do what I'm looking for. I just passed the lightness of the hsl value in as the parameter to the function. I don't know for sure that this is the best way to accomplish my goal though since I'm not familiar with all the terminology at play here. Please note that my choice to use this library is by no means a constraint on how I want to go about this. It just represents my attempt at solving the problem.
The colors certainly now have a more consistent lightness, but the spectrum now seems particularly vivid around the orange to cyan area and particularly dull everywhere else. Also the colors seems to drop very quickly away from black at the top.
Hopefully this example helps a bit to express what I'm trying to accomplish here. Does any know what they best way to go about this is?
I found the solution! Check out HSLuv. It balances out all the hues in the spectrum so that at any given saturation and lightness, all hues will have the exact same perceived brightness to the human eye.
This solved my problem because now I can just set my text color to white (for example) and then as long as the text is readable against a certain HSLuv lightness it is guaranteed that it will be readable against any hue and saturation used in combination with that lightness. Magic.

SVG filter that highlights a path upwards (image sample provided)

I'm trying to highlight the countries of a svg map in a specific manner.
This is the result I want to achieve:
Before
After
Using the drop shadow technique provided here: https://stackoverflow.com/a/6094674, I was able to obtain a small relief effect, but I think this might not be the correct direction.
How should I approach this?
This gives you a shadow effect, which is fine. But if you want a true relief effect that works for all shapes (even fiddly ones with thin horizontal lines), then you'll need to composite multiple copies of the SourceGraphic, incrementally offset in y once for each pixel. Alternatively, you can use lighting primitives and some fancy compositing.

SVG plot from point-value pairs

I need to write some code (for a web.py webapp with a straight-HTML/JS client) that will generate a visual representation of a set of point-values. Each point has an X and Y coordinate, and the value is an integer. If I can use SVG to do this, then I can scale the image client-side with no extra code. Can I actually do this? I am concerned about a couple of things:
The points don't necessarily have any relation to each other. They aren't necessarily in a grid, nor can we say how many points are nearby, etc.
Gradients are primarily one-direction, and multiple gradients on the same shape seems to be a foreign concept.
Fills require an existing image, at which point, I'd be better off generating the entire image server-side anyway.
Objects always have a layering, even if it isn't specified, which can change how the image is rendered.
If it helps, consider a situation where we have a point surrounded by 5 others, where one of them is a bit closer than the others (exact distances and sizes can be adjusted). All six of the points have different colors (Red, Green, Blue, Cyan, Magenta, Yellow, with red in the center and Yellow being slightly closer), and the outer five points are arranged roughly in a pentagon. Note that this situation is not the only option, just a theoretically possible situation.
Can I do this with SVG, or should I render an image server-side?
EDIT: The main difficulty isn't in drawing the points, it is in filling the space between the points so that there is no whitespace, and color transitions aren't harsh/unpredictable if you know the data.
I don't entirely understand the different issues you are having with wanting to use svg. I am currently using the set up you are describing to render X-Y scatter plots and gaussian curves and found that it works great.
Regarding the last point about object layering, you have to be particularly careful when layering objects with less than 100% opacity which are different colors. The way the colors "add" depends on the order in which you add the objects to your svg drawing.
Thankfully you can use different filters to overlay the colors without blending them. Specifically I am using the FeComposite filter element. There is a good example of its usage here:
http://www.w3.org/TR/SVG/filters.html#feCompositeElement

Algorithm to adjust color brightness

I am doing a project trying to simulate Google Analytic Map Overlays. Take a look at this link to see what I mean (you need to scroll down to where it says "Here is a geographical country-based visitor volume overview courtesy of Google Analytics"). The Flash mapping tool I have supports Hex Color codes (e.g. color='FFFFCC'). If I am not mistaken this is basically RGB coding?
I am looking for an algorithm where I can computationally create the color codes for a select number of shades of green.
It seems I really want HSV type calculation and not a RGB one.
I think the easiest way to accomplish this is to select a set of colors and then map then to different segments of your data. I suppose you may need more flexibility.
If you want to calculate color. You can use HSV internally, and then covert it to RGB using this algorithm:
http://www.cs.rit.edu/~ncs/color/t_convert.html

Choosing colors that convert nicely to greyscale

If I'm designing af tool that must "screenshot" well for printed documentation, can I easily choose colors that look different even when printed in greyscale?
EDIT: I was hoping for some easy-to-use palette or tool, but the inputs given already is very insightfull for sure
Yes. Your best choice would be to choose colors that have a high level of relative contrast. Frankly, it might even be easiest for you to design your UI in greyscale in the first place. Basically, you're going to want to choose colors that are either lighter or darker than the colors around them by a decent amount.
You could calculate the luminance from the RGB values:
Y = 0.2126 R + 0.7152 G + 0.0722 B
And make sure your Y values for your selected colors are as distributed as evenly as possible.

Resources