<?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>Silveira Neto &#187; tutorial</title>
	<atom:link href="http://silveiraneto.net/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://silveiraneto.net</link>
	<description></description>
	<lastBuildDate>Fri, 09 Mar 2012 04:13:27 +0000</lastBuildDate>
	<language>pt-br</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>what I feel when I see someone using JPG when he should be using a PNG</title>
		<link>http://silveiraneto.net/2011/10/09/what-i-feel-when-i-see-someone-using-jpg-when-he-should-be-using-a-png/</link>
		<comments>http://silveiraneto.net/2011/10/09/what-i-feel-when-i-see-someone-using-jpg-when-he-should-be-using-a-png/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 02:04:20 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[capitão nascimento]]></category>
		<category><![CDATA[gif]]></category>
		<category><![CDATA[JPG]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3936</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2011/10/09/what-i-feel-when-i-see-someone-using-jpg-when-he-should-be-using-a-png/" title="what I feel when I see someone using JPG when he should be using a PNG"></a>Seriously, is that hard? To discovery which file type you have to use for your image just follow these simple instructions in following priority order: Have text? Use PNG. Is a piece of art like a draw, a painting or a webcomic? &#8230;<p class="read-more"><a href="http://silveiraneto.net/2011/10/09/what-i-feel-when-i-see-someone-using-jpg-when-he-should-be-using-a-png/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2011/10/09/what-i-feel-when-i-see-someone-using-jpg-when-he-should-be-using-a-png/" title="what I feel when I see someone using JPG when he should be using a PNG"></a><p style="text-align: center;"><img class="size-full wp-image-3937 aligncenter" title="capitao nascimento tapa na cara" src="http://silveiraneto.net/wp-content/uploads/2011/10/capitao_nascimento_tapa_na_cara.gif" alt="" width="280" height="160" /></p>
<p>Seriously, is that hard?</p>
<p>To discovery which file type you have to use for your image just follow these simple instructions in following priority order:</p>
<ol>
<li>Have text? <strong>Use PNG.</strong></li>
<li>Is a piece of art like a draw, a painting or a webcomic? <strong>Use PNG.</strong></li>
<li>It is&#8230; moving! <strong>Use GIF.</strong></li>
<li>Is a photo? Use <strong>JPG</strong>.</li>
<li>Is not exactly a photo but contains photos (like people. trees and landscapes)? <strong>Use JPG.</strong></li>
<li>Is not a photo, does not contain a photo but I remain concerned about the size of my file despite the breakthrough in telecommunication speeds.<strong> Try PNG with indexed palette and Floyd–Steinberg color dithering.</strong></li>
<li>Nah, man. <strong>Use JPG but with all lower compression or higher quality options you may find.</strong></li>
<li>It&#8217;s nothing listed above! <strong>Sir, your problem is far away from the scope of these instructions.</strong></li>
</ol>
<p>Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2011/10/09/what-i-feel-when-i-see-someone-using-jpg-when-he-should-be-using-a-png/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Inkscape masks</title>
		<link>http://silveiraneto.net/2011/02/19/inkscape-masks/</link>
		<comments>http://silveiraneto.net/2011/02/19/inkscape-masks/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 18:18:18 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[CC-BY-SA]]></category>
		<category><![CDATA[Drawing]]></category>
		<category><![CDATA[Inkscape]]></category>
		<category><![CDATA[mask]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=3656</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2011/02/19/inkscape-masks/" title="Inkscape masks"></a>In Inkscape if you have two filled circles. A big solid red one and a smaller, blurred and pinky one, like this: You can use the mask to trap one inside another to create a light effect. Metaphorically, I drew a &#8230;<p class="read-more"><a href="http://silveiraneto.net/2011/02/19/inkscape-masks/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2011/02/19/inkscape-masks/" title="Inkscape masks"></a><p>In <a href="http://inkscape.org">Inkscape</a> if you have two filled circles. A big solid red one and a smaller, blurred and pinky one, like this:<br />
<img class="size-full wp-image-3657 aligncenter" title="two balls one with blur" src="http://silveiraneto.net/wp-content/uploads/2011/02/two_balls_one_with_blur.png" alt="" width="498" height="396" />You can use the <strong>mask</strong> to trap one inside another to create a light effect.</p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="510" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/8HZ8RqF-xWc?fs=1&amp;hl=pt_BR&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="510" src="http://www.youtube.com/v/8HZ8RqF-xWc?fs=1&amp;hl=pt_BR&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Metaphorically, I drew a mask using the mask effect:</p>
<p style="text-align: center;"><img class="size-full wp-image-3659 aligncenter" title="mask inkscape using mask" src="http://silveiraneto.net/wp-content/uploads/2011/02/mask_inkscape_using_mask.png" alt="" width="500" height="632" /></p>
<p>You can download it here: <a href="http://silveiraneto.net/downloads/mask_inkscape_by_silveiraneto.svg">mask_inkscape_by_silveiraneto.svg</a><br />
As always, you can use or modify it under the <a href="http://creativecommons.org/licenses/by-sa/3.0/us/">Creative Commons Attribution Share-Alike</a> license.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2011/02/19/inkscape-masks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter Bot @rudaufc versão 1</title>
		<link>http://silveiraneto.net/2009/11/09/twitter-bot-rudaufc-versao-1/</link>
		<comments>http://silveiraneto.net/2009/11/09/twitter-bot-rudaufc-versao-1/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 19:54:18 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[português]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[Comida]]></category>
		<category><![CDATA[CRON]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[culinária]]></category>
		<category><![CDATA[CURL]]></category>
		<category><![CDATA[ia]]></category>
		<category><![CDATA[inteligência artificial]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Restaurante Universitário]]></category>
		<category><![CDATA[robô]]></category>
		<category><![CDATA[robot]]></category>
		<category><![CDATA[SH]]></category>
		<category><![CDATA[Shell Script]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[ufc]]></category>
		<category><![CDATA[Universidade Federal do Ceará]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2927</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2009/11/09/twitter-bot-rudaufc-versao-1/" title="Twitter Bot @rudaufc versão 1"></a>Este aqui é um bot bem simples para Twitter. Diariamente, as nove da manhã ele posta qual vai ser o cardápio do RU (Restaurante Universitário) da UFC naquele dia. Assim, quando vai batendo a hora da fome, os alunos podem &#8230;<p class="read-more"><a href="http://silveiraneto.net/2009/11/09/twitter-bot-rudaufc-versao-1/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/11/09/twitter-bot-rudaufc-versao-1/" title="Twitter Bot @rudaufc versão 1"></a><p><center><img src="http://silveiraneto.net/wp-content/uploads/2009/11/robo.jpg" alt="robô" title="robô" width="117" height="227" class="alignnone size-full wp-image-2933" /></center></p>
<p>Este aqui é um bot bem simples para Twitter.</p>
<p>Diariamente, as nove da manhã ele posta qual vai ser o cardápio do RU (<a href="http://www.ufc.br/portal/index.php?option=com_content&#038;task=view&#038;id=6842&#038;Itemid=87">Restaurante Universitário</a>) da <a href="http://www.ufc.br">UFC</a> naquele dia.</p>
<p>Assim, quando vai batendo a hora da fome, os alunos podem entrar no perfil <a href="http://www.twitter.com/rudaufc">@rudaufc</a> e olhar qual vai ser o prato do dia, ou quem está seguindo ele no Twitter pode ter a agradável surpresa de ver todo dia o que vai ser servido hoje.</p>
<p>Aqui está o código fonte do arquivo rudaufc.sh:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># Twitter bot @rudaufc</span>
<span style="color: #007800;">login</span>=<span style="color: #ff0000;">&quot;rudaufc&quot;</span>
<span style="color: #007800;">senha</span>=<span style="color: #ff0000;">&quot;suasenhaaqui&quot;</span>
&nbsp;
<span style="color: #007800;">segunda</span>=<span style="color: #ff0000;">&quot;Picadinho com legumes ou bife na chapa. Salada de macarrão com cenoura. Arroz. Feijão com abóbora e batata doce.&quot;</span>
<span style="color: #007800;">terca</span>=<span style="color: #ff0000;">&quot;Franco guisado ou coxas de frango ao forno . Salada de acelga, cenoura e passas. Arroz. Feijão com abóbora e batata doce.&quot;</span>
<span style="color: #007800;">quarta</span>=<span style="color: #ff0000;">&quot;# Feijoada à moda RU ou bisteca . Salada de repolho branco, cenoura e abacaxi. Arroz. Feijão com abóbora e batata doce&quot;</span>
<span style="color: #007800;">quinta</span>=<span style="color: #ff0000;">&quot;Frango à passarinho ou frango chinês. Salada de Alface, Tomate e Cebola. Arroz. Feijão com abóbora e batata doce.&quot;</span>
<span style="color: #007800;">sexta</span>=<span style="color: #ff0000;">&quot;# Isca ao molho ou maravilha de carne. Salada de acelga com cenoura. Arroz. Feijão com abóbora e batata doce.&quot;</span>
&nbsp;
<span style="color: #007800;">dia</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span><span style="color: #c20cb9; font-weight: bold;">w</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">log</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y-<span style="color: #000000; font-weight: bold;">%</span>m-<span style="color: #000000; font-weight: bold;">%</span>d-<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #ff0000;">&quot;-$$.log&quot;</span>
<span style="color: #007800;">dir</span>=<span style="color: #ff0000;">&quot;/home/silveiraneto/rudaufc&quot;</span>
<span style="color: #007800;">msg</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dia</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
<span style="color: #666666; font-style: italic;">#	&quot;0&quot;) msg=$domingo ;;</span>
	<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">msg</span>=<span style="color: #007800;">$segunda</span> <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">msg</span>=<span style="color: #007800;">$terca</span> <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">msg</span>=<span style="color: #007800;">$quarta</span> <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #ff0000;">&quot;4&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">msg</span>=<span style="color: #007800;">$quinta</span> <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">msg</span>=<span style="color: #007800;">$sexta</span> <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #666666; font-style: italic;">#	&quot;6&quot;) msg=$sabado ;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
curl <span style="color: #660033;">-u</span> <span style="color: #007800;">$login</span>:<span style="color: #007800;">$senha</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">status</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$msg</span>&quot;</span> http:<span style="color: #000000; font-weight: bold;">//</span>twitter.com<span style="color: #000000; font-weight: bold;">/</span>statuses<span style="color: #000000; font-weight: bold;">/</span>update.xml <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$dir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$log</span></pre></div></div>

<p>A mágica toda está na capacidade do <a href="http://en.wikipedia.org/wiki/CURL">Curl</a> de acessar facilmente a <a href="http://apiwiki.twitter.com/">API do Twitter</a> para enviar mensagens.</p>
<p>Para que o script execute diariamente as nove da manhã ele está alocado em um servidor com a <a href="http://pt.wikipedia.org/wiki/Crontab">crontab</a> configurada da seguinte maneira:</p>
<pre>
0 5 * * *  . /caminho_para_onde_ele_esta/rudaufc.sh
</pre>
<p><small>ps: leve em conta que o servidor está em um fuso horário diferente do Brasil.</small></p>
<p>Nessa versão o prato de cada dia está hardcoded no script, o que não é o ideal e faz com que semanalmente eu tenha que atualizar o script inserindo os pratos da semana manualmente. Eu espero que a próxima versão seja capaz de descobrir esses pratos e se atualizar sem nenhuma interferência.</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/11/09/twitter-bot-rudaufc-versao-1/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>BumbaBot-1</title>
		<link>http://silveiraneto.net/2009/03/16/bumbabot-1/</link>
		<comments>http://silveiraneto.net/2009/03/16/bumbabot-1/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 03:43:42 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[boi bumbá]]></category>
		<category><![CDATA[bumba meu boi]]></category>
		<category><![CDATA[bumbabot-1]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[High-Current Darlington Transistor Arrays]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Hardware]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[roboitcs]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ULN2003A]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=2384</guid>
		<description><![CDATA[ <p class="read-more"><a href="http://silveiraneto.net/2009/03/16/bumbabot-1/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2009/03/16/bumbabot-1/" title="BumbaBot-1"></a><p>I got a simple motor from a broken domestic printer. It&#8217;s a <a title="Mitsumi product" href="http://www.mitsumi.co.jp/Catalog/compo/motor/m35sp9_e.html">Mitsumi m355P-9T stepping motor</a>. Any other common stepping motor should fits. You can find one in printers, multifunction machines, copy machines, FAX, and such.</p>
<p style="text-align: center;"><a title="bumbabot v01 by Silveira Neto, on Flickr" href="http://www.flickr.com/photos/silveiraneto/3358845802/"><img class="aligncenter" src="http://farm4.static.flickr.com/3460/3358845802_286e74ee01.jpg" alt="bumbabot v01" width="500" height="375" /></a></p>
<p>With a flexible cap of water bottle with a hole we make a connection between the motor axis and other objects.</p>
<p style="text-align: center;"><a title="bumbabot v01 by Silveira Neto, on Flickr" href="http://www.flickr.com/photos/silveiraneto/3358029549/"><img class="aligncenter" src="http://farm4.static.flickr.com/3571/3358029549_0b9680180a.jpg" alt="bumbabot v01" width="500" height="375" /></a></p>
<p style="text-align: center;"><a title="bumbabot v01 by Silveira Neto, on Flickr" href="http://www.flickr.com/photos/silveiraneto/3358031295/"><img class="aligncenter" src="http://farm4.static.flickr.com/3582/3358031295_fb8ed598cc.jpg" alt="bumbabot v01" width="500" height="375" /></a></p>
<p>With super glue I attached to the cap a little handcraft clay ox statue.</p>
<p style="text-align: center;"><a title="bumbabot v01 by Silveira Neto, on Flickr" href="http://www.flickr.com/photos/silveiraneto/3358032255/"><img class="aligncenter" src="http://farm4.static.flickr.com/3612/3358032255_3686d7e295.jpg" alt="bumbabot v01" width="500" height="375" /></a></p>
<p>It&#8217;s a representation from a Brazilian folkloric character <a title="Wikipedia, english" href="http://en.wikipedia.org/wiki/Bumba_Meu_Boi">Boi Bumbá</a>. In some traditional parties in Brazil, someone dress a structure-costume and dances in circular patterns interacting with the public.</p>
<p style="text-align: center;"><a href="http://www.flickr.com/photos/canoafurada/776513346/"><img class="size-full wp-image-2392 aligncenter" title="776513346_c31db6843b_m" src="http://silveiraneto.net/wp-content/uploads/2009/03/776513346_c31db6843b_m.jpg" alt="776513346_c31db6843b_m" width="198" height="240" /></a></p>
<p style="text-align: center;"><a href="http://www.flickr.com/photos/canoafurada/2246467684/"><img class="size-full wp-image-2393 aligncenter" title="2246467684_49164d3397_m" src="http://silveiraneto.net/wp-content/uploads/2009/03/2246467684_49164d3397_m.jpg" alt="2246467684_49164d3397_m" width="240" height="160" /></a><br />
<small>Photos by <a href="http://www.flickr.com/people/canoafurada/">Marcus Guimarães</a>.</small></p>
<p>Controlling a stepper motor is not difficult.  There&#8217;s a good documentation on how to that on the <a title="Arduino Docs" href="http://www.arduino.cc/en/Tutorial/StepperUnipolar">Arduino Stepper Motor Tutorial</a>. Basically it&#8217;s about sending a logical signal for each coil in a circular order (that is also called full step).</p>
<p style="text-align: center;"><img class="size-full wp-image-2403 aligncenter" title="full step" src="http://silveiraneto.net/wp-content/uploads/2009/03/animacompleto1.gif" alt="full step" width="97" height="97" /></p>
<p style="text-align: center;"><small>Animation from <a href="http://www.rogercom.com/pparalela/IntroMotorPasso.htm">rogercom.com</a>.</small></p>
<p style="text-align: center;"><img class="size-full wp-image-2400 aligncenter" title="stepper motor diagram" src="http://silveiraneto.net/wp-content/uploads/2009/03/stepper_motor_diagram.png" alt="stepper motor diagram" width="348" height="265" /></p>
<p>You&#8217;ll probably also use a driver chip ULN2003A or similar to give to the motor more current than your Arduino can provide and also for protecting it from a power comming back from the motor. It&#8217;s a very easy find this tiny chip on electronics or automotive  stores or also from broken printers where you probably found your stepped motor.</p>
<p style="text-align: center;"><img class="size-full wp-image-2404 aligncenter" title="Arduino Stepper Motor UNL2003A" src="http://silveiraneto.net/wp-content/uploads/2009/03/arduino_stepper_motor_uln2003a.jpg" alt="Arduino Stepper Motor UNL2003A" width="400" height="514" /></p>
<p>With a simple program you can already controlling your motor.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Simple stepped motor spin</span>
<span style="color: #666666; font-style: italic;">// by Silveira Neto, 2009, under GPLv3 license</span>
<span style="color: #666666; font-style: italic;">// http://silveiraneto.net/2009/03/16/bumbabot-1/</span>
<span style="color: #993333;">int</span> coil1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> coil2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> coil3 <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> coil4 <span style="color: #339933;">=</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> step <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> interval <span style="color: #339933;">=</span> <span style="color: #0000dd;">100</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  pinMode<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> step<span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> step<span style="color: #339933;">==</span><span style="color: #0000dd;">1</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> step<span style="color: #339933;">==</span><span style="color: #0000dd;">2</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> step<span style="color: #339933;">==</span><span style="color: #0000dd;">3</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span>interval<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  step <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>step<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span><span style="color:#800080;">4</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p style="text-align: center;"><object width="425" height="344" data="http://www.youtube.com/v/roq9z3tpEhI&amp;hl=pt-br&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/roq9z3tpEhI&amp;hl=pt-br&amp;fs=1" /><param name="allowfullscreen" value="true" /></object><br />
Writing a little bit more generally code we can create function to step forward and step backward.</p>
<p>My motor needs 48 steps to run a complete turn. So 360º/48 steps give us 7,5º per step. Arduino has a simple <a title="Arduino Reference" href="http://www.arduino.cc/en/Reference/Stepper">Stepper Motor Library</a> but it doesn&#8217;t worked with me and it&#8217;s also oriented to steps and I&#8217;d need something oriented to angles instead. So I wrote some routines to do that.</p>
<p>For this first version of BumbaBot I mapped angles with letters to easy the communication between the programs.</p>
<p style="text-align: center;"><img class="alignnone size-full wp-image-2411" title="motor angle step control" src="http://silveiraneto.net/wp-content/uploads/2009/03/motor_angle_control_map.png" alt="motor angle step control" width="300" height="236" /></p>
<p>Notice that <strong>it&#8217;s not the final version and there&#8217;s still some bugs!</strong></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Stepped motor control by letters</span>
<span style="color: #666666; font-style: italic;">// by Silveira Neto, 2009, under GPLv3 license</span>
<span style="color: #666666; font-style: italic;">// http://silveiraneto.net/2009/03/16/bumbabot-1/</span>
&nbsp;
<span style="color: #993333;">int</span> coil1 <span style="color: #339933;">=</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> coil2 <span style="color: #339933;">=</span> <span style="color: #0000dd;">9</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> coil3 <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> coil4 <span style="color: #339933;">=</span> <span style="color: #0000dd;">11</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> delayTime <span style="color: #339933;">=</span> <span style="color: #0000dd;">50</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> steps <span style="color: #339933;">=</span> <span style="color: #0000dd;">48</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> step_counter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  pinMode<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  pinMode<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> OUTPUT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// tells motor to move a certain angle</span>
<span style="color: #993333;">void</span> moveAngle<span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span> angle<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
  <span style="color: #993333;">int</span> howmanysteps <span style="color: #339933;">=</span> angle<span style="color: #339933;">/</span>stepAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>howmanysteps<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    howmanysteps <span style="color: #339933;">=</span> <span style="color: #339933;">-</span> howmanysteps<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>angle<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>howmanysteps<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      step<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span><span style="color:#800080;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      delay<span style="color: #009900;">&#40;</span>delayTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>howmanysteps<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      backstep<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span><span style="color:#800080;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      delay<span style="color: #009900;">&#40;</span>delayTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// tells motor to move to a certain angle</span>
<span style="color: #993333;">void</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #993333;">float</span> angle<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  moveAngle<span style="color: #009900;">&#40;</span>angle<span style="color: #339933;">-</span>actualAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// actual stepper motor angle</span>
<span style="color: #993333;">float</span> actualAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> step_counter<span style="color: #339933;">*</span>stepAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// angle made by each step</span>
<span style="color: #993333;">float</span> stepAngle<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color:#800080;">360.0</span><span style="color: #339933;">/</span>steps<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// backward step</span>
<span style="color: #993333;">void</span> backstep<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> coil<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  step_counter<span style="color: #339933;">--;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// forward step</span>
<span style="color: #993333;">void</span> step<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> coil<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil1<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil2<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil3<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  digitalWrite<span style="color: #009900;">&#40;</span>coil4<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>coil<span style="color: #339933;">==</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>HIGH<span style="color: #339933;">:</span>LOW<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  step_counter<span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  byte val<span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>Serial.<span style="color: #202020;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    val <span style="color: #339933;">=</span> Serial.<span style="color: #202020;">read</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'A'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span>  <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'B'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">45</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'C'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span> <span style="color: #0000dd;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'D'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">135</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'E'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">180</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'F'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">225</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'G'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">270</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'H'</span><span style="color: #339933;">:</span> moveToAngle<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">315</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'I'</span><span style="color: #339933;">:</span> backstep<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> backstep<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'J'</span><span style="color: #339933;">:</span> step<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> step<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In another post I wrote <a title="Arduino and Java" href="http://silveiraneto.net/2009/03/01/arduino-and-java/">how create a Java program to talk with Arduino</a>. We&#8217;ll use this to send messages to Arduino to it moves. </p>
<p style="text-align: center;"><img src="http://silveiraneto.net/wp-content/uploads/2009/03/captura_de_tela-bumba01-netbeans-ide-65-500x283.png" alt="captura_de_tela-bumba01-netbeans-ide-65" title="captura_de_tela-bumba01-netbeans-ide-65" width="500" height="283" class="alignnone size-medium wp-image-2416" /></p>
<p>[put final video here]</p>
<p><strong>To be continued&#8230; </strong>:)</p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2009/03/16/bumbabot-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaFX, how to create a rpg like game</title>
		<link>http://silveiraneto.net/2008/12/08/javafx-how-to-create-a-rpg-like-game/</link>
		<comments>http://silveiraneto.net/2008/12/08/javafx-how-to-create-a-rpg-like-game/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 07:38:04 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[applet]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Web Start]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[ogv]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1861</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2008/12/08/javafx-how-to-create-a-rpg-like-game/" title="JavaFX, how to create a rpg like game"></a>JavaFX 1.0 is out and there are tons of new cool features, specially for game development.trans I&#8217;ll show in this tutorial how to create a very simple demo that shows how to load imtrages, handle sprites, collisions and keyboard events &#8230;<p class="read-more"><a href="http://silveiraneto.net/2008/12/08/javafx-how-to-create-a-rpg-like-game/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2008/12/08/javafx-how-to-create-a-rpg-like-game/" title="JavaFX, how to create a rpg like game"></a><p><a href="http://javafx.com">JavaFX 1.0</a> is out and there are tons of new cool features, specially for game development.trans</p>
<p>I&#8217;ll show in this tutorial how to create a very simple demo that shows how to load imtrages, handle sprites, collisions and keyboard events that you can use to create a game with a old school rpg like vision.</p>
<p>For the background scenario I&#8217;m using the house <a title="My Free Tileset version 2" href="http://silveiraneto.net/2008/08/31/my-free-tileset-version-2/">that I drew</a> and we&#8217;ll call as <strong>house.png</strong>.</p>
<p style="text-align: center;"><a title="Pixelart home" href="http://silveiraneto.net/wp-content/uploads/2008/08/silveira_neto_gpl_pixelart_kitchen_home1.png"><img class="size-full wp-image-1190 aligncenter" title="House pixelart free GPL" src="../wp-content/uploads/2008/08/silveira_neto_gpl_pixelart_kitchen_home1.png" alt="" width="416" height="384" /></a></p>
<p>That we load as a <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.scene.image/javafx.scene.image.Image.html">Image</a> and place into a <a title="JavaFX API" href="http://java.sun.com/javafx/1/docs/api/javafx.scene.image/javafx.scene.image.ImageView.html">ImageView</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ImageView<span style="color: #009900;">&#123;</span>
   image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}house.png&quot;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For the character I&#8217;m using the last character I drew, <a title="The Nerdy Guy" href="http://silveiraneto.net/2008/12/07/nerdy-guy-my-free-charset-version-2/">the nerdy guy</a>.</p>
<p style="text-align: center;"><img class="size-full wp-image-1863 aligncenter" title="nerdyguy creative commons att share alike" src="../wp-content/uploads/2008/12/nerdyguy_from_silveiranetonet_creativecommons_att_share_alike.png" alt="" width="101" height="183" /></p>
<p>To make the animation easier, I spited it into 9 pieces:</p>
<p><strong>down0.png</strong>, <strong>down1.png</strong> and <strong>down2.png</strong></p>
<p><a href="http://silveiraneto.net/wp-content/uploads/2008/12/down0.png"><img class="alignnone size-full wp-image-1867" title="down0" src="http://silveiraneto.net/wp-content/uploads/2008/12/down0.png" alt="" width="30" height="39" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/down1.png"><img class="alignnone size-full wp-image-1868" title="down1" src="http://silveiraneto.net/wp-content/uploads/2008/12/down1.png" alt="" width="30" height="39" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/down2.png"><img class="alignnone size-full wp-image-1869" title="down2" src="http://silveiraneto.net/wp-content/uploads/2008/12/down2.png" alt="" width="30" height="39" /></a></p>
<p><strong>left0.png</strong>, <strong>left1.png</strong> and <strong>left2.png</strong></p>
<p><a href="http://silveiraneto.net/wp-content/uploads/2008/12/left0.png"><img class="alignnone size-full wp-image-1874" title="left0" src="http://silveiraneto.net/wp-content/uploads/2008/12/left0.png" alt="" width="30" height="39" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/left1.png"><img class="alignnone size-full wp-image-1875" title="left1" src="http://silveiraneto.net/wp-content/uploads/2008/12/left1.png" alt="" width="30" height="39" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/left2.png"><img class="alignnone size-full wp-image-1876" title="left2" src="http://silveiraneto.net/wp-content/uploads/2008/12/left2.png" alt="" width="30" height="39" /></a></p>
<p><strong>right0.png</strong>, <strong>right1.png</strong> and <strong>righ2.png</strong></p>
<p><a href="http://silveiraneto.net/wp-content/uploads/2008/12/right0.png"><img class="alignnone size-full wp-image-1872" title="right0" src="http://silveiraneto.net/wp-content/uploads/2008/12/right0.png" alt="" width="30" height="40" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/right1.png"><img class="alignnone size-full wp-image-1873" title="right1" src="http://silveiraneto.net/wp-content/uploads/2008/12/right1.png" alt="" width="30" height="40" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/right2.png"><img class="alignnone size-medium wp-image-1872" title="right2" src="http://silveiraneto.net/wp-content/uploads/2008/12/right2.png" alt="" width="30" height="40" /></a></p>
<p><strong>up0.png</strong>,<strong> up1.png </strong>and <strong>up2.png</strong></p>
<p><a href="http://silveiraneto.net/wp-content/uploads/2008/12/up0.png"><img class="alignnone size-full wp-image-1877" title="up0" src="http://silveiraneto.net/wp-content/uploads/2008/12/up0.png" alt="" width="30" height="40" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/up1.png"><img class="alignnone size-full wp-image-1878" title="up1" src="http://silveiraneto.net/wp-content/uploads/2008/12/up1.png" alt="" width="30" height="40" /></a> <a href="http://silveiraneto.net/wp-content/uploads/2008/12/up2.png"><img class="alignnone size-full wp-image-1879" title="up2" src="http://silveiraneto.net/wp-content/uploads/2008/12/up2.png" alt="" width="30" height="40" /></a></p>
<blockquote><p><img class="alignnone size-full wp-image-1881" title="warning" src="http://silveiraneto.net/wp-content/uploads/2008/12/dialog-warning.png" alt="" width="16" height="16" /> All images I&#8217;m using should be in the same directory of source code.</p></blockquote>
<p>Let&#8217;s start loading the scenario and a single character sprite.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.Scene</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.*</span><span style="color: #339933;">;</span>
&nbsp;
Stage <span style="color: #009900;">&#123;</span>
   title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;RPG-like demo&quot;</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">424</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">412</span>
   visible<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
   scene<span style="color: #339933;">:</span> Scene<span style="color: #009900;">&#123;</span>
      content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
         ImageView<span style="color: #009900;">&#123;</span>
         image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}house.png&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>,
         ImageView<span style="color: #009900;">&#123;</span>
            x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">80</span>
            image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}down1.png&quot;</span><span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#93;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Saved as Game.fx you can compile and run with in your terminal:</p>
