Hot answers tagged

21

The appropriate thing to do is to make the coloring optional, default to "off" and control it via a command-line flag. That way, people who don't like it or whose terminal doesn't support it aren't affected, people who like it can use it, and people who really, really like it can define an alias or shortcut to predefine the option. Everybody's happy.


15

I recommend using the HSV or HSL color spaces, not the RGB color space, because HSV and HSL are better structured for generating colors that look different to humans. You'll have more work in RGB (though conversions back and forth exist, should you need them). This is what HSV / HSL look like: When using the HSV or HSL color space you can assume (very ...


9

I would consider it appropriate to use color when: There are 'groups' of items and color groups will help visually group the items. There are set(s) of 'label:value' fields and you want the labels (or values) to stand out. There are items that would benefit from being shown in red/green, e.g. stop/go, good/bad, etc. Most of the information is background but ...


9

Text color is enough for that purpose. In most editors I've used, I can clearly see the comments, the keywords, the strings, etc. There is simply no need to visually complicate stuff with background color. Another element is that backgrounds are used, but for the purposes other than syntax highlighting. For example, in Visual Studio: Background colors are ...


9

A simple algorithm that gives reasonably good results: Add the squared difference of each color component (red, green, blue) between the color you are looking for and the color in your list of colors and choose the color where the sum of those squared differences is minimal. For a more accurate result, see the wikipedia article on color difference and ...


9

While you can do the transition in RGB space (using component-wise linear interpolation), this might cause unnaturally-looking transitions; most noticably, the brightness and saturation may bump between control points. If it this is acceptable, just do it this way. Mapping the values through some sort of gamma function before interpolating and then reverting ...


7

Assign each task a numeric rank and keep the list sorted. Rank Description -------------------------------------------------------------------------- 1 Find a way to make our task list readable by the new guy 3 Gain some rep by asking a question on Programmers 9 Convince the manager that 25-people team might need an issue tracker


7

Add an additional system that conveys the same information that your use of colour provides. This could be: Symbols. Size Location. Or anything else, really. However, the disturbing issue here is that you seem to think that these constitute a "completely different system" - that's not the case - your existing users can choose to ignore them entirely and ...


6

