<?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>Okashini &#187; programación</title>
	<atom:link href="http://okashini.com/tags/programacion/feed/" rel="self" type="application/rss+xml" />
	<link>http://okashini.com</link>
	<description>Curiosidades, programación, tecnología, actualidad, astronomía y cualquier tema que se me pase por la cabeza</description>
	<lastBuildDate>Wed, 16 May 2012 20:41:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>El reto de la rana</title>
		<link>http://okashini.com/el-reto-de-la-rana/</link>
		<comments>http://okashini.com/el-reto-de-la-rana/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 15:47:55 +0000</pubDate>
		<dc:creator>Kamugo</dc:creator>
				<category><![CDATA[Programación]]></category>
		<category><![CDATA[inteligencia]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[juego]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://okashini.com/?p=2352</guid>
		<description><![CDATA[Kaeru Jump, del japonés kaeru (蛙, rana), es un pequeño juego en flash de inteligencia (o también de probar, probar y probar). El objetivo del juego es que la rana protagonista llegue a cada una de las piedras del escenario. A cada salto, la piedra anterior se hunde en el agua. Los saltos son sólo [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Kaeru Jump</strong>, del japonés <em>kaeru</em> (蛙, rana), es un pequeño juego en flash de inteligencia (o también de probar, probar y probar). El objetivo del juego es que la rana protagonista llegue a <strong>cada una de las piedras</strong> del escenario. A cada salto, la piedra anterior se hunde en el agua. Los saltos son sólo en ángulos rectos y no se puede saltar hacia atrás.</p>
<p>El reto son diez niveles generados aleatoriamente, a cada cual más difícil. Os reto a ver cuánto tiempo tardáis en acabarlos todos, sin hacer trampas claro.</p>

<embed "application="" x-shockwave-flash"="" src="http://okashini.com/wp-content/uploads/2011/08/kaeruJump.swf" width="700px" height="700px" quality="medium">

<h3>Solución</h3>
<p>Si no consiguieseis acabar todos los niveles, no os desesperéis ni lancéis el teclado por la ventana. Existe un método para resolver este tipo de problemas. En programación se le llama <a href="http://es.wikipedia.org/wiki/Vuelta_Atr%C3%A1s" title="backtracking">backtracking</a>. Aunque por el nombre parezca algo <em>guapo</em>, no es más que ir probando combinaciones hasta encontrar las que resuelvan el problema (en nuestro caso paramos al encontrar la primera que lo resuelva). Son muchas combinaciones, pero mientras las haga el ordenador a nosotros nos da igual, ¿no?</p>
<p>Para hacerlo funcionar, sólo tenéis que decir la posición inicial, la dirección a la que mira la rana y marcar los <em><strong>checkbox</strong></em> del mapa del nivel, si está marcado es que en el mapa hay una piedra en esa posición. <strong>¡Si leéis desde el lector RSS es probable que no veáis nada!</strong></p>

<script type="text/javascript" src="http://okashini.com/js/jquery.js"></script>
<script type="text/javascript" src="http://okashini.com/wp-content/uploads/2011/08/rana.js"></script>

<div style = "text-align: center;">
Fila inicial: <select id="filaOrigen"></select>
Columna inicial: <select id="columnaOrigen"></select>
Dirección inicial:
<select id="direccionOrigen">
         <option value="arriba">Arriba</option>
         <option value="derecha">Derecha</option>
         <option value="abajo">Abajo</option>
	<option value="izquierda">Izquierda</option>
</select>
<input type="button" id="botonResolver" value ="Resolver"/>
<div style="text-align: center;" id ="tablero"></div>
<h4><div style = "font-family: Georgia, Times; font-style: italic;" id="solucionRana"></div></h4>
</div>

<h3>El código</h3>
<p>Os pongo la función para calcular la solución en <strong>javascript</strong>. Se puede comprimir más el código, pero así se entiende mejor. Para llamarla, necesitáis la fila y la columna inicial(<code class="codecolorer javascript default .codecolorer-container { border-radius: 5px; }"><span class="javascript">f</span></code> y <code class="codecolorer javascript default .codecolorer-container { border-radius: 5px; }"><span class="javascript">c</span></code>), una matriz de booleanos para el <code class="codecolorer javascript default .codecolorer-container { border-radius: 5px; }"><span class="javascript">tablero</span></code> donde un <code class="codecolorer javascript default .codecolorer-container { border-radius: 5px; }"><span class="javascript"><span style="color: #003366; font-weight: bold;">true</span></span></code> indica que hay una piedra en esa posición, un <code class="codecolorer javascript default .codecolorer-container { border-radius: 5px; }"><span class="javascript">Array</span></code> vacío para guardar el <code class="codecolorer javascript default .codecolorer-container { border-radius: 5px; }"><span class="javascript">camino</span></code> en la recursividad y un <code class="codecolorer javascript default .codecolorer-container { border-radius: 5px; }"><span class="javascript">string</span></code> <code class="codecolorer javascript default .codecolorer-container { border-radius: 5px; }"><span class="javascript">direccion</span></code> para la dirección inicial, que puede ser &#8220;arriba&#8221;, &#8220;derecha&#8221;, &#8220;abajo&#8221; o &#8220;izquierda&#8221;. El resultado es un <code class="codecolorer javascript default .codecolorer-container { border-radius: 5px; }"><span class="javascript">Array</span></code> con dos posiciones: la primera indica si hay solución y la segunda indica el camino.</p>

<div class="codecolorer-container javascript railscasts .codecolorer-container { border-radius: 5px; }" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;height:100%;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> resolver<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> c<span style="color: #339933;">,</span> tablero<span style="color: #339933;">,</span> restantes<span style="color: #339933;">,</span> camino<span style="color: #339933;">,</span> direccion<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>restantes <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> camino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> resuelto <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Miro todas las direcciones desde la posición actual</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Arriba</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>direccion <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;abajo&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> hay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>fila <span style="color: #339933;">=</span> f <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> <span style="color: #339933;">!</span>hay <span style="color: #339933;">&amp;&amp;</span> fila <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #339933;">--</span>fila<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>tablero<span style="color: #009900;">&#91;</span>fila<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">--</span>restantes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camino.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Arriba&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultado <span style="color: #339933;">=</span> resolver<span style="color: #009900;">&#40;</span>fila<span style="color: #339933;">,</span> c<span style="color: #339933;">,</span> tablero<span style="color: #339933;">,</span> restantes<span style="color: #339933;">,</span> camino<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;arriba&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>resultado<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> camino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>restantes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camino.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Derecha</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>direccion <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;izquierda&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> hay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>columna<span style="color: #339933;">=</span> c <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> <span style="color: #339933;">!</span>hay <span style="color: #339933;">&amp;&amp;</span> columna <span style="color: #339933;">&lt;</span> columnas<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>columna<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>columna<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">--</span>restantes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camino.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Derecha&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultado <span style="color: #339933;">=</span> resolver<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> columna<span style="color: #339933;">,</span> tablero<span style="color: #339933;">,</span> restantes<span style="color: #339933;">,</span> camino<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;derecha&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>resultado<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> camino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>restantes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camino.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Abajo</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>direccion <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;arriba&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> hay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>fila <span style="color: #339933;">=</span> f <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> <span style="color: #339933;">!</span>hay <span style="color: #339933;">&amp;&amp;</span> fila <span style="color: #339933;">&lt;</span> filas<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>fila<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>tablero<span style="color: #009900;">&#91;</span>fila<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">--</span>restantes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camino.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Abajo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultado <span style="color: #339933;">=</span> resolver<span style="color: #009900;">&#40;</span>fila<span style="color: #339933;">,</span> c<span style="color: #339933;">,</span> tablero<span style="color: #339933;">,</span> restantes<span style="color: #339933;">,</span> camino<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;abajo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>resultado<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> camino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>restantes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camino.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Izquierda</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>direccion <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;derecha&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> hay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>columna<span style="color: #339933;">=</span> c <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> <span style="color: #339933;">!</span>hay <span style="color: #339933;">&amp;&amp;</span> columna <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #339933;">--</span>columna<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>columna<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">--</span>restantes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camino.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Izquierda&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resultado <span style="color: #339933;">=</span> resolver<span style="color: #009900;">&#40;</span>f<span style="color: #339933;">,</span> columna<span style="color: #339933;">,</span> tablero<span style="color: #339933;">,</span> restantes<span style="color: #339933;">,</span> camino<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;izquierda&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>resultado<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> camino<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>restantes<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablero<span style="color: #009900;">&#91;</span>f<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>c<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; camino.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>

]]></content:encoded>
			<wfw:commentRss>http://okashini.com/el-reto-de-la-rana/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>El conjunto de Mandelbrot</title>
		<link>http://okashini.com/el-fractal-de-mandelbrot/</link>
		<comments>http://okashini.com/el-fractal-de-mandelbrot/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 11:14:30 +0000</pubDate>
		<dc:creator>Kamugo</dc:creator>
				<category><![CDATA[Matemáticas y números]]></category>
		<category><![CDATA[Programación]]></category>
		<category><![CDATA[fractales]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mandelbrot]]></category>
		<category><![CDATA[matemáticas]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://okashini.com/?p=1991</guid>
		<description><![CDATA[Un fractal, como muchos sabréis, es una estructura que se repite a diferentes escalas. El fractal más conocido es el de Mandelbrot, estudiado por el matemático polaco, ya fallecido, Benoît Mandelbrot, recientemente fallecido, en la década de los 70 del siglo pasado. Mandelbrot pensaba que lo que él estaba estudiando no interesaba a nadie, ya [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript" src = "http://okashini.com/js/jquery.js"></script><script type="text/javascript" src = "http://okashini.com/wp-content/uploads/2011/07/mandelbrot.js"></script><p>Un <a href="http://es.wikipedia.org/wiki/Fractal">fractal</a>, como muchos sabréis, es una estructura que se repite a diferentes escalas. El fractal más conocido es el de Mandelbrot, estudiado por el matemático polaco, ya fallecido, <a href="http://es.wikipedia.org/wiki/Beno%C3%AEt_Mandelbrot">Benoît Mandelbrot</a>, recientemente fallecido, en la <strong>década de los 70</strong> del siglo pasado. Mandelbrot pensaba que lo que él estaba estudiando no interesaba a nadie, ya que todos los demás matemáticos se centraban en estructuras &#8220;suaves y regulares&#8221;. Para definir estas nuevas estructuras acudió a un diccionario de latín, hasta encontrar un adjetivo que describía las piezas irregulares de una piedra que ha sido lanzada: «<em>fractus</em>, <em>fracta</em>, <em>fractum</em>».</p>

<p>Los fractales no son sólo cosa de las matemáticas, sino que <strong>aparecen en muchos lugares de la naturaleza</strong>, como en las hojas de los helechos, en las ramas de los árboles, en el brécol, etc. Un caso extraordinario de fractal lo podemos encontrar en el Romanescu, una mezcla de brécol y coliflor.</p>

<a href="http://okashini.com/wp-content/uploads/2011/07/Romanescu.jpg"><img class="aligncenter size-medium wp-image-2273" title="Romanescu" src="http://okashini.com/wp-content/uploads/2011/07/Romanescu-300x288.jpg" alt="Romanescu, un fractal en la naturaleza" width="300" height="288" /></a>

<strong>Matemáticamente</strong>, el conjunto de Mandelbrot se define como:
<ul>
	<li>Tenemos <img src='http://s0.wp.com/latex.php?latex=c&#038;bg=ffffff&#038;fg=000&#038;s=0' alt='c' title='c' class='latex' />, un número complejo cualquiera.</li>
	<li>Tenemos la sucesión por inducción siguiente
<img src='http://s0.wp.com/latex.php?latex=%5Cleft+%5C%7B++%5Cbegin%7Bmatrix%7D++z_0+%26+%3D+%26+0+%5Cqquad+%5C+%26+%5Cqquad+%5C%5C++z_%7Bn%2B1%7D+%26+%3D+%26+z_n%5E2+%2B+c+%26++%5Cend%7Bmatrix%7D+%5Cright.&#038;bg=ffffff&#038;fg=000&#038;s=0' alt='&#92;left &#92;{  &#92;begin{matrix}  z_0 &amp; = &amp; 0 &#92;qquad &#92; &amp; &#92;qquad &#92;&#92;  z_{n+1} &amp; = &amp; z_n^2 + c &amp;  &#92;end{matrix} &#92;right.' title='&#92;left &#92;{  &#92;begin{matrix}  z_0 &amp; = &amp; 0 &#92;qquad &#92; &amp; &#92;qquad &#92;&#92;  z_{n+1} &amp; = &amp; z_n^2 + c &amp;  &#92;end{matrix} &#92;right.' class='latex' /></li>
</ul>

<p>Si la sucesión queda acotada, podemos decir que el punto <img src='http://s0.wp.com/latex.php?latex=c+&#038;bg=ffffff&#038;fg=000&#038;s=0' alt='c ' title='c ' class='latex' /> es parte del conjunto.</p>

<p>Pero dejemos las matemáticas y vamos a ver como se ve el conjunto gráficamente. Lo he generado utilizando <strong>jQuery</strong> y HTML5. Podéis aumentarlo para ver la autosimilitud haciendo clic encima. Es probable que no lo podáis leer desde el lector RSS o utilizando un navegador antiguo.</p>

<center><canvas style="border: 1px solid gray; border-radius: 3px;" id="canvas" width="150" height="150">
Tu navegador no es compatible con Canvas, deberías utilizar uno más moderno.
</canvas></center>
<div id="mandInfo" style = "color: gray; font-style: italic; text-align: center;"></div>

<p>Para acabar, la entrevista de Benoît en el programa Redes</p>

<span style="text-align:center; display: block;"><a href="http://okashini.com/el-fractal-de-mandelbrot/"><img src="http://img.youtube.com/vi/npOwA6fXevE/2.jpg" alt="" /></a></span>

<p>Como siempre, dejo el código para los programadores curiosos</p>

<div class="codecolorer-container javascript railscasts .codecolorer-container { border-radius: 5px; }" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;height:100%;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">// Clase timer para contar el tiempo de ejecucion</span><br />
<span style="color: #003366; font-weight: bold;">var</span> timer <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;time<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;now<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</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: #339933;">,</span><br />
&nbsp; &nbsp;start<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">time</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">now</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: #339933;">,</span><br />
&nbsp; &nbsp;since<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">now</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">time</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Variables globales</span><br />
<span style="color: #006600; font-style: italic;">// Variables del tamaño de Canvas</span><br />
<span style="color: #003366; font-weight: bold;">var</span> width <span style="color: #339933;">=</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> height <span style="color: #339933;">=</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// Precisión de los pixels (1 es lo más preciso)</span><br />
<span style="color: #003366; font-weight: bold;">var</span> pixels <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Coordenadas iniciales</span><br />
<span style="color: #003366; font-weight: bold;">var</span> xmin <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">2</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> xmax <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> ymin <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1.5</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> ymax <span style="color: #339933;">=</span> <span style="color: #CC0000;">1.5</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Stride</span><br />
<span style="color: #003366; font-weight: bold;">var</span> stridex <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>xmax <span style="color: #339933;">-</span> xmin<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> height<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> pixels<span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> stridey <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ymax <span style="color: #339933;">-</span> ymin<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> width<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> pixels<span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Aumentos</span><br />
<span style="color: #003366; font-weight: bold;">var</span> zoom <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> aumentos <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// Iteraciones</span><br />
<span style="color: #003366; font-weight: bold;">var</span> maxIt <span style="color: #339933;">=</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">function</span> render<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; timer.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Cargamos canvas</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Obtenemos el objeto Canvas</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> canvas <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'canvas'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Obtenemos el contexto 2d</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>canvas <span style="color: #339933;">&amp;&amp;</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'2d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; context <span style="color: #339933;">=</span> canvas.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'2d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Si existe empezamos a dibujar</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Cambiamos el tamaño, por si este ha cambiado</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; canvas.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> width<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; canvas.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> height<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x0 <span style="color: #339933;">=</span> xmin<span style="color: #339933;">,</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> height<span style="color: #339933;">;</span> i <span style="color: #339933;">+=</span> pixels<span style="color: #339933;">,</span> x0 <span style="color: #339933;">+=</span> stridex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> y0 <span style="color: #339933;">=</span> ymin<span style="color: #339933;">,</span> j <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> width<span style="color: #339933;">;</span> j <span style="color: #339933;">+=</span> pixels<span style="color: #339933;">,</span> y0 <span style="color: #339933;">+=</span> stridey<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> it<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>it <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x<span style="color: #339933;">*</span>x <span style="color: #339933;">+</span> y<span style="color: #339933;">*</span>y <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">&amp;&amp;</span> it <span style="color: #339933;">&lt;</span> maxIt<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>it<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> xtemp <span style="color: #339933;">=</span> x<span style="color: #339933;">*</span>x <span style="color: #339933;">-</span> y<span style="color: #339933;">*</span>y <span style="color: #339933;">+</span> x0<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">*</span>x<span style="color: #339933;">*</span>y <span style="color: #339933;">+</span> y0<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x <span style="color: #339933;">=</span> xtemp<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>it <span style="color: #339933;">&gt;=</span> maxIt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;rgba(0,0,0,1)&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>pixels<span style="color: #339933;">,</span>pixels<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;rgba(0,0,0,&quot;</span> <span style="color: #339933;">+</span> it <span style="color: #339933;">/</span> maxIt <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;)&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>pixels<span style="color: #339933;">,</span>pixels<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> timer.<span style="color: #660066;">since</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> since <span style="color: #339933;">=</span> render<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mandInfo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Renderizado en &quot;</span> <span style="color: #339933;">+</span> since <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; ms&lt;/br&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#canvas&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Obtengo las coordenadas del clic dentro de canvas</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">pageX</span><span style="color: #339933;">-</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#canvas&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">left</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">pageY</span><span style="color: #339933;">-</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#canvas&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">top</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Las transformo a las coordenadas actuales</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> realx <span style="color: #339933;">=</span> xmin <span style="color: #339933;">+</span> x <span style="color: #339933;">*</span> stridex<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> realy <span style="color: #339933;">=</span> ymin <span style="color: #339933;">+</span> y <span style="color: #339933;">*</span> stridey<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Pongo los nuevos límites de las coordenadas</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> temp_xmin <span style="color: #339933;">=</span> xmin<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> temp_xmax <span style="color: #339933;">=</span> xmax<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> temp_ymin <span style="color: #339933;">=</span> ymin<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> temp_ymax <span style="color: #339933;">=</span> ymax<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xmin <span style="color: #339933;">=</span> realx <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>temp_xmax <span style="color: #339933;">-</span> temp_xmin<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> zoom<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; xmax <span style="color: #339933;">=</span> realx <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>temp_xmax <span style="color: #339933;">-</span> temp_xmin<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> zoom<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ymin <span style="color: #339933;">=</span> realy <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>temp_ymax <span style="color: #339933;">-</span> temp_ymin<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> zoom<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ymax <span style="color: #339933;">=</span> realy <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>temp_ymax <span style="color: #339933;">-</span> temp_ymin<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> zoom<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Recalculo los Strides</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; stridex <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>xmax <span style="color: #339933;">-</span> xmin<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> height<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> pixels<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; stridey <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ymax <span style="color: #339933;">-</span> ymin<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> width<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> pixels<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>aumentos<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; since <span style="color: #339933;">=</span> render<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mandInfo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Aumentado en &quot;</span> <span style="color: #339933;">+</span> since <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; ms&lt;/br&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>

Para que funcione, en el HTML hay que importar la librería <strong>jQuery</strong>. Después necesitamos el <em>canvas</em> de HTML5: <code class="codecolorer html4strict default .codecolorer-container { border-radius: 5px; }"><span class="html4strict"><span style="color: #009900;">&lt;canvas <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;canvas&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;500&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>canvas&gt;</span></span></code> (tiene que tener identificador <strong>canvas</strong>). Por último y opcionalmente, un <em>div</em> donde se muestra el tiempo de renderizado: <code class="codecolorer html4strict default .codecolorer-container { border-radius: 5px; }"><span class="html4strict"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;mandInfo&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></span></code>.]]></content:encoded>
			<wfw:commentRss>http://okashini.com/el-fractal-de-mandelbrot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tu uso de cada letra</title>
		<link>http://okashini.com/uso-letras/</link>
		<comments>http://okashini.com/uso-letras/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 15:54:33 +0000</pubDate>
		<dc:creator>Kamugo</dc:creator>
				<category><![CDATA[Programación]]></category>
		<category><![CDATA[Curiosidades]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://okashini.com/?p=1400</guid>
		<description><![CDATA[Ya os hablé una vez de cuanto se usaba cada letra de media en Español, pero eso solo eran datos. Hoy os traigo algo más entretenido para que comprobéis que porcentaje de letras utilizáis vosotros mismos. Solo tenéis que escribir lo que queráis en el cuadro de texto y podréis ver un gráfico con los [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript" src="/js/jquery.js"></script><script type="text/javascript" src="/js/jscharts.js"></script><script type="text/javascript" src="/wp-content/uploads/2010/11/cuenta_letras.js"></script><p>Ya os hablé <a href="http://okashini.com/el-uso-de-las-letras/">una vez</a> de cuanto se usaba cada letra de media en Español, pero eso solo eran datos. Hoy os traigo algo más entretenido para que comprobéis que porcentaje de letras utilizáis vosotros mismos. Solo tenéis que escribir lo que queráis en el cuadro de texto y podréis ver un gráfico con los porcentajes de cada letra. Si el texto es muy largo seguramente se parezca a la media que os conté la otra vez.</p>
<p>¿Se parece a los porcentajes del otro post? ¿Cuál es la letra que más utilizas?</p>
<p>El programa no cuenta caracteres <em>extraños </em>como á, é, ñ, ç, &#8230; ¡viva el inglés! Recordad que necesitáis estar en el navegador y <strong>no en el lector RSS </strong>para poder probarlo.</p>
<textarea style="width: 100%; height: 50px"id="texto_letras_j"></textarea>
<div id="grafico_letras_j">
<p style="text-align:center; font-weight:bold;">Escribe el texto que quieras</p>
</div>
<p>Para los que quieran saber como funciona el programa en Javascript, os lo dejo aquí el código, he utilizado jQuery y <a href="http://www.jscharts.com/">JSCharts</a><strong> </strong>para generar los gráficos. El <strong>script principal</strong> es el siguiente:</p>

<div class="codecolorer-container javascript railscasts .codecolorer-container { border-radius: 5px; }" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;height:100%;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> v <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">26</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> abecedario <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'b'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'c'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'d'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'e'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'f'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'g'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'h'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'i'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'j'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'k'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'l'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'m'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'n'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'o'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'p'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'q'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'r'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'s'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'t'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'u'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'v'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'w'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'x'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'y'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'z'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Cada vez que dejemos de pulsar una tecla</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#texto_letras_j&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#contador_letras_j&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> v.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> v<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> arr <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#texto_letras_j&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> cont <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Recorremos todo el texto para analizar cada letra</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> arr.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Comprobamos que sea una letra y la aÃ±adimos</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[a-z]/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>arr.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>cont<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>v<span style="color: #009900;">&#91;</span>arr.<span style="color: #660066;">charCodeAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #3366CC;">'a'</span>.<span style="color: #660066;">charCodeAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[A-Z]/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>arr.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>cont<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span>v<span style="color: #009900;">&#91;</span>arr.<span style="color: #660066;">charCodeAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #3366CC;">'A'</span>.<span style="color: #660066;">charCodeAt</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>cont <span style="color: #339933;">!=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> myData <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">26</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Escribimos los resultados</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> v.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> res <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">*</span>v<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span>cont<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>abecedario<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> res<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#contador_letras_j&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&amp;lt;li&amp;gt;&quot;</span><span style="color: #339933;">+</span>abecedario<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;: &quot;</span><span style="color: #339933;">+</span>res.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;%&amp;lt;/li&amp;gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Generamos el grÃ¡fico de JSCharts</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> myChart <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> JSChart<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'grafico_letras_j'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'bar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Uso letras'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setAxisNameY</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setAxisNameX</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Letras'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setDataArray</span><span style="color: #009900;">&#40;</span>myData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setBarColor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#42aBdB'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setBarOpacity</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0.8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setBarBorderColor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#D9EDF7'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setBarValues</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setTitleColor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#8C8383'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setAxisColor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#777E81'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setAxisValuesColor</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#777E81'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">setSize</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">616</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">321</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myChart.<span style="color: #660066;">draw</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#grafico_letras_j&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>

<p>Además, para que funcione, debemos añadir lo siguiente al <strong>HTML</strong></p>
<p>El resultado final del HTML será el siguiente:</p>

<div class="codecolorer-container html4strict railscasts .codecolorer-container { border-radius: 5px; }" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/jquery.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/jscharts.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/cuenta_letras.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">textarea</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;texto_letras_j&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">textarea</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;grafico_letras_j&gt;</span></span>Escribe el texto que quieras<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;contador_letras_j&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></div></div>

<ul>
<li>Los scripts Javascript.</li>
<li>El cuadro de texto (<strong>texto_letras_j</strong>).</li>
<li>Un <strong>div</strong> para colocar el gráfico (<strong>grafico_letras_j</strong>).</li>
<li>Una lista<strong> </strong>y un párrafo (<strong>contador_letras_j</strong>) para guardar los resultados.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://okashini.com/uso-letras/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programadores maltratados</title>
		<link>http://okashini.com/programadores-maltratados/</link>
		<comments>http://okashini.com/programadores-maltratados/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 14:36:55 +0000</pubDate>
		<dc:creator>Kamugo</dc:creator>
				<category><![CDATA[Informática]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[vídeos]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://okashini.co.cc/?p=407</guid>
		<description><![CDATA[Hoy os traigo un vídeo sobre el inferno de los programadores. Están en la calle, con carteles de cartón como si estuvieran pidiendo. Por si no sabéis ingles, os traduzco los carteles, por orden. Estoy dolido. Llevamos 4 meses en un programa de 5 y he recibido los requisitos finales ayer (y han vuelto a cambiar!) Gasto [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy os traigo un vídeo sobre el inferno de los programadores. Están en la calle, con carteles de cartón como si estuvieran pidiendo.<br />
<span style="text-align:center; display: block;"><a href="http://okashini.com/programadores-maltratados/"><img src="http://img.youtube.com/vi/1lqxORnQARw/2.jpg" alt="" /></a></span>
Por si no sabéis ingles, os traduzco los carteles, por orden.</p>
<ul>
<li>Estoy dolido.</li>
<li>Llevamos 4 meses en un programa de 5 y he recibido los requisitos finales ayer (y han vuelto a cambiar!)</li>
<li>Gasto la mitad de mi día en reuniones de como trabajar mejor (en vez de trabajar).</li>
<li>Mi jefe leyó en una revista que los programadores usando (otro) lenguaje de programación eran dos veces más productivos, así que compró una copia y cortó por la mitad el programa (lo destrozó).</li>
<li>Cada día mi jefe cambia de opinión sobre lo que estamos programando.</li>
<li>La gente no para de decirme que les arregle el correo, así que no tengo tiempo para programar-</li>
<li>Mi padre no tiene más tiempo para mi.</li>
<li>Le dijeron a mi jefe que podían hacer nuestra siguiente versión en la mitad de tiempo y por la mitad de dinero, él les creyó, pero ahora han gastando todo su presupuesto y todo el tiempo y&#8230;</li>
<li>Está aun a la mitad. Ahora  se han ido y su código es un desastre, tenemos que arreglarlo y acabar lo que empezaron.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://okashini.com/programadores-maltratados/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

