<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: color code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 07:46:32 GMT</pubDate>
    <description>DZone Snippets: color code</description>
    <item>
      <title>Ruby method to determine if a string would look more readable on black vs. white.</title>
      <link>http://snippets.dzone.com/posts/show/5455</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def self.ideal_font_color_for(hex_str)&lt;br /&gt;	hex_str = hex_str.split('#').last&lt;br /&gt;&lt;br /&gt;	threshold = 105&lt;br /&gt;&lt;br /&gt;	r = hex_str[0..1].hex&lt;br /&gt;	g = hex_str[2..3].hex&lt;br /&gt;	b = hex_str[4..5].hex&lt;br /&gt;&lt;br /&gt;	delta = (r*0.299) + (g*0.587) + (b*0.114)&lt;br /&gt;&lt;br /&gt;	255 - delta &lt; threshold ? "#000000" : "#FFFFFF"&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 02 May 2008 20:41:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5455</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Print color highlighted strings to unix terminal</title>
      <link>http://snippets.dzone.com/posts/show/5445</link>
      <description>Sample of escape sequences needed to print in color to unix/linux terminal.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;print x.replace('toostis', '\033[0;31mtoostis\033[m')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This will highlight all 'toostis' instances in x with red.</description>
      <pubDate>Wed, 30 Apr 2008 11:06:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5445</guid>
      <author>kedder (Andrey lebedev)</author>
    </item>
    <item>
      <title>Retrieve the color from an SVG shape</title>
      <link>http://snippets.dzone.com/posts/show/5291</link>
      <description>&lt;code&gt;&lt;br /&gt;    &lt;rect id="c1" x="510"&lt;br /&gt;y="120" width="20px" height="20px" fill="pink" stroke="blue" onclick="setPenColour(evt)"/&gt;&lt;br /&gt;  &lt;![CDATA[&lt;br /&gt;  function setPenColour(evt) {&lt;br /&gt;    m_pen_colour = evt.target.getAttribute('fill');&lt;br /&gt;  }&lt;br /&gt;  ]]&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Reference: &lt;br /&gt;&lt;a href="http://www.kevlindev.com/tutorials/basics/index.htm"&gt;Tutorials - SVG&lt;/a&gt; [kevlindev.com]&lt;br /&gt;&lt;a href="http://www.kevlindev.com/tutorials/basics/events/mouse/svg_js/index.htm"&gt;Tutorials - SVG - Events&lt;/a&gt; [kevlindev.com]</description>
      <pubDate>Sun, 30 Mar 2008 14:37:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5291</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Unix Console Styler</title>
      <link>http://snippets.dzone.com/posts/show/4822</link>
      <description>This modue can be used to apply many style on Unix* terminals&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# Unix Console Style&lt;br /&gt;# You can use this module to apply a style on the terminal&lt;br /&gt;#&lt;br /&gt;# &lt;b&gt;DON'T WORK ON WINDOWS (Only on *nix Terminal)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;module UnixConsoleStyler&lt;br /&gt;  class StyleNotFoundException &lt; Exception; end&lt;br /&gt;  &lt;br /&gt;  # Availables Styles&lt;br /&gt;  STYLE = {&lt;br /&gt;      :default    =&gt;    "\033[0m",&lt;br /&gt;    	# styles&lt;br /&gt;    	:bold       =&gt;    "\033[1m",&lt;br /&gt;    	:underline  =&gt;    "\033[4m",&lt;br /&gt;    	:blink      =&gt;    "\033[5m",&lt;br /&gt;    	:reverse    =&gt;    "\033[7m",&lt;br /&gt;    	:concealed  =&gt;    "\033[8m",&lt;br /&gt;    	# font colors&lt;br /&gt;    	:black      =&gt;    "\033[30m", &lt;br /&gt;    	:red        =&gt;    "\033[31m",&lt;br /&gt;    	:green      =&gt;    "\033[32m",&lt;br /&gt;    	:yellow     =&gt;    "\033[33m",&lt;br /&gt;    	:blue       =&gt;    "\033[34m",&lt;br /&gt;    	:magenta    =&gt;    "\033[35m",&lt;br /&gt;    	:cyan       =&gt;    "\033[36m",&lt;br /&gt;    	:white      =&gt;    "\033[37m",&lt;br /&gt;    	# background colors&lt;br /&gt;    	:on_black   =&gt;    "\033[40m", &lt;br /&gt;    	:on_red     =&gt;    "\033[41m",&lt;br /&gt;    	:on_green   =&gt;    "\033[42m",&lt;br /&gt;    	:on_yellow  =&gt;    "\033[43m",&lt;br /&gt;    	:on_blue    =&gt;    "\033[44m",&lt;br /&gt;    	:on_magenta =&gt;    "\033[45m",&lt;br /&gt;    	:on_cyan    =&gt;    "\033[46m",&lt;br /&gt;    	:on_white   =&gt;    "\033[47m" }&lt;br /&gt;  &lt;br /&gt;  # Methods to use if you want to apply a style&lt;br /&gt;  def UnixConsoleStyler::apply_style(style)&lt;br /&gt;    if STYLE.has_key? style&lt;br /&gt;      STDOUT.write STYLE[style]&lt;br /&gt;    else&lt;br /&gt;      raise StyleNotFoundException, "Style #{style} not found"&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 28 Nov 2007 19:21:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4822</guid>
      <author>kedare (Mathieu Poussin)</author>
    </item>
    <item>
      <title>Gradient in an applet</title>
      <link>http://snippets.dzone.com/posts/show/3903</link>
      <description>&lt;code&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.applet.*;&lt;br /&gt;import javax.swing.*;&lt;br /&gt;&lt;br /&gt;public class JavaAppDe extends JApplet {&lt;br /&gt;	&lt;br /&gt;    public void init() {&lt;br /&gt;    }&lt;br /&gt;	&lt;br /&gt;    public void paint (Graphics g) {&lt;br /&gt;        super.paint(g);&lt;br /&gt;	int base = 0;&lt;br /&gt;	while(base&lt;255) {&lt;br /&gt;		g.setColor(new Color(base,base,base));&lt;br /&gt;		g.drawLine(0,base,255,base);&lt;br /&gt;		base++;&lt;br /&gt;	}&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 25 Apr 2007 20:54:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3903</guid>
      <author>kedare (Mathieu Poussin)</author>
    </item>
    <item>
      <title>Linux - command ls without color</title>
      <link>http://snippets.dzone.com/posts/show/3177</link>
      <description>// Elimina tutti i caratteri speciali che portano il colore&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ls --color=never&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 19 Dec 2006 22:55:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3177</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Colorize Function</title>
      <link>http://snippets.dzone.com/posts/show/2461</link>
      <description>/*&lt;br /&gt;I don't use the flash colorize function much so this is an example of how to colorize a movieclip with a supplied hexnumber&lt;br /&gt;&lt;br /&gt;colorize(0xff0000,my_movieClip);&lt;br /&gt;&lt;br /&gt;//will turn my_movieClip bright red.&lt;br /&gt;*/&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function colorize(c:Number,mc:MovieClip){&lt;br /&gt;  var tf:Transform = new Transform(mc);&lt;br /&gt;  var color_tf:ColorTransform = new ColorTransform();&lt;br /&gt;  color_tf.rgb = c;&lt;br /&gt;  tf.colorTransform = color_tf;&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 23 Aug 2006 08:42:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2461</guid>
      <author>heavysixer ()</author>
    </item>
    <item>
      <title>Color Picker drop-down box helper</title>
      <link>http://snippets.dzone.com/posts/show/2084</link>
      <description>// description of your code here&lt;br /&gt;This helper will generate a whole bunch o' colors in a drop down box, which which you can do whatever with.  Currently I am allowing users to change certain colors of the page.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;     def color_picker(name)&lt;br /&gt;       #build the hexes&lt;br /&gt;      hexes = []&lt;br /&gt;       (0..15).step(3) do |one|&lt;br /&gt;         (0..15).step(3) do |two|&lt;br /&gt;           (0..15).step(3) do |three|&lt;br /&gt;            hexes &lt;&lt; "#" + one.to_s(16) + two.to_s(16) + three.to_s(16)&lt;br /&gt;           end&lt;br /&gt;         end&lt;br /&gt;       end&lt;br /&gt;       arr = []&lt;br /&gt;       10.times { arr &lt;&lt; "&amp;nbsp;" }&lt;br /&gt;         returning html = '' do&lt;br /&gt;        html &lt;&lt; "&lt;select name=#{name}&gt;"&lt;br /&gt;        html &lt;&lt; hexes.collect {|c|&lt;br /&gt;          "&lt;option value='#{c}' style='background-color: #{c}'&gt;#{arr.join}&lt;/option&gt;" }.join("\n")&lt;br /&gt;        html &lt;&lt; "&lt;/select&gt;"&lt;br /&gt;      end&lt;br /&gt;     end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 22 May 2006 17:56:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2084</guid>
      <author>lono ()</author>
    </item>
    <item>
      <title>Python - change_color_entry</title>
      <link>http://snippets.dzone.com/posts/show/1714</link>
      <description>// Cambia il colore di sfondo di una gtk.Entry, ma il discorso vale anche&lt;br /&gt;// per la gtk.TextView...&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import gtk&lt;br /&gt;&lt;br /&gt;def change_color_entry(entry, color):&lt;br /&gt;    entry.modify_base(gk.STATE_NORMAL, gtk.gdk.color_parse(color))&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 18 Mar 2006 16:10:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1714</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Using &amp;lt;font&gt; (font tag) within pys60 Text widget</title>
      <link>http://snippets.dzone.com/posts/show/1612</link>
      <description>The Text widget allow rich text. However, it's quite&lt;br /&gt;difficult to use. You need to set each attribute&lt;br /&gt;(font, style, highlight, color) of the widget&lt;br /&gt;before adding more text with differert style.&lt;br /&gt;&lt;br /&gt;So, I make a function that make it a bit easier.&lt;br /&gt;The font tag (&lt;font&gt;&lt;/font&gt;) is used (borrowed from HTML).&lt;br /&gt;Attributes allowed are&lt;br /&gt;- color ( #RRGGBB or 0xRRGGBB or color name)&lt;br /&gt;- face ( both font and size eg. albi17b )&lt;br /&gt;- style ( bold, italic, underline or strikethrough )&lt;br /&gt; (styles can be combined using comma)&lt;br /&gt;- highlight ( standard, rounded, shadow)&lt;br /&gt;- hcolor ( highlight color )&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from appuifw import *&lt;br /&gt;&lt;br /&gt;def process_color(color):&lt;br /&gt;    color_name = {&lt;br /&gt;        'red': 0xff0000, 'green': 0x008000, 'blue':0x0000ff,       &lt;br /&gt;        'black': 0,      'white':0xffffff,      'yellow': 0xffff00&lt;br /&gt;        }&lt;br /&gt;    if color.startswith('#'):   # HTML format #000000&lt;br /&gt;        return int(color[1:], 16)&lt;br /&gt;    if color.startswith('0x'):  # pys60 format 0x000000&lt;br /&gt;        return int(color, 16)&lt;br /&gt;    return color_name[color]&lt;br /&gt;&lt;br /&gt;def set_ml(t, s):&lt;br /&gt;    stack = []&lt;br /&gt;    t.clear()&lt;br /&gt;    t.font = 'normal'&lt;br /&gt;    i = 0&lt;br /&gt;    while i &lt; len(s):&lt;br /&gt;        if s.startswith('&lt;', i):  # tag end or tag begin&lt;br /&gt;            j = s.find('&gt;', i) + 1&lt;br /&gt;            if s[i:i+7] == '&lt;/font&gt;' or s[i:i+3] == '&lt;/&gt;':&lt;br /&gt;                t.color, t.font, t.style, t.highlight_color = stack.pop()&lt;br /&gt;            else:&lt;br /&gt;                stack.append([t.color, t.font, t.style, t.highlight_color])&lt;br /&gt;                to_style = 0&lt;br /&gt;                for attr_val in s[i:j-1].split(' '):&lt;br /&gt;                    if '=' in attr_val:&lt;br /&gt;                        attr, val = attr_val.split('=')&lt;br /&gt;                        if attr == 'color':&lt;br /&gt;                            t.color = process_color(val)&lt;br /&gt;                        elif attr == 'face':&lt;br /&gt;                            t.font = unicode(val)&lt;br /&gt;                        elif attr == 'hcolor':&lt;br /&gt;                            t.highlight_color = process_color(val)&lt;br /&gt;                        elif attr == 'style':   # style and highlight go together&lt;br /&gt;                            to_style |= eval('|'.join(['STYLE_' + st.upper() for st in val.split(',')]))&lt;br /&gt;                        elif attr == 'highlight':&lt;br /&gt;                            to_style |= eval("HIGHLIGHT_" + val.upper())&lt;br /&gt;                if to_style:&lt;br /&gt;                    t.style = to_style&lt;br /&gt;        else:    # normal text&lt;br /&gt;            j = s.find('&lt;', i)&lt;br /&gt;            if j == -1: j = len(s)&lt;br /&gt;            text = u'' + s[i:j].replace('&amp;lt;', '&lt;')&lt;br /&gt;            t.add(text)&lt;br /&gt;        i = j      # go next chunk&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now you can use it easily&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; t = app.body   # use the default Text widget that start pys60&lt;br /&gt;&gt;&gt;&gt; set_ml(t, '&lt;font color=red&gt;Hello&lt;/font&gt; &lt;font style=bold&gt;World&lt;/font&gt;.')&lt;br /&gt;&gt;&gt;&gt;  # a stylish 'Hello World' is displayed&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Notice:&lt;br /&gt;- Quotation marks are not used to specify attribute values.&lt;br /&gt;- A &lt;/&gt; shorthand can be used for &lt;/font&gt;&lt;br /&gt;- &lt;font&gt; can be nested.</description>
      <pubDate>Thu, 02 Mar 2006 11:19:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1612</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