<blockquote><p>$ javafxc Game.fx</p>
<p>$ javafx Game</p></blockquote>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2008/12/screenshot1.png"><img class="size-full wp-image-1883 aligncenter" title="javafx rpg like game demo" src="http://silveiraneto.net/wp-content/uploads/2008/12/screenshot1.png" alt="" width="451" height="433" /></a></p>
<blockquote><p><img class="alignnone size-full wp-image-1881" title="warning" src="http://silveiraneto.net/wp-content/uploads/2008/12/dialog-warning.png" alt="" width="16" height="16" /> <strong>Hint:</strong> You can use <a title="JavaFX Downloads" href="http://javafx.com/downloads">NetBeans 6.5 JavaFX plugin</a> to easier the JavaFX development.</p></blockquote>
<p>To put animation on the character we load all sprites into four lists. Each list for each direction.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// sprites</span>
def up    <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}up{i}.png&quot;</span>    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def right <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}right{i}.png&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def down  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}down{i}.png&quot;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def left  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}left{i}.png&quot;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>And create vars to store the character position and frame of animation.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">var frame <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
var posx <span style="color: #339933;">=</span> <span style="color: #cc66cc;">320</span><span style="color: #339933;">;</span>
var posy <span style="color: #339933;">=</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span></pre></div></div>

