Hot answers tagged

22

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

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 ...


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

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 ...


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 ...


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.


4

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

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

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

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 ...


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) + ...


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

I have experimented a bit and found out that even with HSL/HSV it's not quite easy to get a decent algorithm for nice, undisturbing, calming (all quite subjective, but...), yet contrasty colors. Some parts of the specter are visually similar - esp. the green-blue section. So I had to add some lightness variation. Here is what I ended up with: $.plot($('#...


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