Not exactly. Additive and subtractive colour models are based on continuous physical phenomena, while XOR is a discrete operation lacking a real-world optical counterpart. Subtractive colour models are based on mixing of pigments, which absorb certain frequencies of light and reflect others—red paint, for example, absorbs non-red frequencies from white (...


5

Update: During the implementation of all the algorithms I realized that this would probably make for a pretty nice package. In case you're interested you can get it on npm. So good guy Christos Lytras put together an excellent answer on my corresponding question over at StackOverflow. I'm going to take the vital part of it and rephrase it here: The ...


5

Additive and subtractive mixing can be defined in terms of formulas that approximate certain real-world properties (mixing of coloured light, mixing of paint, application of successive coloured filters etc.) XOR doesn't really make sense in this context, for two reasons: XOR works with binary values, 1 and 0 (or true and false). It isn't normally defined ...


5

One other major factor to consider is that coloring, depending on platform, can add character escape sequences. For builds on those platforms, If the current/default mode is to output colour, it is customary to detect if the program output is a PIPE and stripping colour if that is the case. This is so that the color escape sequences do not throw off ...


4

You can't really do it smoothly using the RGB color space, but it's easier when done with HSV. See HSL and HSV Using HSV space you can transition from Green to Yellow to Red along a single float value for Hue while keeping the saturation/value constant.


3

Late to the party, but: Color Oracle is a program that runs on your computer and makes your desktop look like it would to a person with any of the different types of colorblindness. Run it with your IDE open, and tweak the colors you use for various things. Very few people are totally colorblind, in the sense that they can't perceive any color differences at ...


3

You can treat RGB colours as a 3-dimensional vector. The distance between any two points (colors) is given by the following formula: Your color is given as: #5D8AA8 This is made up of three hexadecimal values: [5D][8A][A8] Follow these steps: Strip the # off the string Break the remainder into 2x2x2 pieces and Use a Hex2Dec converter to convert your ...


3

In the 9-bin example, 49 is the number of pixels in the first 5 bins. 49 is the median number in the set of 9 partial sums, but we want the median pixel in the set, which is 43 (or 44), and it resides in the 4th bin. Inspection of the modified median cut algorithm in colorquant2.c of leptonica shows that the actual cut location for the 3d box does not ...


2

Yes your going to need to support your Alpha channel in software. If you have 3 bytes for RGB you will need an extra Alpha byte to represent the transparency of the pixel in your source images. The blending comes in to play when you composite all the layers on top of one another. To blend you will need a screen size buffer in memory that you copy each ...


2

Quantisation is simply a transformation from a large range of possible values into a smaller range of possible values. In the HSV colour space, H‌ue takes values from 0 to 360 degrees, while S‌aturation and V‌alue take values from 0 to 1. I believe (though I'm not positive) that for this process in Mpeg7 the quantisation is uniform, which ...


2

The bandwidth is the distance/size scale of the kernel function, i.e. what the size of the “window” is across which you calculate the mean. There is no bandwidth that works well for all purposes and all instances of the data. Instead, you will need to either manually select an appropriate bandwith for your algorithm; or use an algorithm that automatically ...


2

Recently I utilized ANSI escape codes to get the color on my print-outs, but this method is limited for me, because it seems to only work with string literals, and not printable objects like list and dictionaries. The comments you gave indicated you simply got the syntax wrong. Try a function like this one: def blueprint(x): print('\033[34m' + str(x) + ...


2

You can readily apply the k-means algorithm to the RGB image data set. An image data set is in no way special, except that each data vector is three dimensional (R, G and B) and the values are bounded integers in the [0, 255] range. The standard k-means algorithm just needs to compute the distance between two as well as the mean of several data points. For ...


2

Instead of using a table to store the mapping, consider building a "curve" for it: a mathematical function to calculate the conversions. There are infinitely many ways to do this, but you can probably pick something simple like Béziers or polynomials. The curve will have some unknown parameters that you'll need to fiddle with in order to produce the right ...


1

Replacing a single color Generate a opacity mask (alpha channel) by computing the color distance between each pixel to the color-to-be-replaced. A zero distance (i.e. matching exactly the color to be replaced) corresponds to zero opacity (i.e. fully transparent, such that its original pixel color will be ignored) Opacity increases as the color distance ...


1

Your issue is that you're trying to map 24-bit colors to 8-bit outputs (or inputs for your LED), where your color ranges are a lot more reduced - and probably provide only a segment of the actual code to your LED. To understand this better, please read this Wikipedia article and pay particular attention to "web-safe colors", because ultimately this is what ...


1

This is a basic linear algebra problem. Let b = [ b1, b2, b3 ] be your mixed colour, x = [ x1, x2, ... xn ] be your solution, I = [ 1, 1, 1 ] (or whatever your white value is), and A = [ c1, c2, ..., cn ] be your colour set where each ci is a column vector in the matrix A. You must solve for x in the the equation I - Ax = b or Ax = I - b. You can check out ...


1

For the case where you don't know in advance how many distinct colors you will be needing another interesting algorithm is the golden ratio algorithm. Simply start at your favorite color and then go around the color wheel in steps of the golden angle (137.5°). With this angle you'll ensure that after every convolution around the color wheel your new colors ...


1

It's a no brainer, but really, do not rely a lot on color, on your code. And in general, do not rely in a mandatory editing system. (an IDE may be tolerable, but only given enough tradeoffs in term of productivity) Establishing a proper indenting convention is already quite hard, time consuming, a matter of feuds, and a source of discontent. Mandating ...


1

The very simplest thing would probably be to take a few hours and add a new symbol to go with each color (lik3 # with red; @@ for blue, etc) and put it in a comment line near the colored text. This way the color-blind person can just search for all # and find all red lines. He can't scan a page and have color jump out at him, but there's little textual ...


Only top voted, non community-wiki answers of a minimum length are eligible