RGB to HSL conversion

I’ve been reading several wiki pages and checking different calculations, and creating visualizations of RGB cube projection onto a hexagon. And I’d like to post my understanding of this conversion. Since I find this conversion (representations of color models using geometric shapes) interesting, I’ll try to be as thorough as I can be. First, let’s … Read more

How to pick good contrast RGB colors programmatically?

There is some information in the Web Content Accessibility Guidelines (WCAG) 2.0 (http://www.w3.org/TR/2008/REC-WCAG20-20081211) Visual contrast: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#visual-audio-contrast-contrast Contrast ratio: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef Relative luminance : http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef There’s a good example in this site but he calculate where two colors are enough, not how to get them. To choose a color with good contrast, I’d go with complementary colors: … Read more

SVG fill color transparency / alpha?

You use an addtional attribute; fill-opacity: This attribute takes a decimal number between 0.0 and 1.0, inclusive; where 0.0 is completely transparent. For example: <rect … fill=”#044B94″ fill-opacity=”0.4″/> Additionally you have the following: stroke-opacity attribute for the stroke opacity for the entire object

navbar color in Twitter Bootstrap

You can overwrite the bootstrap colors, including the .navbar-inner class, by targetting it in your own stylesheet as opposed to modifying the bootstrap.css stylesheet, like so: .navbar-inner { background-color: #2c2c2c; /* fallback color, place your own */ /* Gradients for modern browsers, replace as you see fit */ background-image: -moz-linear-gradient(top, #333333, #222222); background-image: -ms-linear-gradient(top, #333333, … Read more

gnuplot: apply colornames from datafile

In case somebody wants to use a lookup table as @Ethan suggested, here are the 111 predefined gnuplot colors in arrays (taken from the gnuplot manual). array ColorNames[111] = \ [‘white’, ‘black’, ‘dark-grey’, ‘red’, ‘web-green’, ‘web-blue’, ‘dark-magenta’, ‘dark-cyan’, ‘dark-orange’, ‘dark-yellow’, \ ‘royalblue’, ‘goldenrod’, ‘dark-spring-green’, ‘purple’, ‘steelblue’, ‘dark-red’, ‘dark-chartreuse’, ‘orchid’, ‘aquamarine’, ‘brown’, \ ‘yellow’, ‘turquoise’, ‘grey0’, … Read more

Converting hex color to RGB and vice-versa

In python: def hex_to_rgb(value): “””Return (red, green, blue) for the color given as #rrggbb.””” value = value.lstrip(‘#’) lv = len(value) return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3)) def rgb_to_hex(red, green, blue): “””Return color as #rrggbb for the given color values.””” return ‘#%02x%02x%02x’ % (red, green, blue) hex_to_rgb(“#ffffff”) … Read more