<p>Also store the house background.</p>
<pre>// house background
def house = ImageView{ image: Image {url: "{__DIR__}house.png"} };</pre>
<p>I create booleans to store some key states and at each interval of time I see how they are and do something about. You can handle keyboard event with less code but I like this way because keep visual and game logics a little bit more separated.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// keyboard</span>
var    upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
var rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
var  downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
var  leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// player</span>
var player <span style="color: #339933;">=</span> ImageView<span style="color: #009900;">&#123;</span>
   x<span style="color: #339933;">:</span> bind posx y<span style="color: #339933;">:</span> bind posy
   image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}down1.png&quot;</span><span style="color: #009900;">&#125;</span>
   onKeyPressed<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">KeyEvent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_DOWN</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_UP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_LEFT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_RIGHT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// onKeyPressed</span>
&nbsp;
   onKeyReleased<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span> <span style="color: #003399;">KeyEvent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_DOWN</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_UP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_LEFT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_RIGHT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// onKeyReleased</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>See a video of the game working so far:</p>
<p style="text-align: center;"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/Xv5z-9LGuOc&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Xv5z-9LGuOc&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></p>
<p>Now we will add collisions. In a <a href="http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/">previous post</a> I showed some math behind bounding box game collisions. The good news are that you no longer need to worry about that. There are a lot of API improvements in JavaFX 1.0 that do all the hard work for you, specially the new classes on javafx.geometry package, <a href="http://java.sun.com/javafx/1/docs/api/javafx.geometry/javafx.geometry.Rectangle2D.html">Rectangle2D</a> and <a href="http://java.sun.com/javafx/1/docs/api/javafx.geometry/javafx.geometry.Point2D.html">Point2D</a>.</p>
<p>We create rectangles that represent the obstacles in the house.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// collidable obstacles</span>
def obstacles <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> y<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">382</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> y<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">414</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">384</span> y<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">382</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">224</span> y<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">96</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">224</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">96</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">255</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">170</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">257</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">295</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">60</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">327</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">23</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p style="text-align: center;"><img class="size-full wp-image-1887 aligncenter" title="bounding boxes" src="http://silveiraneto.net/wp-content/uploads/2008/12/boundingboxes.png" alt="" width="416" height="384" /></p>
<p>We just have to change a little bit the game logics in order to handle collisions.</p>
<p style="text-align: center;"><img class="size-full wp-image-1889 aligncenter" title="boudingbox" src="http://silveiraneto.net/wp-content/uploads/2008/12/boudingbox.png" alt="" width="200" height="260" /></p>
<p>We define a bounding box around the player, it&#8217;s a rectangle from (4, 25) at the player coordinates system and with width 19 and height 10. The idea is to prospect where the player will be in the next step, see if it&#8217;s bouding box don&#8217;t collide with any obstacle and so pass it to the real game position.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// game logics</span>
var gamelogics <span style="color: #339933;">=</span> Timeline <span style="color: #009900;">&#123;</span>
   repeatCount<span style="color: #339933;">:</span> Timeline.<span style="color: #006633;">INDEFINITE</span>
   keyFrames<span style="color: #339933;">:</span> KeyFrame <span style="color: #009900;">&#123;</span>
      time <span style="color: #339933;">:</span> 1s<span style="color: #339933;">/</span><span style="color: #cc66cc;">8</span>
      action<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         var nextposx <span style="color: #339933;">=</span> posx<span style="color: #339933;">;</span>
         var nextposy <span style="color: #339933;">=</span> posy<span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>downkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposy <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> down<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>upkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposy <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> up<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rightkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposx <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> right<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>leftkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposx <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> left<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>obst in obstacles<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>obst.<span style="color: #006633;">boundsInLocal</span>.<span style="color: #006633;">intersects</span><span style="color: #009900;">&#40;</span>nextposx <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span>, nextposy <span style="color: #339933;">+</span> <span style="color: #cc66cc;">25</span>, <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
         posx <span style="color: #339933;">=</span> nextposx<span style="color: #339933;">;</span>
         posy <span style="color: #339933;">=</span> nextposy<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is enough to do the trick but I also added a way to smoothly show the obstacles when pressing the space key.</p>
