<?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>Carlan+Calazans</title>
	<atom:link href="http://carlancalazans.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://carlancalazans.com</link>
	<description>{ Às vezes eu sonho com códigos }</description>
	<lastBuildDate>Thu, 28 Oct 2010 22:56:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>RubyConf Brasil &#8211; dia 2 (final)</title>
		<link>http://carlancalazans.com/rubyconf-brasil-dia-2-final/</link>
		<comments>http://carlancalazans.com/rubyconf-brasil-dia-2-final/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 22:56:34 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[eventos]]></category>
		<category><![CDATA[ruby learning]]></category>
		<category><![CDATA[ruby rails]]></category>
		<category><![CDATA[rubyconf]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=356</guid>
		<description><![CDATA[Segundo dia
É impressão minha ou sempre as melhores &#8220;coisas&#8221; ficam pro final? IMHO, o segundo dia, foi muito melhor que o primeiro. Os palestrantes estavam mais animados e o conteúdo das palestras foram muito interessantes (e não davam sono).
Palestras
O segundo dia começou com o Evan Phoenix (@evanphx) falando sobre Rubinius. Acredito que todos ficaram impressionados [...]]]></description>
			<content:encoded><![CDATA[<h4>Segundo dia</h4>
<p>É impressão minha ou sempre as melhores &#8220;coisas&#8221; ficam pro final? IMHO, o segundo dia, foi muito melhor que o primeiro. Os palestrantes estavam mais animados e o conteúdo das palestras foram muito interessantes (e não davam sono).</p>
<h4>Palestras</h4>
<p>O segundo dia começou com o Evan Phoenix (<a href="http://twitter.com/evanphx">@evanphx</a>) falando sobre <a href="http://rubini.us">Rubinius</a>. Acredito que todos ficaram impressionados com as ferramentas de profiling. Achei muito estranho como os commits do projeto são organizados (ou não possuem organização). Logo depois do café, na sala 1, o Charles Nutter (<a href="http://twitter.com/headius">@headius</a>) subiu ao palco para falar sobre <a href="http://jruby.org">JRuby</a>. Uma parte interessante da palestra aconteceu quase no final quando ele mostrou o JRuby rodando no emulador do <a href="http://www.android.com">Android</a> através do <a href="http://groups.google.com/group/ruboto">Ruboto</a>.</p>
<p>A palestra do David Chelimsky (<a href="http://twitter.com/dchelimsky">@dchelimsky</a>) foi bem divertida por que ele deu exemplos bem claros onde o princípio DRY se encaixa e onde não faz sentido aplicá-lo. Depois do almoço, na sala 2, o Rodrigo Franco (<a href="http://twitter.com/caffo">@caffo</a>) fez um relato de como é a vida de um desenvolvedor que trabalha em casa para empresas estrangeiras remotamente. Ele apresentou também um conjunto de dicas e ferramentas que visam auxiliar desde como controlar suas horas trabalhadas até emissão de nota fiscal. Logo em seguida veio o Scott Chacon (<a href="http://twitter.com/chacon">@chacon</a>) novamente, mas desta vez para falar sobre novidades e formas avançadas de utilização do <a href="http://git-scm.com">git</a>.</p>
<p>Depois do Coffee Break da tarde fui ver o Guilherme Silveira (<a href="http://twitter.com/guilhermecaelum">@guilhermecaelum</a>) e o Anderson Leite (<a href="http://twitter.com/anderson_leite">@anderson_leite</a>) com a palestra &#8220;O melhor dos dois mundos: funcional e orientado a objetos&#8221;. Os dois deram dicas bem bacanas sobre programação funcional. Pra finalizar o evento o Jim Weirich (<a href="http://twitter.com/jimweirich">@jimweirich</a>) deu uma aula sobre um conjunto de princípios que melhoram um design orientado a objetos.</p>
<h4>Conclusão</h4>
<p>Como muitos, também acredito que este evento é único. O nível das palestras, a organização, a disposição dos participantes e o respeito a outras linguagens de programação. O nível de respeito foi tanto que não consigo comparar com o ano passado, onde muitos palestrantes fizeram piadas de outras linguagens. A organização do evento teve alguns problemas com a rede wifi e o ar condicionado, mas nada que atrapalhasse alguém a assistir uma palestra. Estes pequenos problemas sempre vão existir aos olhos de alguém. Resumindo, gostei muito do evento e volto o ano que vem sem pensar.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/rubyconf-brasil-dia-2-final/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RubyConf Brasil</title>
		<link>http://carlancalazans.com/rubyconf-brasil/</link>
		<comments>http://carlancalazans.com/rubyconf-brasil/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 23:41:35 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[eventos]]></category>
		<category><![CDATA[ruby learning]]></category>
		<category><![CDATA[ruby rails]]></category>
		<category><![CDATA[rubyconf]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=347</guid>
		<description><![CDATA[Primeiro dia
É muito bom estar de volta a São Paulo e ter a oportunidade de respirar ar novo. Este ar novo vem acomanhado de novas idéias, novas amizades e conhecimento. O RubyConf (antigo Rails Summit Latin America) é o único evento, fora do Espírito Santo, que faço questão de comparecer todos os anos.
Palestras
O dia começou [...]]]></description>
			<content:encoded><![CDATA[<h4>Primeiro dia</h4>
<p>É muito bom estar de volta a São Paulo e ter a oportunidade de respirar ar novo. Este ar novo vem acomanhado de novas idéias, novas amizades e conhecimento. O <a href="http://rubyconf.com.br">RubyConf</a> (antigo Rails Summit Latin America) é o único evento, fora do Espírito Santo, que faço questão de comparecer todos os anos.</p>
<h4>Palestras</h4>
<p>O dia começou com o Fábio Akita (<a href="http://twitter.com/akitaonrails">@AkitaOnRails</a>) dando uma geral no Ruby e no Rails do passado até os dias atuais. Uma parte legal desta palestra foi o comentário sobre prática e o poder de uma idéia. Em seguida, na sala 1, foi a vez do Yehuda Katz (<a href="http://twitter.com/wycats">@wycats</a>) subir ao palco e falar sobre o lado do cliente no desenvolvimento de aplicações onde o foco é server-side. Boa parte das dicas que ele mencionou estão em um <a href="http://is.gd/gkdH2">post</a> do blog da <a href="http://www.caelum.com.br">Caelum</a>, recomendo a leitura.</p>
<p>A próxima palestra da sala 1 foi dada pelo Scott Chacon (<a href="http://twitter.com/chacon">@chacon</a>) ao invés do Chris Wanstrath (<a href="http://twitter.com/defunkt">@defunkt</a>) como esperado. O assunto foi processos em background e como o pessoal do <a href="http://github.com">github</a> resolveu este problema. Logo depois do almoço foi a vez do José Valim (<a href="http://twitter.com/josevalim">@josevalim</a>) falar sobre Rails 2.3, 3.0 e 3.1: passado, presente e futuro.</p>
<p>Continuando, na sala 2, foi a vez do Pedro Franceschi (<a href="http://twitter.com/pedroh96">@pedroh96</a>) de apenas 14 anos falar sobre como integrar aplicações iPhone com Rails. Depois foi a vez do Lucas Húngaro (<a href="http://twitter.com/lucashungaro">@lucashungaro</a>) relatar suas dificuldades com aplicações Rails em produção e passar o conhecimento adiante de como resolver a maioria dos problemas que todos nós podemos encontrar.</p>
<p>Pra finalizar, a desconferência começou com o Luca Bastos (<a href="http://twitter.com/lucabastos">@lucabastos</a>) apresentando como os desenvolvedores de hoje em dia são todos EMOs e os programadores de sua época é que eram machos. E a última palestra (que eu assisti) foi a do Fernando Vieira (<a href="http://twitter.com/fnando">@fnando</a>) onde ele apresentou uma aplicação muito bacana feita com Rails + Nodejs.</p>
<h4>Finalizando</h4>
<p>Tive a oportunidade de encontrar novamente o William Molinari (<a href="http://twitter.com/pothix">@pothix</a>) e este ano também a Letícia Figueira (<a href="http://twitter.com/_leticia">_leticia</a>), já conhecia ambos do <a href="http://rubylearning.org">rubylearning.org</a>.</p>
<p>Amanhã tem mais <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/rubyconf-brasil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails sem domínio</title>
		<link>http://carlancalazans.com/ruby-on-rails-sem-dominio/</link>
		<comments>http://carlancalazans.com/ruby-on-rails-sem-dominio/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 07:51:03 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby rails]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/ruby-on-rails-sem-dominio/</guid>
		<description><![CDATA[Bateu uma sensação de dejá vu agora. No ano passado ocorreu o mesmo problema e vários desenvolvedores ficaram sem poder acessar o site. Acredito que o conteúdo mais acessado é a api do Ruby in Rails, pelo menos é o conteúdo que uso com mais frequência.
No ano passado não demorou muito tempo para o problema [...]]]></description>
			<content:encoded><![CDATA[<p>Bateu uma sensação de dejá vu agora. No ano passado ocorreu o mesmo problema e vários desenvolvedores ficaram sem poder acessar o site. Acredito que o conteúdo mais acessado é a api do Ruby in Rails, pelo menos é o conteúdo que uso com mais frequência.</p>
<p>No ano passado não demorou muito tempo para o problema ser resolvido. Só nos resta aguardar.</p>
<p><a href="http://carlancalazans.com/wp-content/uploads/2010/04/p_480_320_09530465-4F7B-4792-8B7C-3B1DA88DD3BF.jpeg"><img src="http://carlancalazans.com/wp-content/uploads/2010/04/p_480_320_09530465-4F7B-4792-8B7C-3B1DA88DD3BF.jpeg" alt="" class="alignnone size-full" /></a></p>
<p><a href="http://carlancalazans.com/wp-content/uploads/2010/04/p_480_320_5B581D97-1E9F-41D1-B082-C07A8FFB1FC6.jpeg"><img src="http://carlancalazans.com/wp-content/uploads/2010/04/p_480_320_5B581D97-1E9F-41D1-B082-C07A8FFB1FC6.jpeg" alt="" class="alignnone size-full" /></a></p>
<p><strong>Update:</strong><br />
O domínio .org foi renovado por 20 anos <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/ruby-on-rails-sem-dominio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vitória merece</title>
		<link>http://carlancalazans.com/vitoria-merece/</link>
		<comments>http://carlancalazans.com/vitoria-merece/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 01:06:33 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=325</guid>
		<description><![CDATA[Updated!
Podem marcar no calendário pois dia 29 de maio Vitóra/ES vai concentrar o número máximo de desenvolvedores já reunidos em um local. A intenção é mover a ilha pra um lugar com mais sombra já que o sol está tostando todos os capixabas. WTF?
O real motivo deste post
Na verdade não é bem isso. Realmente algo [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>Updated!</em></strong></p>
<p>Podem marcar no calendário pois dia 29 de maio Vitóra/ES vai concentrar o número máximo de desenvolvedores já reunidos em um local. A intenção é mover a ilha pra um lugar com mais sombra já que o sol está tostando todos os capixabas. <strong>WTF?</strong></p>
<h3>O real motivo deste post</h3>
<p>Na verdade não é bem isso. Realmente algo de muito bom vai acontecer em Vitória/ES no dia 29 de maio. Trata-se do evento <a href="http://www.mare-vix.com">Maré de Agilidade em Vitória/ES</a> (ou Maré Vix) e a real intenção deste evento é reunir os interessados para trocar experiências e bater um papo sobre o tema. Alguns dos palestrantes já são conhecidos pela comunidade como você pode ver na figura abaixo:</p>
<div id="attachment_327" class="wp-caption aligncenter" style="width: 296px"><a href="http://carlancalazans.com/wp-content/uploads/2010/04/marevixprogramacao.png"><img src="http://carlancalazans.com/wp-content/uploads/2010/04/marevixprogramacao-286x300.png" alt="Maré Vix - programação" title="Maré Vix programação" width="286" height="300" class="size-medium wp-image-327" /></a><p class="wp-caption-text">Maré Vix - programação</p></div>
<p>A empresa em que trabalho (<a href="http://www.highlan.com.br">Highlan</a>) é uma das patrocinadoras do evento junto com outras empresas (ou grupo de usuários) de grande nome (vide figura).</p>
<div id="attachment_326" class="wp-caption aligncenter" style="width: 313px"><a href="http://carlancalazans.com/wp-content/uploads/2010/04/marevixpatrocinadores.png"><img src="http://carlancalazans.com/wp-content/uploads/2010/04/marevixpatrocinadores.png" alt="Maré Vix - patrocinadores" title="Maré Vix patrocinadores" width="303" height="219" class="size-full wp-image-326" /></a><p class="wp-caption-text">Maré Vix - patrocinadores</p></div>
<p>Se você se interessa pelo assunto, divulgue e apareça no evento!</p>
<p>Veja também:</p>
<ul>
<li><a href="http://www.mare-vix.com">Site do evento</a></li>
<li><a href="http://www.jeveaux.com/blog/2010/mare-de-agilidade-em-vitoria-es-mare-vix">Post no blog do Jeveaux</a></li>
<li><a href="http://www.franciscosouza.net/2010/04/19/divulgando-mare-de-agilidade-em-vitoria/">Post no blog do Francisco Souza</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/vitoria-merece/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Rapidinha: instalando o MicroXP no VirtualBox</title>
		<link>http://carlancalazans.com/rapidinha-instalando-o-microxp-no-virtualbox/</link>
		<comments>http://carlancalazans.com/rapidinha-instalando-o-microxp-no-virtualbox/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 00:19:32 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[rapidinha]]></category>
		<category><![CDATA[virtualbox]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=288</guid>
		<description><![CDATA[Resolvi escrever (ou tirar do draft) sobre algo que faz parte do meu dia-a-dia no trabalho, ou seja, lidar com máquinas virtuais. A pouco tempo atrás quando se falava em máquina virtual o que me vinha na mente era o aplicativo VMWare. De lá pra cá, eu só tinha lido sobre o assunto e feito somente [...]]]></description>
			<content:encoded><![CDATA[<p>Resolvi escrever (ou tirar do draft) sobre algo que faz parte do meu dia-a-dia no <a href="http://www.highlan.com.br">trabalho</a>, ou seja, lidar com <a href="http://en.wikipedia.org/wiki/Virtual_machine">máquinas virtuais</a>. A pouco tempo atrás quando se falava em máquina virtual o que me vinha na mente era o aplicativo <a href="http://www.vmware.com">VMWare</a>. De lá pra cá, eu só tinha lido sobre o assunto e feito somente 01 único teste. Até por que o VMWare é pago.</p>
<p>Pesquisando sobre o assunto e procurando uma solução livre, um ex-chefe me sugeriu dar uma olhada no <a href="http://www.virtualbox.org">VirtualBox</a>. Sem dúvidas ele me pareceu bem melhor do que o <a href="http://www.qemu.org">Qemu</a>, por exemplo. Não que este último seja ruim, mas uma das facilidades que eu precisava era acesso a rede e a configuração da interface do hospedeiro não era nada simples. Por outro lado, no VirtualBox, através da documentação encontrei as informações que precisava e tudo funcionou corretamente. Comecei a gostar desse aplicativo.</p>
<p>No início do ano passado a <a href="http://www.sun.com">Sun</a> comprou a <a href="http://www.virtualbox.org/wiki/innotek">Innotek</a>, empresa que criou o VirtualBox. O aplicativo melhorou muito desde que a Sun assumiu. As atualizações ficaram mais frequêntes, a configuração de rede se faz com dois cliques do mouse, a documentação ficou mais clara e objetiva, dentre outras coisas.</p>
<p>Abaixo se encontra o vídeo de instalação, veja como o processo é simples <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div id="mvcontainer"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>
<p><script src="https://media.dreamhost.com/mp4/swfobject.js" type="text/javascript"></script> <script type="text/javascript">// <![CDATA[
var s1 = new SWFObject("https://media.dreamhost.com/mp4/player.swf","ply","470","320","9","#FFFFFF");
s1.addParam("allowfullscreen","true");
s1.addParam("allowscriptaccess","always");
s1.addParam('wmode','opaque');
s1.addVariable('bufferlength','10');
s1.addVariable("file","http://files.carlancalazans.com/videos/microxp.mov");
s1.write("mvcontainer");
// ]]&gt;</script><br />
<a href="http://files.carlancalazans.com/videos/microxp.mov">Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/rapidinha-instalando-o-microxp-no-virtualbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://files.carlancalazans.com/videos/microxp.mov" length="170352813" type="video/quicktime" />
		</item>
		<item>
		<title>Rapidinha: juntando várias imagens em uma</title>
		<link>http://carlancalazans.com/rapidinha-juntando-varias-imagens-em-uma/</link>
		<comments>http://carlancalazans.com/rapidinha-juntando-varias-imagens-em-uma/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 23:36:45 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=263</guid>
		<description><![CDATA[Uns dias atrás precisei juntar várias imagens separadas em único arquivo para descobrir o que estava causando um espaçamento em um arquivo de saída postscript gerado através de uma aplicação que desenvolvemos na empresa em que trabalho. As imagens em questão compõem uma track (área gráfica) em um software de acompanhamento geológico desenvolvido para a [...]]]></description>
			<content:encoded><![CDATA[<p>Uns dias atrás precisei juntar várias imagens separadas em único arquivo para descobrir o que estava causando um espaçamento em um arquivo de saída postscript gerado através de uma aplicação que desenvolvemos na <a href="http://www.highlan.com.br">empresa</a> em que trabalho. As imagens em questão compõem uma track (área gráfica) em um software de acompanhamento geológico desenvolvido para a <a href="http://www.petrobras.com.br">Petrobrás</a>, muito parecido com <a href="http://carlancalazans.com/wp-content/uploads/2009/09/aplicativo.png">isto</a> por sinal. Enfim, não necessariamente as imagens precisam fazer parte de um gráfico. No meu caso, como eu precisava de uma imagem orientada na vertical, as imagens deveriam ter as mesmas dimensões, seguir uma nomenclatura que eu pudesse trabalhar facilmemente e só <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Como fazer coisas repetitivas semprem dão sono, na maioria das pessoas, resolvi criar uma pequenina classe em Ruby baseado no que eu escrevi <a href="http://carlancalazans.com/rapidinha-gif-animado-com-ruby">aqui</a>. Segue a classe em questão.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'RMagick'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">include</span> Magick<br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> JoinImages<br />
&nbsp;<br />
&nbsp; attr_accessor <span style="color:#ff3333; font-weight:bold;">:source</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> save<span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@images</span> = load_files<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@images</span>.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; private<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> load_files<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span> = ImageList.<span style="color:#9900CC;">new</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">entries</span><span style="color:#006600; font-weight:bold;">&#40;</span>source<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">reject</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> f =~ <span style="color:#006600; font-weight:bold;">/</span>^\.<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">sort</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>a,b<span style="color:#006600; font-weight:bold;">|</span> a.<span style="color:#9900CC;">to_i</span><span style="color:#006600; font-weight:bold;">&lt;=&gt;</span>b.<span style="color:#9900CC;">to_i</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">read</span> <span style="color:#996600;">&quot;#{source}/#{f}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">append</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#008000; font-style:italic;">#Usage:</span><br />
<span style="color:#008000; font-style:italic;">#gif = JoinImages.new</span><br />
<span style="color:#008000; font-style:italic;">#gif.source = 'img'</span><br />
<span style="color:#008000; font-style:italic;">#gif.save 'track1.gif'</span></div></div>
<p>As minhas imagens foram salvas no formato &#8220;001.png&#8221;, &#8220;021.png&#8221;, &#8220;250.png&#8221; e assim por diante, ou seja, traduzindo temos &#8220;0&#8243; como a track 1 (área gráfica 1) e &#8220;2&#8243; como a track 3 (área gráfica 3), o resto é relativo a um contador. </p>
<p>Para montar a imagens final corretamente, existe uma ordenação no código, estou ordenando as imagem usando a parte numérica do nome do arquivo, como mencionado acima. É possível usar uma expressão regular para pegar somente as imagens que desejamos no bloco &#8220;reject&#8221; também.</p>
<p>Espero que seja útil pra alguém.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/rapidinha-juntando-varias-imagens-em-uma/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Trapaceando no Monkey Kick Off</title>
		<link>http://carlancalazans.com/trapaceando-no-monkey-kick-off/</link>
		<comments>http://carlancalazans.com/trapaceando-no-monkey-kick-off/#comments</comments>
		<pubDate>Mon, 11 May 2009 23:30:23 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=222</guid>
		<description><![CDATA[Monkey Kick Off é um game em desenvolvido em flash pela Totebo Interactive. O objetivo do game é ajudar um macaco a chutar a bola o mais longe possível ou pelo menos até a vila dos macacos a 4000 metros de distância. Para chutar a bola basta clicar com o botão esquerdo do mouse ou [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.totebo.com/monkey-kick-off.php">Monkey Kick Off</a> é um game em desenvolvido em flash pela <a href="http://www.totebo.com">Totebo Interactive</a>. O objetivo do game é ajudar um macaco a chutar a bola o mais longe possível ou pelo menos até a vila dos macacos a 4000 metros de distância. Para chutar a bola basta clicar com o botão esquerdo do mouse ou pressionar qualquer tecla no teclado. </p>
<div id="attachment_236" class="wp-caption aligncenter" style="width: 410px"><img src="http://carlancalazans.com/wp-content/uploads/2009/05/picture-1.png" alt="Monkey Kick Off" title="Monkey Kick Off" width="400" height="300" class="size-full wp-image-236" /><p class="wp-caption-text">Monkey Kick Off</p></div>
<p>Simples, não? A quem diga que até um macaco consegue <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h4>Análise do problema</h4>
<p>É necessário um pouco de tempo até perceber que existem algumas variantes para conseguir chutar a bola a uma certa distância. Primeiro, há um momento, randômico, em que o macaco consegue levantar a bola até a altura máxima. Outra variante importante é o momento do chute. É preciso entender que existe um momento certo para se dar o chute. Este ponto fica entre a altura da cabeça e barriga do macaco.</p>
<p>Como a altura máxima da bola é randômico, esperar pelo momento certo pode levar muito tempo. O mesmo vale para a hora do chute, mas este é menos complicado, pois, pode ser calculado medindo o tempo gasto para a bola chegar no momento do chute.</p>
<p>Há outros fatores que também devem ser levados em consideração quando estamos jogando. As cores do game prejudicam a visão, se ficarmos olhando durante muito tempo os marcadores (os coqueiros ou a placa indicando que a vila dos macacos fica a 4000m) no plano de fundo começam a desaparecer. Se ficarmos muito tempo olhando para a tela, a visão pode ficar cansada e embaralhada.</p>
<h4>A solução (ou a trapaça)</h4>
<p>Depois de analisar o problema cheguei a conclusão que o meu computador pode fazer todo o trabalho por mim. Cheater, preguiçoso, eu? <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Resolvi criar um bot afim de monitorar o game, mais precisamente a minha tela, processar as variantes e chutar a bola. Seria mais ou menos assim, acesso a página do game e inicio o jogo. Logo após, inicio o bot em um console, lembrando de minimizar todas as janelas menos o navegador e posso ir tomar um café enquanto o aplicativo fica rodando.</p>
<p>Como mencionado acima, não existe um tempo correto para a bola chegar no ponto mais alto. É possível abordar este problema de várias formas que vão desde análise de imagens (screenshots) a redes neurais. A técnica mais simples é a análise de imagens e é nela que vou implementar o bot.</p>
<p>Para registro, estou utilizando a resolução de 1024 x 768 em dois monitores de 17&#8243;. Independente da resolução o bot poderá ser criado. Já fiz todo o processo que vou explicar a seguir em um macbook e tudo funciona normalmente. Para isso é necessário seguir alguns passos que listo no próximo parágrafo.</p>
<p>Para começar, é preciso mapear a altura máxima que a bola pode chegar, leia-se distância entre o topo e a esquerda, em relação a sua área de trabalho. Em seguida, recorte a imagem da bola de acordo com o passo anterior, pois, ela gira em seu eixo. Estes são os passos necessários para calibração do bot.</p>
<p>As etapas anteriores são um tanto quanto chatas, mas as que vem a seguir serão bem mais interessantes. Com a imagem da bola podemos compará-la com o screenshot que vamos tirar do ponto mapeado. E por último, se as imagens forem iguais, aguardamos o momento do chute e chutamos.</p>
<p>É claro que podem haver várias maneiras de se implementar os passos citados acima. Não estou levando em consideração o desempenho, pois, em todos os meus testes o desempenho foi suficiente. Inclusive se você que está lendo tiver alguma sugestão, por favor, sinta-se a vontade para compartilhar.</p>
<p>Agora, um pouco de código.</p>
<h4>Passo 1 e 2 (calibração)</h4>
<p>Tire uma screenshot do navegador com o game iniciado (foto abaixo), com um software de edição de imagens meça a distância do topo (padTop) e esquerda (padLeft) do canvas do game (linhas azuis).</p>
<div id="attachment_259" class="wp-caption aligncenter" style="width: 310px"><a href="http://carlancalazans.com/wp-content/uploads/2009/05/picture-21.png"><img src="http://carlancalazans.com/wp-content/uploads/2009/05/picture-21-300x187.png" alt="Mapeamento" title="Mapeamento" width="300" height="187" class="size-medium wp-image-259" /></a><p class="wp-caption-text">Mapeamento</p></div>
<p>Agora, configure a classe para tirar fotos somente do canvas, encontre a imagem do ponto (linhas vermelhas) mais alto que a bola pode chegar analisando todas as imagens e, por último, com um software de edição de imagens meça novamente a distância do topo e esquerda, mas desta vez em relação a bola. Essa é uma das partes chatas.</p>
<p>Segue abaixo a classe para tirar fotos do game canvas.</p>
<p>TakeShoots.java (canvas)</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.image.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TakeShoots <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a> robot<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> padLeft, padTop, w, h<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> TakeShoots<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// settings for game canvas</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padLeft <span style="color: #339933;">=</span> <span style="color: #cc66cc;">185</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padTop <span style="color: #339933;">=</span> <span style="color: #cc66cc;">209</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w <span style="color: #339933;">=</span> <span style="color: #cc66cc;">640</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h <span style="color: #339933;">=</span> <span style="color: #cc66cc;">480</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// settings for ball</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//padLeft = 322;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//padTop = 431;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//w = 46;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//h = 46;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aawtexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">AWTException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Waiting 5 seg...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Initializing thread...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TSThread t <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TSThread<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> TSThread <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">int</span> howManyTimes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> file<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TSThread<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> times<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">howManyTimes</span> <span style="color: #339933;">=</span> times<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">howManyTimes</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;image <span style="color: #339933;">=</span> robot.<span style="color: #006633;">createScreenCapture</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arectangle+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Rectangle</span></a><span style="color: #009900;">&#40;</span>padLeft, padTop, w, h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;image&quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//file = new File(&quot;ball&quot;+i+&quot;.png&quot;);</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ImageIO.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>image,<span style="color: #0000ff;">&quot;png&quot;</span>, file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> TakeShoots<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Com a imagem do passo 1, recorte a imagem da bola no ponto mais alto em formato de quadrado. A bola possui o tamanho 46&#215;46. Salve este arquivo com o nome ball.png no diretório do arquivo java. No meu caso a screenshot do game canvas em que a bola chega no ponto mais alto e a imagem da bola (ball.png) podem ser visualizadas abaixo:</p>
<div id="attachment_254" class="wp-caption aligncenter" style="width: 410px"><img src="http://carlancalazans.com/wp-content/uploads/2009/05/higher2.png" alt="Ponto mais alto" title="Ponto mais alto" width="400" height="300" class="size-full wp-image-254" /><p class="wp-caption-text">Ponto mais alto</p></div>
<div id="attachment_248" class="wp-caption aligncenter" style="width: 56px"><img src="http://carlancalazans.com/wp-content/uploads/2009/05/ball.png" alt="Bola" title="Bola" width="46" height="46" class="size-full wp-image-248" /><p class="wp-caption-text">Bola</p></div>
<p>Se desejar, alterando a classe TakeShoots.java, podemos automatizar o processo tirando screenshots somente da bola, é uma forma de ter certeza que é o ponto mais alto também. Para isso faça:</p>
<p>TakeShoots.java (ball)</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.image.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TakeShoots <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a> robot<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> padLeft, padTop, w, h<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> TakeShoots<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// settings for all game canvas</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//padLeft = 185;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//padTop = 209;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//w = 640;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//h = 480;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// settings for ball</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padLeft <span style="color: #339933;">=</span> <span style="color: #cc66cc;">322</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padTop <span style="color: #339933;">=</span> <span style="color: #cc66cc;">431</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w <span style="color: #339933;">=</span> <span style="color: #cc66cc;">46</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h <span style="color: #339933;">=</span> <span style="color: #cc66cc;">46</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aawtexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">AWTException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Waiting 5 seg...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Initializing thread...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TSThread t <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TSThread<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> TSThread <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">int</span> howManyTimes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> file<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TSThread<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> times<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">howManyTimes</span> <span style="color: #339933;">=</span> times<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">howManyTimes</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;image <span style="color: #339933;">=</span> robot.<span style="color: #006633;">createScreenCapture</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arectangle+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Rectangle</span></a><span style="color: #009900;">&#40;</span>padLeft, padTop, w, h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//file = new File(&quot;image&quot;+i+&quot;.png&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ball&quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ImageIO.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>image,<span style="color: #0000ff;">&quot;png&quot;</span>, file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> TakeShoots<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<h4>Passo 3</h4>
<p>Com a imagem do passo 2 compare com outra imagem de tamanho 46&#215;46 (ou não). Faça os testes você mesmo, compare a imagem calibrada (ball.png) com qualquer outra 46&#215;46 no formato png. Faça também a comparação de ball.png com ela mesma e veja o resultado. </p>
<p>Estou utilizando uma forma bem simples para identificar se as imagens são iguais. Como se trata de uma imagem de tamanho pequeno, a comparação é feita pelos valores RGB das duas imagens pixel a pixel. Caso a imagem fosse maior que 46&#215;46, uma outra forma seria, traçar linhas horizontais / verticais ou nas diagonais e comparar os valores RGB somente daqueles pontos. Em softwares de detecção de movimento é possível aprender muitas formas de tratar este problema.</p>
<p>Ah, lembrando, as imagens devem estar no mesmo diretório do arquivo java quando executar a classe.</p>
<p>CompareImages.java</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.image.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CompareImages <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image1, image2<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> filename1, filename2<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> CompareImages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loadImages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> started <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> result <span style="color: #339933;">=</span> compareImage<span style="color: #009900;">&#40;</span>image1, image2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> started <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; ms.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Result: &quot;</span> <span style="color: #339933;">+</span> result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> loadImages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename1 <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ball.png&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filename2 <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ball.png&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image1 <span style="color: #339933;">=</span> ImageIO.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>filename1<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image2 <span style="color: #339933;">=</span> ImageIO.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>filename2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> compareImage<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image1, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> image1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> image1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> image1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image1.<span style="color: #006633;">getRGB</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getRGB</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> CompareImages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<h4>Passo 4</h4>
<p>Junte todos os passos anteriores em uma nova classe, quando a classe detectar que as imagens são iguais pressione e solte o botão esquerdo do mouse. Aproveitei este passo e criei um arquivo de configuração que é lido somente ao executar a classe em questão, isso evita recompilar o arquivo java só para ajustar os valores de configuração.</p>
<p>KickOffTrick.java (final)</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.image.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.imageio.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> KickOffTrick <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aproperties+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Properties</span></a> properties<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> propertiesFileName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;kickoff.properties&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> ball1, ball2<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a> robot<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> padLeft, padTop, w, h<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> KickOffTrick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; readPropertiesFile<span style="color: #009900;">&#40;</span>propertiesFileName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padLeft <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;paddingleft&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padTop <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;paddingtop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;shootwidth&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;shootheight&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ball1 <span style="color: #339933;">=</span> ImageIO.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ballimagefilename&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arobot+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Robot</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aawtexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">AWTException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Waiting 5s...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Prepare yourself...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Initializing thread...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TSThread t <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TSThread<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> readPropertiesFile<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> filename<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; properties <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aproperties+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Properties</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; properties.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afileinputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">FileInputStream</span></a><span style="color: #009900;">&#40;</span>filename<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aioexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">IOException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> TSThread <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066; font-weight: bold;">boolean</span> result<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TSThread<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ball2 <span style="color: #339933;">=</span> robot.<span style="color: #006633;">createScreenCapture</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Arectangle+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Rectangle</span></a><span style="color: #009900;">&#40;</span>padLeft, padTop, w, h<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #339933;">=</span> compareImage<span style="color: #009900;">&#40;</span>ball1, ball2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sleepbeforekick&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot.<span style="color: #006633;">mousePress</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputEvent</span></a>.<span style="color: #006633;">BUTTON1_MASK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; robot.<span style="color: #006633;">mouseRelease</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputEvent</span></a>.<span style="color: #006633;">BUTTON1_MASK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sleepafterkick&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ball2 <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athread+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Thread</span></a>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainteger+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Integer</span></a>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>properties.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sleepballshoot&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainterruptedexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InterruptedException</span></a> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> compareImage<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image1, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abufferedimage+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">BufferedImage</span></a> image2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> image1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> image1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> image1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>image1.<span style="color: #006633;">getRGB</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> image2.<span style="color: #006633;">getRGB</span><span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> KickOffTrick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>O arquivo de configuração ficou assim:</p>
<p>kickoff.properties</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># ball left distance<br />
paddingleft = 322<br />
# ball top distance<br />
paddingtop = 431<br />
# ball shoot width<br />
shootwidth = 46<br />
# ball shoot height<br />
shootheight = 46<br />
# ball filename (for comparation)<br />
ballimagefilename = ball.png<br />
# sleep before kick the ball in ms<br />
sleepbeforekick = 110<br />
# sleep after kick the ball in ms<br />
sleepafterkick = 10000<br />
# sleep interval for take another shoot<br />
sleepballshoot = 50</div></div>
<p>Não utilize os valores pré-selecionados, eles só estão preenchidos para você ter uma cola.</p>
<h4>Concluindo</h4>
<p>Talvez com este exemplo você não consiga bater nenhum record, mas vai ter a oportunidade de aprender coisas novas e interessantes. Eu me diverti pensando em como implementar a solução, espero que você se divirta lendo (ou fazendo todos os passos) <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Em breve os arquivos estarão no github.com se alguém se interessar.</p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/trapaceando-no-monkey-kick-off/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby calculando o dia da Páscoa</title>
		<link>http://carlancalazans.com/ruby-calculando-o-dia-da-pascoa/</link>
		<comments>http://carlancalazans.com/ruby-calculando-o-dia-da-pascoa/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 23:06:46 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[rapidinha]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=209</guid>
		<description><![CDATA[A Páscoa é uma data comemorativa que serve de referência para datas comemorativas móveis como Carnaval, Quaresma, Corpus Christ e outras. Por isso é importante saber quando a Páscoa vai ser comemorada. Além de interessante, serve como uma brincadeira para os garotos(as) de programa de plantão que não tem nada para fazer no feriado.
Cálculo
No total [...]]]></description>
			<content:encoded><![CDATA[<p>A Páscoa é uma data comemorativa que serve de referência para datas comemorativas móveis como Carnaval, Quaresma, Corpus Christ e outras. Por isso é importante saber quando a Páscoa vai ser comemorada. Além de interessante, serve como uma brincadeira para os garotos(as) de programa de plantão que não tem nada para fazer no feriado.</p>
<h4>Cálculo</h4>
<p>No total são três formas de calcular a data da Páscoa. A primeira é recorrendo a uma tabela, a segunda é através ao algorítimo de Gauss para o intervalo de anos que se inicia em 1900 e termina em 2099 e a terceira com o algorítimo de Meeus / Jones / Butcher. Como exemplo, optei pela segunda forma por ter umas condições e por ela ser mais elaborada. Para quem se interessar, os algorítimos serão relacionados no final deste texto.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span><br />
<br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'date'</span><br />
<br />
FIELDS = <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>Carnaval Pascoa Corpus\ Christ<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
ano = <span style="color:#006666;">2009</span> <span style="color:#008000; font-style:italic;">#change me</span><br />
<br />
x = <span style="color:#006666;">24</span><br />
y = <span style="color:#006666;">5</span><br />
<br />
a = ano <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">19</span><br />
b = ano <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">4</span><br />
c = ano <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">7</span><br />
d = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">19</span> <span style="color:#006600; font-weight:bold;">*</span> a <span style="color:#006600; font-weight:bold;">+</span> x<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">30</span><br />
e = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2</span> <span style="color:#006600; font-weight:bold;">*</span> b <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">4</span> <span style="color:#006600; font-weight:bold;">*</span> c <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">6</span> <span style="color:#006600; font-weight:bold;">*</span> d <span style="color:#006600; font-weight:bold;">+</span> y<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">7</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>d <span style="color:#006600; font-weight:bold;">+</span> e <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#008000; font-style:italic;">#april</span><br />
&nbsp; dia = d <span style="color:#006600; font-weight:bold;">+</span> e <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">9</span><br />
&nbsp; mes = <span style="color:#006666;">4</span><br />
<br />
&nbsp; <span style="color:#008000; font-style:italic;">#exceptions &nbsp;</span><br />
&nbsp; dia = <span style="color:#006666;">19</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>dia == <span style="color:#006666;">26</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; dia = <span style="color:#006666;">18</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>dia == <span style="color:#006666;">25</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> d == <span style="color:#006666;">28</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> a <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; <span style="color:#008000; font-style:italic;">#march</span><br />
&nbsp; dia = d <span style="color:#006600; font-weight:bold;">+</span> e <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">22</span><br />
&nbsp; mes = <span style="color:#006666;">3</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
dt = <span style="color:#CC00FF; font-weight:bold;">Date</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>ano, mes, dia<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<br />
result = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> dt <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">47</span><br />
result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> dt<br />
result <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> dt <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">60</span><br />
<br />
FIELDS.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>d<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{d}: #{result.shift.strftime(&quot;</span><span style="color:#006600; font-weight:bold;">%</span>d<span style="color:#006600; font-weight:bold;">-%</span>m<span style="color:#006600; font-weight:bold;">-%</span>Y<span style="color:#996600;">&quot;)}&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Este texto tem uma pegadinha. Na verdade, meu intuito com ele não é ensinar Ruby nem mostrar como se calcula o dia da Páscoa. Foi uma forma que encontrei de mostrar como a linguagem chega perto do idioma, como poucas linguagens o fazem. Qualquer pessoa é capaz de entender as fórmulas matemáticas e relacioná-las com o exemplo mostrado. Sim, existe um açúcar, mas é fácil de entendê-lo também.</p>
<p>A maior parte do tempo, parece que estamos conversando com um editor de textos.</p>
<h4>Referências:</h4>
<ul>
<li><a href="http://pt.wikipedia.org/wiki/P%C3%A1scoa">Páscoa</a></li>
<li><a href="http://pt.wikipedia.org/wiki/C%C3%A1lculo_da_P%C3%A1scoa">Cálculo da Páscoa</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/ruby-calculando-o-dia-da-pascoa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rapidinha: GIF animado com Ruby</title>
		<link>http://carlancalazans.com/rapidinha-gif-animado-com-ruby/</link>
		<comments>http://carlancalazans.com/rapidinha-gif-animado-com-ruby/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 19:50:15 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[rapidinha]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=203</guid>
		<description><![CDATA[A algumas horas atrás estava tentando criar um gif animado para o twitter. Esbarrei com uma solução usando Gimp, sugestão do oráculo. Fiz o gif animado. Alguns minutos depois, o lembrei de uma gem para Ruby chamada RMagick para processamento de imagens. Como nunca a tinha experimentado eis que veio a idéia de escrever uma [...]]]></description>
			<content:encoded><![CDATA[<p>A algumas horas atrás estava tentando criar um gif animado para o <a href="http://twitter.com/carlancalazans">twitter</a>. Esbarrei com uma <a href="http://azulebanana.com/bluey/2007/04/30/simples-faixa-animada-em-gif-com-o-gimp/">solução</a> usando <a href="http://www.gimp.org/">Gimp</a>, sugestão do oráculo. Fiz o gif animado. Alguns minutos depois, o lembrei de uma gem para <a href="http://http://www.ruby-lang.org/">Ruby</a> chamada <a href="http://rmagick.rubyforge.org/">RMagick</a> para processamento de imagens. Como nunca a tinha experimentado eis que veio a idéia de escrever uma classe para criar um gif animado.</p>
<p>A gem RMagick é baseada na biblioteca de imagens <a href="http://www.imagemagick.org/">Image Magick</a> comumente conhecida no mundo Linux pelo poder de seus utilitários em linha de comando. É, linha de comando, sem a necessidade de Gimp, FW, PS e similares. Quem nunca ouviu falar de import ou convert? <img src='http://carlancalazans.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>A classe em questão é a:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'RMagick'</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">include</span> Magick<br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> AnimatedGif<br />
<br />
&nbsp; DELAY = <span style="color:#006666;">100</span><br />
&nbsp; <span style="color:#CC0066; font-weight:bold;">LOOP</span> = <span style="color:#006666;">0</span><br />
&nbsp; <br />
&nbsp; attr_accessor <span style="color:#ff3333; font-weight:bold;">:source</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> save<span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; load_files<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">delay</span> = DELAY<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">iterations</span> = <span style="color:#CC0066; font-weight:bold;">LOOP</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; private<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> load_files<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span> = ImageList.<span style="color:#9900CC;">new</span><br />
&nbsp; &nbsp; <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>source<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">entries</span>.<span style="color:#9900CC;">reject</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> f =~ <span style="color:#006600; font-weight:bold;">/</span>^\.<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">read</span> <span style="color:#996600;">&quot;#{source}/#{f}&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#008000; font-style:italic;">#Usage:</span><br />
gif = AnimatedGif.<span style="color:#9900CC;">new</span><br />
gif.<span style="color:#9900CC;">source</span> = <span style="color:#996600;">'img_src'</span><br />
gif.<span style="color:#9900CC;">save</span> <span style="color:#996600;">'/tmp/animated.gif'</span></div></div>
<p>O delay entre as imagens está fixo no código. O loop é infinito, ou seja, seu gif ficará se repetindo a vida toda. Após criar um objeto da classe AnimatedGif é necessário informar um diretório com imagens estáticas para gerar o gif animado. E por último, é só chamar o método save passando o caminho do arquivo gif final.</p>
<p>Demorou uns dois minutos a mais depois do entendimento da solução em Gimp para gerar esta classe em Ruby. Foram uns 3 minutos para entender a técnica do Gimp e 5 minutos para criar a classe em Ruby. A linguagem não morde!</p>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/rapidinha-gif-animado-com-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Triggers no SQLITE</title>
		<link>http://carlancalazans.com/triggers-no-sqlite/</link>
		<comments>http://carlancalazans.com/triggers-no-sqlite/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 03:24:41 +0000</pubDate>
		<dc:creator>Carlan Calazans</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aprendizado]]></category>
		<category><![CDATA[dev]]></category>
		<category><![CDATA[dica]]></category>
		<category><![CDATA[pesquisa]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[trigger]]></category>

		<guid isPermaLink="false">http://carlancalazans.com/?p=157</guid>
		<description><![CDATA[Esta semana um grande amigo twitou uma pergunta que me chamou atenção. Já tinha estudado sobre o assunto a alguns anos atrás para utilizar em um sistema. Foi dai que veio a idéia para este post, peguei os meus rascunhos e comecei a escrever.
O banco de dados SQLITE, em sua versão atual, não possui suporte [...]]]></description>
			<content:encoded><![CDATA[<p>Esta semana um <a href="http://www.leocabral.com.br">grande</a> <a href="http://twitter.com/lcquadros">amigo</a> <a href="http://twitter.com/lcquadros/status/1275497421">twitou</a> uma pergunta que me chamou atenção. Já tinha estudado sobre o assunto a alguns anos atrás para utilizar em um sistema. Foi dai que veio a idéia para este post, peguei os meus rascunhos e comecei a escrever.</p>
<p>O banco de dados <a href="http://www.sqlite.org">SQLITE</a>, em sua <a href="http://www.sqlite.org/releaselog/3_6_11.html">versão atual</a>, não possui suporte a <a href="http://pt.wikipedia.org/wiki/Integridade_referencial">integridade referencial</a>. Nunca consegui entender o motivo, já que bancos similares como <a href="http://www.h2database.com">h2</a> e <a href="http://hsqldb.org">HSQLDB</a> possuem. Talvez não implementaram a funcionalidade ainda por que existe uma outra alternativa. Uma forma de driblar essa limitação é através de <a href="http://pt.wikipedia.org/wiki/Gatilho_(banco_de_dados)">triggers</a>. Um trigger é disparado quando um evento ocorre. É possível deletar os registros filhos relacionados com uma tabela pai, por exemplo. O evento neste caso, para ficar bem claro, é a remoção de um registro da tabela pai.</p>
<p>A sintaxe básica para a criação de um trigger é:</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> nome_da_trigger<br />
<span style="color: #66cc66;">&#123;</span> BEFORE <span style="color: #66cc66;">|</span> AFTER <span style="color: #66cc66;">|</span> INSTEAD OF <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#123;</span> <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">UPDATE</span> OF <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#125;</span><br />
BEGIN<br />
<span style="color: #66cc66;">&#123;</span> SQL STATEMENT <span style="color: #66cc66;">&#125;</span><br />
END;</div></div>
<p>Para praticar, criei as tabelas abaixo. Se você for preguiçoso como eu, pode baixar o arquivo do banco de dados direto <a href="http://files.carlancalazans.com/sqlite/exemplo.zip">daqui</a>. É um exemplo bem simples, se você já for um expert em banco de dados (ou um dba), nada do que vou mostrar é novidade.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">BEGIN TRANSACTION;<br />
<br />
<span style="color: #808080; font-style: italic;">-- users table</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> users <span style="color: #66cc66;">&#40;</span>id integer <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> login text<span style="color: #66cc66;">,</span> password text<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #808080; font-style: italic;">-- tasks table</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> tasks <span style="color: #66cc66;">&#40;</span>id integer <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> user_id integer<span style="color: #66cc66;">,</span> name text<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #808080; font-style: italic;">-- logs table</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> logs<span style="color: #66cc66;">&#40;</span>id integer <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> event text<span style="color: #66cc66;">,</span> created_at datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #66cc66;">&#40;</span>datetime<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'now'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'localtime'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #808080; font-style: italic;">-- counts table</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> counts<span style="color: #66cc66;">&#40;</span>id integer <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> name text<span style="color: #66cc66;">,</span> value integer<span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #808080; font-style: italic;">-- data</span><br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'admin'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'admin'</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Entender triggers no sqlite'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Aprender a voar'</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;counts&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'users'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;counts&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'tasks'</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
COMMIT;</div></div>
<p>Agora vem a parte interessante. Vejamos como inserir um registro na tabela logs toda vez que um usuário for criado. O trigger é &#8220;colocado&#8221; na tabela users e, toda vez, após ocorrer um insert o trigger é disparado.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">-- after insert user trigger</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> user_insert<br />
after <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ON</span> users<br />
begin<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> logs <span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;New user created&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
end;</div></div>
<p>Faça o teste. Termine de inserir outros usuários e verifique a tabela logs.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'user'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'user'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'test'</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> logs;</div></div>
<p>O trigger acima monitora a operação insert e adiciona um registro em outra tabela. Agora um exemplo que monitora a mesma operação, mas realiza o update em outra tabela.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">-- update users count</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> update_users_count<br />
after <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">ON</span> users<br />
begin<br />
<span style="color: #993333; font-weight: bold;">UPDATE</span> counts <span style="color: #993333; font-weight: bold;">SET</span> value <span style="color: #66cc66;">=</span> value <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;users&quot;</span>;<br />
end;<br />
<br />
<span style="color: #808080; font-style: italic;">-- test again</span><br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'delete'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'me'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;users&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'highlander'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'therecanbeonlyone'</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Para o exemplo de integridade referencial, maiores informações no início do post, o trigger realiza o delete em todos os registros (for each row) relacionados com a tabela pai. Neste exemplo a tabela pai é users e a filha é tasks. A referência feita a old significa o valor atual do iterator no loop.</p>
<div class="codecolorer-container sql vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">-- before delete user trigger</span><br />
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> user_delete<br />
before <span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">ON</span> users<br />
<span style="color: #993333; font-weight: bold;">FOR</span> each row<br />
begin<br />
<span style="color: #993333; font-weight: bold;">DELETE</span> <span style="color: #993333; font-weight: bold;">FROM</span> tasks <span style="color: #993333; font-weight: bold;">WHERE</span> tasks<span style="color: #66cc66;">.</span>user_id<span style="color: #66cc66;">=</span>old<span style="color: #66cc66;">.</span>id;<br />
end;<br />
<br />
<span style="color: #808080; font-style: italic;">-- test</span><br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Ganhar na mega-sena'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Delete me'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Dominar o mundo'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Test task'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Hello world'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Buy new car'</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">&quot;tasks&quot;</span> <span style="color: #993333; font-weight: bold;">VALUES</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Drink more'</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>Delete o usuário de id número 4 e veja o que acontece.</p>
<p>Pra finalizar, recomendo a todos <a href="http://files.carlancalazans.com/sqlite/exemplo.zip">baixar o arquivo de exemplo</a> e fuçar. Esta solução pode não atender a todos, já que para deletar 1000000 registros filhos, dependendo o seu hardware, o processo pode ser custoso. Não tenho um conhecimento tão profundo sobre engines de banco de dados para explicar como seria feito utilizando um banco com suporte a integridade referencial, portanto, leve isso em consideração ao interpretar a afirmação acima.</p>
<p>De qualquer forma, o uso do SQLITE só deve ser feito em protótipos ou em aplicações cujo os dados não são de muita importância. Caso os dados de sua aplicação sejam muito importantes, geralmente são, você deveria procurar outra alternativa.</p>
<p>Enfim, pelo menos, deu pra brincar um pouco.</p>
<p>Referências:<a href="     * http://www.sqlite.org/lang_createtrigger.html  "><br />
</a></p>
<ul>
<li><a href="     * http://www.sqlite.org/lang_createtrigger.html  ">http://www.sqlite.org/lang_createtrigger.html</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://carlancalazans.com/triggers-no-sqlite/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

