EzDevInfo.com

colors interview questions

Top colors frequently asked interview questions

RGB to Hex and Hex to RGB

Well, I just need to convert RGB values to HEX and the other way around.

I've tried this, but it didn't work.

function RGB2HTML(red, green, blue)
{
    var decColor = red + 256 * green + 65536 * blue;
    return decColor.toString(16);
}

Example :

#0080C0 to (0,128,192)

Source: (StackOverflow)

Colorized Ruby output [closed]

Is there a proper plugin or a class to perform background and foreground text colorization within a common output console?

I remember, when programming Pascal we all used to play with textcolor(...) procedures to make our small educational programs look more pretty and presentational.

Is there anything similar in Ruby?


Source: (StackOverflow)

Advertisements

Formula to determine brightness of RGB color

I'm looking for some kind of formula or algorithm to determine the brightness of a color given the RGB values. I know it can't be as simple as adding the RGB values together and having higher sums be brighter, but I'm kind of at a loss as to where to start.


Source: (StackOverflow)

Colorize diff on the command line [closed]

When I have a diff, how can I colorize it so that it looks good? I want it for the command line, so please no GUI solutions.


Source: (StackOverflow)

How to get Color from Hexadecimal color code using .NET?

How can I get a Color from a Hexadecimal color code or say, Hash code (e.g. #FFDFD991)?

I am reading a file and getting Hexadecimal color code, I need to create the corresponding System.Windows.Media.Color instance for the Hexadecimal color code. Is there any inbuilt method in framework to do this?


Source: (StackOverflow)

Hex transparency in colors

I'm working on implementing a wigdget transparency option for my app widget although I'm having some trouble getting the hex color values right. Being completely new to hex color transparency I searched around a bit although I couldn't find a specific answer to my question.

I want to set transparency by hex color so let's say my hex color id "#33b5e5" and I want it to be 50% transparent. Then I'll use "#8033b5e5" because 80 is 50%.

I found a useful chart here: http://www.dtp-aus.com/hexadeci.htm . With this data I managed to come up with this:

0% = #00
10% = #16
20% = #32
30% = #48
40% = #64
50% = #80
60% = #96
70% = #112
80% = #128
90% = #144

Now the issues start appearing when I get higher than 100 in hex. Hex color codes can only be 8 symbols long right? For example #11233b5e5 (80%) crashes.

What can I do to enable me to use the higher numbers aswell?


Source: (StackOverflow)

How to color the Git console in Ubuntu?

I recently saw that the Git console in Windows is colored, e.g. Green for additions, red for deletions, etc. How do I color my Ubuntu Git console like that?

To install it, I used the command: $ apt-get install git-core


Source: (StackOverflow)

How to set the text color of TextView in code?

In XML, we can set a text color by the textColor attribute, like android:textColor="#FF0000". But how do I change it by coding?

I tried something like:

holder.text.setTextColor(R.color.Red);

Where holder is just a class and text is of type TextView. Red is an RGB value (#FF0000) set in strings.

But it shows a different color rather than red. What kind of parameter can we pass in setTextColor()? In documentation, it says int, but is it a resource reference value or anything else?


Source: (StackOverflow)

jQuery animate backgroundColor

I am trying to animate a change in backgroundColor using jQuery on mouseover.

I have checked some example and I seem to have it right, it works with other properties like fontSize, but with backgroundColor I get and "Invalid Property" js error. The element I am working with is a div.

$(".usercontent").mouseover(function() {
    $(this).animate({ backgroundColor: "olive" }, "slow");
});

Any ideas?


Source: (StackOverflow)

OS X Terminal Colors [closed]

I'm new to OS X, having just gotten a Mac after working with Ubuntu Linux for some time. Among the many things I'm trying to figure out is the absence of colors in my terminal window - like the ones that are shown (on Linux) when you run 'ls -la' or 'git status'... I just can't figure out how to activate them in the actual shell.


Source: (StackOverflow)

How to set Bullet colors in UL/LI html lists via CSS without using any images or span tags [duplicate]

This question already has an answer here:

Imagine a simple unsorted list, with some <li> items nested inside <ul> tags. Now, I have defined the bullets to be square shaped via list-style:square; however, if I set the color of the <li> items, color: #F00; then everything becomes red!

While I ONLY want to set the color of these square bullets. Is there an elegant wat to define only the color of the bullets in CSS without using ANY sprite images nor any cumbersome span tags?

HTML

<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<ul>

CSS

li{
   list-style:square;
}

Source: (StackOverflow)

Convert RGB to RGBA over white

I have a hex color, e.g. #F4F8FB (or rgb(244, 248, 251)) that I want converted into an as-transparent-as-possible rgba color (when displayed over white). Make sense? I'm looking for an algorithm, or at least idea of an algorithm for how to do so.

For Example:

rgb( 128, 128, 255 ) --> rgba(   0,   0, 255,  .5 )
rgb( 152, 177, 202 ) --> rgba(  50, 100, 150,  .5 ) // can be better(lower alpha)

Ideas?


FYI solution based on Guffa's answer:

function RGBtoRGBA(r, g, b){
    if((g==void 0) && (typeof r == 'string')){
        r = r.replace(/^\s*#|\s*$/g, '');
        if(r.length == 3){
            r = r.replace(/(.)/g, '$1$1');
        }
        g = parseInt(r.substr(2, 2), 16);
        b = parseInt(r.substr(4, 2), 16);
        r = parseInt(r.substr(0, 2), 16);
    }

    var min, a = ( 255 - (min = Math.min(r, g, b)) ) / 255;

    return {
        r    : r = 0|( r - min ) / a,
        g    : g = 0|( g - min ) / a,
        b    : b = 0|( b - min ) / a,
        a    : a = (0|1000*a)/1000,
        rgba : 'rgba(' + r + ', ' + g + ', ' + b + ', ' + a + ')'
    };
}

RGBtoRGBA(204, 153, 102) == RGBtoRGBA('#CC9966') == RGBtoRGBA('C96') == 
    {
       r    : 170,
       g    : 85 ,
       b    : 0  ,
       a    : 0.6,
       rgba : 'rgba(170, 85, 0, 0.6)' 
    }

Source: (StackOverflow)

SVG fill color transparency / alpha?

Is it possible to set a transparency or alpha level on SVG fill colours?

I've tried adding two values to the fill tag (changing it from fill="#044B94" to fill="#044B9466"), but this doesn't work.


Source: (StackOverflow)

Get color-int from color resource

Is there a way to get a color-int from a color resource? I am trying to get the individual red, blue and green components of a color defined in the resource (R.color.myColor) so that I can set the values of three seekbars to a specific level.


For more information on another use-case that may help surface this question in search results, I wanted to apply alpha to a color defined in my resources. Using @sat's correct answer:

int alpha = ... // 0-255, calculated based on some business logic
int actionBarBackground = getResources().getColor(R.color.actionBarBackground);
int actionBarBackgroundWithAlpha = Color.argb(alpha,
        Color.red(actionbarBackground),
        Color.green(actionbarBackground),
        Color.blue(actionbarBackground));

Source: (StackOverflow)

How can I color Python logging output?

Some time ago, I saw a Mono application with colored output, presumably because of its log system (because all the messages were standardized).

Now, Python has the logging module, which lets you specify a lot of options to customize output. So, I'm imagining something similar would be possible with Python, but I can’t find out how to do this anywhere.

Is there any way to make the Python logging module output in color?

What I want (for instance) errors in red, debug messages in blue or yellow, and so on.

Of course this would probably require a compatible terminal (most modern terminals are); but I could fallback to the original logging output if color isn't supported.

Any ideas how I can get colored output with the logging module?


Source: (StackOverflow)