<p style="text-align: center;"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/k-MHh6irvwE&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/k-MHh6irvwE&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></p>
<p>Here is the complete source code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">Game</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.stage.Stage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.image.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.input.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.paint.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.shape.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.animation.*</span><span style="color: #339933;">;</span>
&nbsp;
var frame <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
var posx <span style="color: #339933;">=</span> <span style="color: #cc66cc;">320</span><span style="color: #339933;">;</span>
var posy <span style="color: #339933;">=</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// sprites</span>
def up    <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}up{i}.png&quot;</span>    <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def right <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}right{i}.png&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def down  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}down{i}.png&quot;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
def left  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i in <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span>..<span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}left{i}.png&quot;</span>  <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// house background</span>
def house <span style="color: #339933;">=</span> ImageView<span style="color: #009900;">&#123;</span> image<span style="color: #339933;">:</span> <span style="color: #003399;">Image</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;{__DIR__}house.png&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// keyboard</span>
var    upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
var rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
var  downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
var  leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// player</span>
var player <span style="color: #339933;">=</span> ImageView<span style="color: #009900;">&#123;</span>
   x<span style="color: #339933;">:</span> bind posx y<span style="color: #339933;">:</span> bind posy image<span style="color: #339933;">:</span> down<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>
   onKeyPressed<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">KeyEvent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_DOWN</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_UP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_LEFT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_RIGHT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_SPACE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fade<span style="color: #339933;">==</span><span style="color: #cc66cc;">0.0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         	fadein.<span style="color: #006633;">playFromStart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fade<span style="color: #339933;">==</span><span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				fadeout.<span style="color: #006633;">playFromStart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// onKeyPressed</span>
&nbsp;
   onKeyReleased<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span> <span style="color: #003399;">KeyEvent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_DOWN</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         downkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_UP</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         upkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_LEFT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         leftkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">code</span> <span style="color: #339933;">==</span> KeyCode.<span style="color: #006633;">VK_RIGHT</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         rightkey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// onKeyReleased</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// collidable obstacles</span>
def obstacles <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> y<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">382</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> y<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">414</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">384</span> y<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">382</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">224</span> y<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">96</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">224</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> width<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">96</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">128</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">64</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">255</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">200</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">170</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">257</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">288</span> y<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">320</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">192</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">352</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">295</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">32</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">60</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
	<span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span>  <span style="color: #cc66cc;">32</span> y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">327</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">64</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">23</span> stroke<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">YELLOW</span> <span style="color: #009900;">&#125;</span>,
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// game logics</span>
var gamelogics <span style="color: #339933;">=</span> Timeline <span style="color: #009900;">&#123;</span>
   repeatCount<span style="color: #339933;">:</span> Timeline.<span style="color: #006633;">INDEFINITE</span>
   keyFrames<span style="color: #339933;">:</span> KeyFrame <span style="color: #009900;">&#123;</span>
      time <span style="color: #339933;">:</span> 1s<span style="color: #339933;">/</span><span style="color: #cc66cc;">8</span>
      action<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         var nextposx <span style="color: #339933;">=</span> posx<span style="color: #339933;">;</span>
         var nextposy <span style="color: #339933;">=</span> posy<span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>downkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposy <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> down<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>upkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposy <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> up<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rightkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposx <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> right<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>leftkey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            nextposx <span style="color: #339933;">-=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
            player.<span style="color: #006633;">image</span> <span style="color: #339933;">=</span> left<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>frame mod <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>obst in obstacles<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>obst.<span style="color: #006633;">boundsInLocal</span>.<span style="color: #006633;">intersects</span><span style="color: #009900;">&#40;</span>nextposx <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span>, nextposy <span style="color: #339933;">+</span> <span style="color: #cc66cc;">25</span>, <span style="color: #cc66cc;">19</span>, <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
         posx <span style="color: #339933;">=</span> nextposx<span style="color: #339933;">;</span>
         posy <span style="color: #339933;">=</span> nextposy<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
