<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>caioariede.com weblog &#187; Python</title>
	<atom:link href="http://caioariede.com/category/python/feed" rel="self" type="application/rss+xml" />
	<link>http://caioariede.com</link>
	<description>— coding for great good</description>
	<lastBuildDate>Wed, 08 Sep 2010 03:48:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Calculating gradient colors with Python</title>
		<link>http://caioariede.com/2008/calculating-gradient-colors-with-python</link>
		<comments>http://caioariede.com/2008/calculating-gradient-colors-with-python#comments</comments>
		<pubDate>Wed, 31 Dec 2008 20:29:27 +0000</pubDate>
		<dc:creator>Caio Ariede</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://caioariede.com/?p=275</guid>
		<description><![CDATA[The algorithm below, calculates and returns colors to make a gradient. The input colors must be in hexadecimal, like 000000 or FF0000 (without #).
The third parameter specifies the size of your gradient. By example, in an image of 100 pixels, the length is 100, and in a phrase of 3 characters the length is 3.
Usage

# [...]]]></description>
			<content:encoded><![CDATA[<p>The algorithm below, calculates and returns colors to make a gradient. The input colors must be in hexadecimal, like 000000 or FF0000 (without #).</p>
<p>The third parameter specifies the size of your gradient. By example, in an image of 100 pixels, the length is 100, and in a phrase of 3 characters the length is 3.</p>
<h2>Usage</h2>
<pre lang="python">
# it returns 3 colors, one per letter
color_a, color_b, color_c = gradient('000000', 'FF0000', len('abc'))
</pre>
<h2>Code</h2>
<pre lang="python">def gradient(start, end, length):

    # transform HEX to R G B

    __sr = int(start[0:2].upper(), 16) # 0
    __sg = int(start[2:4].upper(), 16) # 0
    __sb = int(start[4:6].upper(), 16) # 0

    __er = int(end[0:2].upper(), 16) # 255
    __eg = int(end[2:4].upper(), 16) # 255
    __eb = int(end[4:6].upper(), 16) # 255

    # calculate distance to make gradient

    stepr = (__er - __sr) / (length - 1) # 63
    stepg = (__eg - __sg) / (length - 1) # 63
    stepb = (__eb - __sb) / (length - 1) # 63

    # a color per step

    colors = [0] * length

    for i in range(0, length):

        if i == 0:
            # first color
            r = '%02X' % __sr
            g = '%02X' % __sg
            b = '%02X' % __sb
        elif i == length - 1:
            # last color
            r = '%02X' % __er
            g = '%02X' % __eg
            b = '%02X' % __eb
        else:
            # middle color
            r = '%02X' % (__sr + int(stepr) * i)
            g = '%02X' % (__sg + int(stepg) * i)
            b = '%02X' % (__sb + int(stepb) * i)

        colors[i] = r + g + b

    return colors</pre>
]]></content:encoded>
			<wfw:commentRss>http://caioariede.com/2008/calculating-gradient-colors-with-python/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Verificando tipo da variável em Python</title>
		<link>http://caioariede.com/2008/verificando-tipo-da-variavel-em-python-checking-variable-type</link>
		<comments>http://caioariede.com/2008/verificando-tipo-da-variavel-em-python-checking-variable-type#comments</comments>
		<pubDate>Mon, 14 Apr 2008 15:09:23 +0000</pubDate>
		<dc:creator>Caio Ariede</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://caioariede.com/2008/verificando-tipo-da-variavel-em-python-checking-variable-type</guid>
		<description><![CDATA[Estava procurando um método, ou uma função, para Python equivalente aos is_int, is_float, is_string do PHP, até que método abaixo para a comparação, não sei se é o melhor método, em questão de performance, etc.. Segue abaixo a quem interessar.

publici@publici2-desktop:~/python/$ python
Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type [...]]]></description>
			<content:encoded><![CDATA[<p>Estava procurando um método, ou uma função, para Python equivalente aos is_int, is_float, is_string do PHP, até que método abaixo para a comparação, não sei se é o melhor método, em questão de performance, etc.. Segue abaixo a quem interessar.</p>
<p><span id="more-33"></span></p>
<pre lang="python">publici@publici2-desktop:~/python/$ python
Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; type('teste') == str
True
&gt;&gt;&gt; type(1) == int
True
&gt;&gt;&gt; type(-1) == int
True
&gt;&gt;&gt; type(1.5) == int
False
&gt;&gt;&gt; type(1.5) == float
True
&gt;&gt;&gt; type((1,2)) == tuple
True
&gt;&gt;&gt; type([1,2]) == list
True
</pre>
<p>Até.</p>
]]></content:encoded>
			<wfw:commentRss>http://caioariede.com/2008/verificando-tipo-da-variavel-em-python-checking-variable-type/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