gamelogics.<span style="color: #006633;">play</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// obstacles view</span>
var fade <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span><span style="color: #339933;">;</span>
&nbsp;
var obstacleslayer <span style="color: #339933;">=</span> <span style="color: #003399;">Group</span> <span style="color: #009900;">&#123;</span>
   opacity<span style="color: #339933;">:</span> bind fade
   content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
      <span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span><span style="color: #cc66cc;">0</span> y<span style="color: #339933;">:</span><span style="color: #cc66cc;">0</span> width<span style="color: #339933;">:</span><span style="color: #cc66cc;">500</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">500</span> fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span> <span style="color: #009900;">&#125;</span>,
      obstacles,
      <span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span>
        x<span style="color: #339933;">:</span> bind posx <span style="color: #339933;">+</span> <span style="color: #cc66cc;">4</span> y<span style="color: #339933;">:</span> bind posy <span style="color: #339933;">+</span> <span style="color: #cc66cc;">25</span> width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">19</span> height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span>
        fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">LIME</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var fadein <span style="color: #339933;">=</span> Timeline <span style="color: #009900;">&#123;</span>
	keyFrames<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
   	at <span style="color: #009900;">&#40;</span>0s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>fade <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0.0</span><span style="color: #009900;">&#125;</span>
   	at <span style="color: #009900;">&#40;</span>1s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>fade <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var fadeout <span style="color: #339933;">=</span> Timeline <span style="color: #009900;">&#123;</span>
	keyFrames<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
   	at <span style="color: #009900;">&#40;</span>0s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>fade <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1.0</span><span style="color: #009900;">&#125;</span>
   	at <span style="color: #009900;">&#40;</span>1s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>fade <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0.0</span><span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// game stage</span>
Stage <span style="color: #009900;">&#123;</span>
	title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;RPG-like demo&quot;</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">424</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">412</span>
	visible<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
	scene<span style="color: #339933;">:</span> Scene<span style="color: #009900;">&#123;</span>
      fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span>
		content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>house, player, obstacleslayer<span style="color: #009900;">&#93;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Play Through Java Web Start<br />
</strong></p>
<p style="text-align: center;"><a title="Click to launch" href="http://silveiraneto.net/downloads/nerdy/dist/Nerdy.jnlp"><img class="size-full wp-image-1474 aligncenter" title="webstart" src="../wp-content/uploads/2008/10/webstart.png" alt="" width="88" height="23" /></a></p>
<p>or <a title="Applet Game" href="http://silveiraneto.net/downloads/nerdy/dist/Nerdy.html">click here to play via applet</a>, inside your browser.</p>
<p><small><strong>update: </strong>The applet version and Java Web Start versions should be working now.  The applet version on Linux seems to be having problems with the keyboard handling, use the Java Web Start version while I&#8217;m trying to fix it.</small></p>
<p><strong>Downloads:</strong></p>
<ul>
<li>Source, images and jars, <a title="Zipball with sources and images" href="http://silveiraneto.net/downloads/nerdy.zip">nerdy.zip</a></li>
<li><a title="Nerdy Game" href="http://silveiraneto.net/downloads/nerdy/">All content</a></li>
<li>First video, <a title="OGG Video" href="http://silveiraneto.net/downloads/javafx_nerdy_without_collision.ogv">javafx_nerdy_without_collision.ogv</a></li>
<li>Second video, <a title="OGG Video" href="http://silveiraneto.net/downloads/javafx_nerdy.ogv">javafx_nerdy.ogv</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/12/08/javafx-how-to-create-a-rpg-like-game/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>JavaFX SDK 1.0 on Linux</title>
		<link>http://silveiraneto.net/2008/12/06/javafx-sdk-10-on-linux/</link>
		<comments>http://silveiraneto.net/2008/12/06/javafx-sdk-10-on-linux/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 07:15:35 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unofficial]]></category>
		<category><![CDATA[vídeo]]></category>
		<category><![CDATA[Weiqi Gao]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1853</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2008/12/06/javafx-sdk-10-on-linux/" title="JavaFX SDK 1.0 on Linux"></a>JavaFX 1.0 is out and is absolutely amazing. You guys did really a great work on it. As I really need a working SDK on Linux to continue to study and I don&#8217;t have any Windows/Mac near me, I&#8217;m using &#8230;<p class="read-more"><a href="http://silveiraneto.net/2008/12/06/javafx-sdk-10-on-linux/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2008/12/06/javafx-sdk-10-on-linux/" title="JavaFX SDK 1.0 on Linux"></a><p><a href="http://javafx.com">JavaFX 1.0</a> is out and is absolutely amazing. You guys did really a great work on it.</p>
<p style="text-align: center;"><a title="JavaFX Site" href="http://javafx.com"><img class="size-full wp-image-1854 aligncenter" title="javafx site" src="http://silveiraneto.net/wp-content/uploads/2008/12/javafxsite.png" alt="" width="400" height="311" /></a></p>
<p>As I really need a working SDK on Linux to continue to study and I don&#8217;t have any Windows/Mac near me, I&#8217;m using the <a title="Weiqigao Blog" href="http://www.weiqigao.com/blog/2008/08/05/watch_javafx_sdk_run_on_linux.html">Weiqi Gao&#8217;s workaround</a>. I tried to simplify a little bit more the process for those who need JavaFX SDK working on Linux right now.</p>
<p><strong>Download</strong> <a title="JavaFX for Linux" href="http://silveiraneto.net/downloads/javafxsdk_linux_unofficial.tar.bz2">javafxsdk_linux_unofficial.tar.bz2</a> (~18Mb).</p>
<p>And then</p>
<blockquote><p>tar -xjvf javafxsdk_linux_unofficial.tar.bz2<br />
sudo cp javafx /opt/javafx<br />
echo &#8220;PATH=\$PATH:/opt/javafx/bin&#8221; &gt;&gt; ~/.profile<br />
echo &#8220;JAVAFX_HOME=/opt/javafx&#8221; &gt;&gt; ~/.profile<br />
source ~/.profile</p></blockquote>
<p>Now you can call javafx, javafxc, javafxdoc and javafxpackager from your terminal. Don&#8217;t forget that you need Java 1.6 or greater installed.</p>
<p>Here&#8217;s a video showing the SDK working, I&#8217;m compiling and running two sample applications. Remeber that as a temporary unofficial port for Linux, there&#8217;s not native video support nor hardware acceleration.</p>
<p style="text-align: center;"><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ENf5mXEIiD8&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ENf5mXEIiD8&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/12/06/javafx-sdk-10-on-linux/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>JavaFX, rectangular collision detection</title>
		<link>http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/</link>
		<comments>http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 15:26:36 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[jfx]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[openjfx]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rectangle collision]]></category>
		<category><![CDATA[rectangular collision]]></category>
		<category><![CDATA[rectangular collision detection]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1629</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/" title="JavaFX, rectangular collision detection"></a>In a game I wrote some years ago we handled simple rectangular collisions. Given the points: We did: // returning 0 means collision int collision&#40;int ax, int ay, int bx, int by, int cx, int cy, int dx, int dy&#41;&#123; &#8230;<p class="read-more"><a href="http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/" title="JavaFX, rectangular collision detection"></a><p><center><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/NRwRTHPGg6M&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/NRwRTHPGg6M&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object></center></p>
<p>In <a title="Batalhão" href="http://batalhao.codigolivre.org.br/">a game</a> I wrote some years ago we handled simple rectangular collisions. Given the points:</p>
<p style="text-align: center;"><img class="size-full wp-image-1630 aligncenter" title="abcd" src="http://silveiraneto.net/wp-content/uploads/2008/10/abcd.png" alt="" width="200" height="145" /></p>
<p>We did:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// returning 0 means collision</span>
<span style="color: #993333;">int</span> collision<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> ax<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> ay<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> bx<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> by<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> cx<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> cy<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> dx<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> dy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ax <span style="color: #339933;">&gt;</span> dx<span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>bx <span style="color: #339933;">&lt;</span> cx<span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>ay <span style="color: #339933;">&gt;</span> dy<span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>by <span style="color: #339933;">&lt;</span> cy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I&#8217;ll show here a little demo about how implement simple rectangular collisions on JavaFX.<br />
First I created a movable rectangle using the same idea of draggable nodes I already had <a href="http://silveiraneto.net/2008/08/11/javafx-draggable-node/">posted before</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.input.MouseEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.geometry.Rectangle</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MovableRectangle <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Rectangle</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> attribute startX <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> attribute startY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> attribute onMove <span style="color: #339933;">=</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    override attribute onMousePressed <span style="color: #339933;">=</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
        startX <span style="color: #339933;">=</span> e.<span style="color: #006633;">getDragX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>translateX<span style="color: #339933;">;</span>
        startY <span style="color: #339933;">=</span> e.<span style="color: #006633;">getDragY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>translateY<span style="color: #339933;">;</span>
        onMove<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    override attribute onMouseDragged <span style="color: #339933;">=</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
        translateX <span style="color: #339933;">=</span> e.<span style="color: #006633;">getDragX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startX<span style="color: #339933;">;</span>
        translateY <span style="color: #339933;">=</span> e.<span style="color: #006633;">getDragY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span>startY<span style="color: #339933;">;</span>
        onMove<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the main code I some important things:</p>
<ul>
<li><strong>colide</strong>, a color that represents the collision effect. White means no collision and gray means collision.</li>
<li><strong>rec1</strong> and <strong>rec2</strong>, the two rectangles that can collide.</li>
<li><strong>checkcollision()</strong> the function that checks and handles a possible collision.</li>
</ul>
<p>Here is the main code:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.application.Frame</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.application.Stage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.geometry.Rectangle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.paint.Color</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.input.MouseEvent</span><span style="color: #339933;">;</span>
&nbsp;
var colide <span style="color: #339933;">=</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span><span style="color: #339933;">;</span>
&nbsp;
function checkcollision<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#40;</span>rec1.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> rec2.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rec2.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> or
        <span style="color: #009900;">&#40;</span>rec1.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rec1.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> rec2.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> or 
        <span style="color: #009900;">&#40;</span>rec1.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> rec2.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rec2.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> or 
        <span style="color: #009900;">&#40;</span>rec1.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> rec1.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> rec2.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        colide <span style="color: #339933;">=</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        colide <span style="color: #339933;">=</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">LIGHTGRAY</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var rec1<span style="color: #339933;">:</span> MovableRectangle <span style="color: #339933;">=</span> MovableRectangle <span style="color: #009900;">&#123;</span>
    x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span>, y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">10</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">50</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">60</span>, fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span>
    onMove<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">:</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
        checkcollision<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
var rec2<span style="color: #339933;">:</span> MovableRectangle <span style="color: #339933;">=</span> MovableRectangle <span style="color: #009900;">&#123;</span>
    x<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span>, y<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">70</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">30</span>, fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLUE</span>
    onMove<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #003399;">MouseEvent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Void</span> <span style="color: #009900;">&#123;</span>
        checkcollision<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003399;">Frame</span> <span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Rectangular Collisions&quot;</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>
    closeAction<span style="color: #339933;">:</span> function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
    visible<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
&nbsp;
    stage<span style="color: #339933;">:</span> Stage <span style="color: #009900;">&#123;</span>
        fill<span style="color: #339933;">:</span> bind colide
        content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>rec1, rec2<span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Try it via Java Web Start:</p>
<p><center><a href="http://silveiraneto.net/downloads/collisiondemo/launch.jnlp"><img src="http://silveiraneto.net/wp-content/uploads/2008/10/webstart.png" alt="Java Web Start" /></a></center></p>
<p>Some considerations:</p>
<ul>
<li>You can use rectangular collisions to create bounding boxes to handle collisions in more complex shapes or sprites. Is a common approach in 2d games to avoid more expensive calculations.</li>
<li>There are space for optimizations.</li>
<li>In this case I&#8217;m using only two objects. Some problems raises when I have N objects to handle.</li>
</ul>
<p>More generally, we can code:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">function collission<span style="color: #009900;">&#40;</span>ax, ay, bx, by, cx, cy, dx, dy<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #003399;">Boolean</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> not <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ax <span style="color: #339933;">&gt;</span> dx<span style="color: #009900;">&#41;</span>or<span style="color: #009900;">&#40;</span>bx <span style="color: #339933;">&lt;</span> cx<span style="color: #009900;">&#41;</span>or<span style="color: #009900;">&#40;</span>ay <span style="color: #339933;">&gt;</span> dy<span style="color: #009900;">&#41;</span>or<span style="color: #009900;">&#40;</span>by <span style="color: #339933;">&lt;</span> cy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
function hitnode<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">:</span> Node, b<span style="color: #339933;">:</span>Node<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #003399;">Boolean</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>collission<span style="color: #009900;">&#40;</span>
        a.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, a.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        a.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> a.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, a.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> a.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        b.<span style="color: #006633;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, b.<span style="color: #006633;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        b.<span style="color: #006633;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, b.<span style="color: #006633;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This way we can pass just two bounding boxes to hitnode and easily check collision of a node against a list of bounding boxes nodes.<br />
Using the same approach I also wrote this function to test if a Node is inside another Node:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">function inside <span style="color: #009900;">&#40;</span>ax, ay, bx, by, cx, cy, dx, dy<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ax <span style="color: #339933;">&gt;</span> cx<span style="color: #009900;">&#41;</span> and <span style="color: #009900;">&#40;</span>bx <span style="color: #339933;">&lt;</span> dx<span style="color: #009900;">&#41;</span> and <span style="color: #009900;">&#40;</span>ay <span style="color: #339933;">&gt;</span> cy<span style="color: #009900;">&#41;</span> and <span style="color: #009900;">&#40;</span>by <span style="color: #339933;">&lt;</span> dy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
function insidenode<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">:</span>Node,b<span style="color: #339933;">:</span>Node<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #003399;">Boolean</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>inside<span style="color: #009900;">&#40;</span>
        a.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, a.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        a.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> a.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, a.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> a.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        b.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, b.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,
        b.<span style="color: #006633;">getBoundsX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, b.<span style="color: #006633;">getBoundsY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Soon I&#8217;ll post game examples showing how to use this method and others collission detection methods.</p>
<p><strong>Downloads:</strong></p>
<ul>
<li>The original video, <a href="http://silveiraneto.net/downloads/javafx_rectangular_collision_detection.ogg">javafx_rectangular_collision_detection.ogg</a></li>
<li>NetBeans 6.1 Project with sources, <a href="http://silveiraneto.net/downloads/javafx_rec_col.tar.gz">javafx_rec_col.tar.gz</a>. Needs <a href="http://javafx.netbeans.org">JavaFX module</a> installed.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/10/30/javafx-rectangular-collision-detection/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Short urls with Glassfish+MySQL</title>
		<link>http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/</link>
		<comments>http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 02:27:18 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[GlassFish]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[xort]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1503</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/" title="Short urls with Glassfish+MySQL"></a>Pipes, Creative Commons photo by flattop341. 1. The Problem Internet is full of long urls and meaningless. Long urls are difficult to remember or print, usually full of redundancy and low semantic. With short and meaningful urls you can avoid &#8230;<p class="read-more"><a href="http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/" title="Short urls with Glassfish+MySQL"></a><p style="text-align: center;"><img class="size-full wp-image-1517 aligncenter" title="pipes_by_flattop341_on_flickr" src="http://silveiraneto.net/wp-content/uploads/2008/10/pipes_by_flattop341_on_flickr.jpg" alt="" width="500" height="375" /><br />
Pipes, Creative Commons photo by <a href="http://flickr.com/photos/flattop341/253765659/">flattop341</a>.</p>
<h2>1. The Problem</h2>
<p>Internet is full of long urls and meaningless.</p>
<p>Long urls are difficult to remember or print, usually full of redundancy and low semantic. With short and meaningful urls you can avoid thes problems and even achieve profitable goals with SEO<br />
SEO (search engine optimization) technics.</p>
<p>There are services like <a title="Tiny URL" href="http://tinyurl.com/">Tiny URL</a>, <a title="Fancy URL" href="http://www.fancyurl.com/home.php">Fancy URL</a>, <a title="Moo URL" href="http://moourl.com/">Moo URL</a> and others. Although they solve part of the problems, they bring <a title="Wikipedia, english" href="http://en.wikipedia.org/wiki/TinyURL#Criticism">several others</a>. Another problem is if you have a web site like example.com and use a third-party service for short urls you are losing part of your mind-share with your users and clients.</p>
<p>As an example, if a example.com company wants to promote a open work position would be preferable spread a example.com/jobs instead of a tinyurl.com/examplejobs, or even worst, a tinyurl.com/3i4i592 (meaningless hash).</p>
<h2>2. Solution Approach</h2>
<p>I created a little program called <a title="xort project page" href="http://xort.dev.java.net">xort</a> that can be placed on your own server and provide you own short maintening your base url.</p>
<p style="text-align: center;"><img title="pipe_abstraction" src="http://silveiraneto.net/wp-content/uploads/2008/10/pipe_abstraction.png" alt="" /></p>
<p>I use a pipe abstraction. Each pipe redirects from a key url to an output url.</p>
<p>The idea is that you have <a title="xort project page" href="http://xort.dev.java.net">xort</a> installed and associated into your domain (preferably on /x). A pipe inside example.com would be like example.com/x/jobs.</p>
<h2>3. Tools</h2>
<p>All those tools are multi platform, open source and free.</p>
<h3>3.1 Glassfish Application Server</h3>
<p style="text-align: center;"><img title="Glassfish logo" src="../wp-content/uploads/2008/09/glassfish_logo_large.gif" alt="" /></p>
<p><a title="Glassfish Project" href="http://glassfish.dev.java.net">Glassfish</a> is an open source application server project led by Sun Microsystems for the Java Enterprise Edition (Java EE) platform. It&#8217;s very easy to install and run and have a very nice administration web interface where you can do from simple tasks like deploy a application to more complexes like clustering.</p>
<p style="text-align: center;"><img class="size-full wp-image-1249" title="glassfish_web_apps" src="../wp-content/uploads/2008/09/glassfish_web_apps.png" alt="" /><br />
Glassfish Admin Console</p>
<p>To develop the application I&#8217;m using <a title="NetBeans 6.5 Beta Download" href="http://download.netbeans.org/netbeans/6.5/beta/">NetBeans 6.5 Beta</a> that comes with <em>Glassfish V3 prelude b15b</em>. Netbeans also provides a integration of project, database and web server.</p>
<p style="text-align: center;"><img class="size-full wp-image-1504 aligncenter" title="netbeans services server glassfish" src="http://silveiraneto.net/wp-content/uploads/2008/10/netbeans_services_server_glassfish.png" alt="" width="361" height="161" /></p>
<p>Nevertheless, Glassfish has no dependencies with any IDE and perfectly works by alone. If you need <a title="Glassfish on Linux" href="http://silveiraneto.net/2008/09/07/glassfish-on-linux/">I wrote this post</a> explaining how to install and deploy a application on Glassfish from scratch.</p>
<h3>3.2 MySQL Relational Database</h3>
<p style="text-align: center;"><img class="size-full wp-image-1505 aligncenter" title="mysql" src="http://silveiraneto.net/wp-content/uploads/2008/10/mysql.png" alt="" width="180" height="93" /></p>
<p>MySQL is a relational database management system and probably the most used database on internet (has more than 11 million installations). It&#8217;s also very easy to install and administer, through command line or many gui interfaces.</p>
<p>To install MySQL and JDBC driver on Ubuntu just run as root:</p>
<blockquote><p># apt-get install mysql-server libmysql-java</p></blockquote>
<p>After installing and configuring it you can <a title="Looking for databases drivers" href="http://silveiraneto.net/2008/10/13/looking-for-databases-drivers/">test the jdbc driver throught this servlet code</a>. You can optionally register the MySQL on NetBeans to have a easier access to it thought the service tab.</p>
<p style="text-align: center;"><img class="size-full aligncenter" title="netbeans_services_databases" src="http://silveiraneto.net/wp-content/uploads/2008/10/netbeans_services_databases.png" alt="" /></p>
<p>At the command line you can invoke <em>mysql</em> command line interface and use MySql commands or SQL queries. I&#8217;ll login and create a database called xort:</p>
<blockquote><p>$ <strong>mysql -u username -p</strong><br />
Enter password:<br />
Welcome to the MySQL monitor.  Commands end with ; or \g.<br />
Your MySQL connection id is 13<br />
Server version: 5.0.51a-3ubuntu5.3 (Ubuntu)</p>
<p>Type &#8216;help;&#8217; or &#8216;\h&#8217; for help. Type &#8216;\c&#8217; to clear the buffer.</p>
<p>mysql&gt; <strong>create database xort;</strong><br />
Query OK, 1 row affected (0.06 sec)</p></blockquote>
<p>You could also create this database by an SQL statement:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">DATABASE</span> xort;</pre></div></div>

<p>To select the database xort:</p>
<blockquote><p>mysql&gt; <strong>use xort;</strong><br />
Reading table information for completion of table and column names<br />
You can turn off this feature to get a quicker startup with -A</p>
<p>Database changed<br />
mysql&gt;</p></blockquote>
<p>Now we create a database called pipes with fields pin (pipe in) and pout (pipe out). They represent the input url and the output url of our pipe abstraction.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> pipes <span style="color: #66cc66;">&#40;</span>
   pin <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
   pout <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>As we expect a lot of searches queries on this table, we can optionally create a index for it on pin field. This can reduce ours searches from O(n) to O(logn) (because pin&#8217;s will be ordered so don&#8217;t need to look all pipes, we can use logn algorithms like binary search).</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">INDEX</span> pinindex <span style="color: #993333; font-weight: bold;">ON</span> pipes <span style="color: #66cc66;">&#40;</span>pin<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Another trick to improve our speed is recycling connections through connection pools.</p>
<p style="text-align: center;"><img class="size-full wp-image-1535 aligncenter" title="glassfish pool" src="http://silveiraneto.net/wp-content/uploads/2008/10/glassfish_pool.png" alt="" width="300" height="197" /></p>
<p>Creating a pool of MySQL connections on Glassfish is very easy. There&#8217;re two good tutorials on this subject:</p>
<ul>
<li> <a title="Permanent Link: Glassfish v2 UR1 and MySQL Connection Pool" rel="bookmark" href="http://thestewscope.wordpress.com/2008/01/08/glassfish-v2-ur1-and-mysql-connection-pool/">Glassfish v2 UR1 and MySQL Connection Pool</a></li>
<li><a title="Pooling with MySQL" href="http://dev.mysql.com/tech-resources/articles/connection_pooling_with_connectorj.html">Connection pooling with MySQL Connector/J</a></li>
</ul>
<p>And now we populate the database with some initial pipes.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'blog'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://silveiraneto.net'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'cejug'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://cejug.org/display/cejug/Home'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'orkut'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://www.orkut.com.br/Main#Profile.aspx?rl=ls&amp;amp;uid=12443310329436634134'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'glassfish'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://glassfish.dev.java.net'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'mysql'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://dev.mysql.org'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'twitter'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'http://twitter.com/silveira'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'lab'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://maps.google.com/maps?f=q&amp;amp;geocode=&amp;amp;q=campus+do+pici&amp;amp;g=Fortaleza,+Brazil&amp;amp;ie=UTF8&amp;amp;t=h&amp;amp;ll=-3.745978,-38.574023&amp;amp;spn=0.002452,0.004823&amp;amp;z=18'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'videos'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://br.youtube.com/user/NetoSilveira'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> pipes <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'photos'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'http://flickr.com/photos/silveiraneto/'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h2>4. Program</h2>
<p>Basically we have just a program that implement this simple behavior:</p>
<ol>
<li>separate the key from the url.</li>
<li>if the key is a pin from a pipe then redirect to that pout.</li>
<li>else provide a way to create a new pipe.</li>
<li>list all pipes.</li>
<li>provide a way to remove a pipe.</li>
</ol>
<p>To get the key we need to separate the proper part of the request uri:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> uri <span style="color: #339933;">=</span> request.<span style="color: #006633;">getRequestURI</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> key <span style="color: #339933;">=</span> uri.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span>request.<span style="color: #006633;">getContextPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>After that we check if it matches with a pin of some pipe. In this case we redirect user for the correspondent pout:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">response.<span style="color: #006633;">sendRedirect</span><span style="color: #009900;">&#40;</span>pout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Notice that using this approach we can connect a url to a extern or intern url (even to another pipe).</p>
<h2>5. Download</h2>
<p>Check out the xort project and sources at <a href="http://xort.dev.java.net/">xort.dev.java.net</a>:</p>
<ul>
<li><a href="https://xort.dev.java.net/servlets/ProjectDocumentList">Releases</a>.</li>
<li><a title="Subversion" href="https://xort.dev.java.net/source/browse/xort/trunk/">Browse Source Code</a>.</li>
</ul>
<p>Or grab sources and the current build with:</p>
<blockquote><p>svn checkout https://xort.dev.java.net/svn/xort/trunk xort</p></blockquote>
<p>Parameters can be passed by the the web.xml file:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">   Set if users can add new pipes using the web interface.
allowNewPipes
true
&nbsp;
   JDBC driver to use
driver
com.mysql.jdbc.Driver
&nbsp;
   Username to login on the database.
username
root
&nbsp;
   Password for the given username.
password
yourpassword
&nbsp;
   JDBC path to database.
database
jdbc:mysql://localhost:3306/xort</pre></div></div>

<p>Xort up and running:</p>
<p style="text-align: center;"><a href="http://silveiraneto.net/wp-content/uploads/2008/10/xort_running.png"><img class="alignnone size-medium wp-image-1548" title="xort_running" src="http://silveiraneto.net/wp-content/uploads/2008/10/xort_running-500x312.png" alt="" width="500" height="312" /></a></p>
<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/b2Mrk8XfvKk&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/b2Mrk8XfvKk&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></object>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/10/21/short-urls-with-glassfishmysql/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Compiling Inkscape</title>
		<link>http://silveiraneto.net/2008/08/04/compiling-inkscape/</link>
		<comments>http://silveiraneto.net/2008/08/04/compiling-inkscape/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 17:12:34 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Inkscape]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1046</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2008/08/04/compiling-inkscape/" title="Compiling Inkscape"></a>Inkscape is a Open Source vector graphics editor that works with SVG (Scalable Vector Graphics) format, Inkscape works with transparency, gradients, node editing, pattern fills, PNG export, and more. It also runs on Linux, Windows and OSX, those three are &#8230;<p class="read-more"><a href="http://silveiraneto.net/2008/08/04/compiling-inkscape/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2008/08/04/compiling-inkscape/" title="Compiling Inkscape"></a><p style="text-align: center;"><img class="size-full wp-image-1048 aligncenter" title="inkscape screenshot" src="http://silveiraneto.net/wp-content/uploads/2008/08/inkscape_screenshot.jpg" alt="Inkscape running" width="400" height="320" /></p>
<p><a title="Inkscape.org" href="http://inkscape.org">Inkscape</a> is a Open Source vector graphics editor that works with SVG (Scalable Vector Graphics) format, Inkscape works with transparency, gradients, node editing, pattern fills, PNG export, and more. It also runs on Linux, Windows and OSX, those three are officially supported, but also runs in a broad list of Operational Systems. Is a software that I work daily and frequently is featured <a href="http://silveiraneto.net/tag/svg">here in my blog</a>.</p>
<p>You can download <a title="Inkscape Download" href="http://inkscape.org/download/?lang=en">Inkscape</a> or directly install it via some package system like Apt:</p>
<blockquote><p>sudo apt-get install inskcape</p></blockquote>
<p>But sometimes we need some special feature that is not available yet in the repositories or we want gain speed by having special binaries for our platforms or we want to help developing a new feature. In those cases we need to compile the software by ourself.</p>
<p>Those tips are valid for Ubuntu 8.04 but some part of them can be applied in others distributions. The Inkscape compiled here is the version 0.46+devel so newest versions can have compiling procedures slightly different.</p>
<p><strong>Getting sources via APT.</strong>The easiest way to compile Inkscape on Ubuntu is</p>
<blockquote><p>sudo su<br />
apt-get build-dep inkscape<br />
apt-get source inkscape<br />
cd inkscape<br />
./autogen.sh<br />
./configure<br />
make<br />
make install</p></blockquote>
<p>This will get a version of inkscape, compile it and install. If the first step doesn&#8217;t work well, you can try install all necessary packages by yourself using:</p>
<blockquote><p>sudo apt-get install autotools-dev fakeroot dh-make build-essential autoconf automake intltool libglib2.0-dev libpng12-dev libgc-dev libfreetype6-dev liblcms1-dev libgtkmm-2.4-dev libxslt1-dev libboost-dev libpopt-dev libgsl0ldbl libgsl0-dev libgsl0-dbg libgnome-vfsmm-2.6-dev libssl-dev libmagick++9-dev libwpg-dev</p></blockquote>
<p><strong>Getting sources via SVN.</strong> The recipe I showed above will compile a stable version of Inkscape but not the last version of Inkscape. For that we need to grab the source directly from the Subversion repositories and so compile it.</p>
<p>At your home folder:</p>
<blockquote><p>sudo apt-get install subversion<br />
svn checkout https://inkscape.svn.sourceforge.net/svnroot/inkscape/inkscape/trunk inkscape</p></blockquote>
<p>A alternative way to subversion is getting sources from <a href="http://inkscape.modevia.com/svn-snap/?M=D">here</a>. Those are tarballs built every hour after someone change something in the development repositories. Download a tarball, and decompress it on your home folder.</p>
<p>Install all tools we need to compile Inkscape, this should fits:</p>
<blockquote><p>sudo apt-get install autotools-dev fakeroot dh-make build-essential autoconf automake intltool libglib2.0-dev libpng12-dev libgc-dev libfreetype6-dev liblcms1-dev libgtkmm-2.4-dev libxslt1-dev libboost-dev libpopt-dev libgsl0ldbl libgsl0-dev libgsl0-dbg libgnome-vfsmm-2.6-dev libssl-dev libmagick++9-dev libwpg-dev</p></blockquote>
<p>Enter in the directory with the Inkscape source and do:</p>
<blockquote><p>./autogen.sh<br />
mkdir build<br />
cd build<br />
../configure<br />
make<br />
sudo make install</p></blockquote>
<p>In both cases, grabbing sources via svn or via apt, or can set the place where the software will be installed so it not cause conflicts with you already installed version of Inkscape. You can do that replacing the <em>./configure</em> step with something like:</p>
<blockquote><p>./configure &#8211;prefix=/home/yourname/inkscape</p></blockquote>
<p>If you had some trouble in one of those steps, consider reading some of those other tutorials:</p>
<ul>
<li><a href="http://www.inkscape.org/wiki/index.php/CompilingInkscape">http://www.inkscape.org/wiki/index.php/CompilingInkscape</a></li>
<li><a href="http://www.inkscape.org/wiki/index.php/CompilingUbuntu">http://www.inkscape.org/wiki/index.php/CompilingUbuntu</a></li>
<li><a href="https://help.ubuntu.com/community/CompilingEasyHowTo">https://help.ubuntu.com/community/CompilingEasyHowTo</a></li>
</ul>
<p><small><strong>ps:</strong> thanks guys from the inkscape-devel@lists.sourceforge.net specially heathenx.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/08/04/compiling-inkscape/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>JavaFX, creating a sphere with shadow</title>
		<link>http://silveiraneto.net/2008/07/31/javafx-creating-a-sphere-with-shadow/</link>
		<comments>http://silveiraneto.net/2008/07/31/javafx-creating-a-sphere-with-shadow/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 03:42:17 +0000</pubDate>
		<dc:creator>Silveira</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[Blur]]></category>
		<category><![CDATA[effect]]></category>
		<category><![CDATA[Ellipse]]></category>
		<category><![CDATA[Gaussian Blur]]></category>
		<category><![CDATA[Gradient]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[Radial Gradient]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Shadow]]></category>
		<category><![CDATA[sphere]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://silveiraneto.net/?p=1020</guid>
		<description><![CDATA[<a href="http://silveiraneto.net/2008/07/31/javafx-creating-a-sphere-with-shadow/" title="JavaFX, creating a sphere with shadow"></a>This is a short tutorial about some JavaFX elements like ellipses, circles, effects and gradients. In the first code we are creating a frame with a ellipse with center in (120,140), 60 pixels of horizontal radius, 20 pixels of vertical &#8230;<p class="read-more"><a href="http://silveiraneto.net/2008/07/31/javafx-creating-a-sphere-with-shadow/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://silveiraneto.net/2008/07/31/javafx-creating-a-sphere-with-shadow/" title="JavaFX, creating a sphere with shadow"></a><p>This is a short tutorial about some JavaFX elements like ellipses, circles, effects and gradients.</p>
<p>In the first code we are creating a frame with a ellipse with center in (120,140), 60 pixels of horizontal radius, 20 pixels of vertical radius and color black. We have also a circle with center in (100,100), 50 pixels of radius and color red. The idea is make this circle appears like a sphere and make the ellipse look like a shadow.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.application.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.paint.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.geometry.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003399;">Frame</span> <span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;JavaFX Sphere&quot;</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>, visible<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
    stage<span style="color: #339933;">:</span> Stage <span style="color: #009900;">&#123;</span>
        content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
            Ellipse <span style="color: #009900;">&#123;</span>
                 centerX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">120</span>, centerY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">140</span>, radiusX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">60</span>, radiusY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span>
                 fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span>
            <span style="color: #009900;">&#125;</span>,
            Circle <span style="color: #009900;">&#123;</span> centerX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span>, centerY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span>, radius<span style="color: #339933;">:</span> <span style="color: #cc66cc;">50</span>, fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><img class="alignnone size-full wp-image-1021" title="JavaFX" src="http://silveiraneto.net/wp-content/uploads/2008/07/javafx_sphere_1.png" alt="" width="322" height="323" /></p>
<p>Now we will just add two thing, a effect and a radial gradient.</p>
<p>First we&#8217;ll just add javafx.scene.effect.* to our import list and just call the gaussian blur effect in our ellipse with</p>
<pre class="jfx:nocontrols:nogutter">effect: GaussianBlur{ radius: 20 }</pre>
<p>This creates a gaussian blur of radius 20. The first ellipse was like</p>
<p><img class="alignnone size-full wp-image-1030" title="ellipse" src="http://silveiraneto.net/wp-content/uploads/2008/07/ellipse.png" alt="" width="158" height="76" /></p>
<p>and now with the effect becomes</p>
<p><a href="http://silveiraneto.net/wp-content/uploads/2008/07/ellipse_blur.png"><img class="alignnone size-full wp-image-1031" title="ellipse blur" src="http://silveiraneto.net/wp-content/uploads/2008/07/ellipse_blur.png" alt="" width="150" height="67" /></a></p>
<p>Now we create a radial gradient for the circle appears like a sphere. We do that using the RadialGradient class at</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">RadialGradient <span style="color: #009900;">&#123;</span>
   centerX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">75</span>, centerY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">75</span>, radius<span style="color: #339933;">:</span> <span style="color: #cc66cc;">50</span>, proportional<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>
   stops<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
      Stop <span style="color: #009900;">&#123;</span>offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span><span style="color: #009900;">&#125;</span>,
      Stop <span style="color: #009900;">&#123;</span>offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.3</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span><span style="color: #009900;">&#125;</span>,
      Stop <span style="color: #009900;">&#123;</span>offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1.0</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">DARKRED</span><span style="color: #009900;">&#125;</span>,
   <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>First lets look at the gradient. It starts with a white color, going to red during the first 30% of the way. The remaining of the way is the color red going to a dark red. It creates a gradient like this one:</p>
<p><img class="alignnone size-full wp-image-1034" title="gradient" src="http://silveiraneto.net/wp-content/uploads/2008/07/gradient.png" alt="" width="264" height="30" /></p>
<p>But it is a radial gradient, with center in (75,75) and radius 50. So this radial gradient looks like this:</p>
<p><img class="alignnone size-full wp-image-1036" title="radial gradient" src="http://silveiraneto.net/wp-content/uploads/2008/07/radial_gradient.png" alt="" width="160" height="144" /></p>
<p>As we place this radial gradient in our circle, it was like this:</p>
<p><img class="alignnone size-full wp-image-1037" title="circle" src="http://silveiraneto.net/wp-content/uploads/2008/07/circle.png" alt="" width="120" height="110" /></p>
<p>And now is like this:</p>
<p><img class="alignnone size-full wp-image-1038" title="radial gradient circle" src="http://silveiraneto.net/wp-content/uploads/2008/07/radial_gradient_circle.png" alt="" width="119" height="112" /></p>
<p>Now the complete code. I guess it&#8217;s simple and also concise.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.application.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.paint.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.effect.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javafx.scene.geometry.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003399;">Frame</span> <span style="color: #009900;">&#123;</span>
    title<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;JavaFX Sphere&quot;</span>, width<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>, height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">300</span>, visible<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
    stage<span style="color: #339933;">:</span> Stage <span style="color: #009900;">&#123;</span>
        content<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
            Ellipse <span style="color: #009900;">&#123;</span>
                centerX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">120</span>, centerY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">140</span>, radiusX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">60</span>, radiusY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span>
                fill<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span>
                effect<span style="color: #339933;">:</span> GaussianBlur<span style="color: #009900;">&#123;</span> radius<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20</span> <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>,
            Circle <span style="color: #009900;">&#123;</span>
                centerX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span>, centerY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span>, radius<span style="color: #339933;">:</span> <span style="color: #cc66cc;">50</span>
                fill<span style="color: #339933;">:</span> RadialGradient <span style="color: #009900;">&#123;</span>
                    centerX<span style="color: #339933;">:</span> <span style="color: #cc66cc;">75</span>, centerY<span style="color: #339933;">:</span> <span style="color: #cc66cc;">75</span>, radius<span style="color: #339933;">:</span> <span style="color: #cc66cc;">50</span>, proportional<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>
                    stops<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
                        Stop <span style="color: #009900;">&#123;</span>offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.0</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">WHITE</span><span style="color: #009900;">&#125;</span>,
                        Stop <span style="color: #009900;">&#123;</span>offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0.3</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">RED</span><span style="color: #009900;">&#125;</span>,
                        Stop <span style="color: #009900;">&#123;</span>offset<span style="color: #339933;">:</span> <span style="color: #cc66cc;">1.0</span> color<span style="color: #339933;">:</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">DARKRED</span><span style="color: #009900;">&#125;</span>,
                    <span style="color: #009900;">&#93;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here is the final screenshot:</p>
<p><img class="alignnone size-full wp-image-1040" title="javafx sphere" src="http://silveiraneto.net/wp-content/uploads/2008/07/javafx_sphere_2.png" alt="" width="318" height="318" /></p>
]]></content:encoded>
			<wfw:commentRss>http://silveiraneto.net/2008/07/31/javafx-creating-a-sphere-with-shadow/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

