<?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>DmitryBrant.com</title>
	<atom:link href="http://dmitrybrant.com/feed" rel="self" type="application/rss+xml" />
	<link>http://dmitrybrant.com</link>
	<description>Not responsible for any minds blown.</description>
	<lastBuildDate>Thu, 19 Nov 2009 02:03:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Discovering the 3D Mandelbulb</title>
		<link>http://dmitrybrant.com/2009/11/18/mandelbulb</link>
		<comments>http://dmitrybrant.com/2009/11/18/mandelbulb#comments</comments>
		<pubDate>Wed, 18 Nov 2009 20:22:18 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Daily Events]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows Programming]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=674</guid>
		<description><![CDATA[There is some exciting news this week in the world of fractals.  Daniel White, on his website, describes what is apparently a completely new type of fractal, and the closest analog so far to a true 3-dimensional Mandelbrot set!
Although White mentions that this is probably not the &#8220;true&#8221; 3D Mandelbrot, the new fractal is [...]]]></description>
			<content:encoded><![CDATA[<p>There is some exciting news this week in the world of fractals.  Daniel White, on <a href="http://www.skytopia.com/project/fractal/2mandelbulb.html">his website</a>, describes what is apparently a completely new type of fractal, and the closest analog so far to a true 3-dimensional <a href="http://en.wikipedia.org/wiki/Mandelbrot_set">Mandelbrot set</a>!</p>
<p>Although White mentions that this is probably not the &#8220;true&#8221; 3D Mandelbrot, the new fractal is undoubtedly a sight to behold, especially considering the renderings he showcases on his webpage.</p>
<p>Unable to contain my enthusiasm, I quickly wrote up a small program that uses OpenGL to actually display this shape in 3D, in real time, to get a feel for what this beast looks like from all angles.  Don&#8217;t get too excited; the program does not <em>render</em> the shape in real time, it just displays the points rendered <em>so far</em> in real time. The actual rendering process can take a minute or so.</p>
<p>Download the program using the link below, and read further for instructions and screen shots.</p>
<p><img src="/images/download1.png" alt="download" align="left" /><strong><large><a href="/files/MandelbulbExplorer.zip">Download the program!</a></large></strong></p>
<p><a href="/files/MandelbulbExplorer.zip"><img src="/images/mandelbulb_ss1.png" alt="download" class="centered" /></a></p>
<p>The program basically renders the 3D shape by constructing a &#8220;point cloud&#8221; that approximates the edge of the fractal.</p>
<p>Everything in the program should be relatively self-explanatory, but here&#8217;s a brief overview of the features so far:</p>
<ul>
<li>The program lets you click-and drag the rendered shape to rotate it in trackball fashion (left mouse button), as well as zooming in and out (right mouse button).</li>
<li>The program lets you select the &#8220;power&#8221; of the Mandelbulb formula, as well as the number of iterations to perform.</li>
<li>The program lets you select the resolution of the point cloud.</li>
<li>It gives you a &#8220;selection cube&#8221; with which you can select a subset of the shape to zoom in on (with the &#8220;zoom to cube&#8221; button).</li>
<li>It has a number of other minor features like fog and anti-aliasing.</li>
<li>It uses multiple threads to render the shape, so it will take advantage of multiple cores/processors.</li>
</ul>
<p>Here are some additional screen shots:</p>
<div style="text-align: center"><em>Manipulating the selection cube:</em></div>
<p><img src="/images/mandelbulb_ss2.png" class="centered" /></p>
<div style="text-align: center"><em>After zooming in on the cube:</em></div>
<p><img src="/images/mandelbulb_ss3.png" class="centered" /></p>
<div style="text-align: center"><em>Zooming in further:</em></div>
<p><img src="/images/mandelbulb_ss4.png" class="centered" /></p>
<div style="text-align: center"><em>Looking inside:</em></div>
<p><img src="/images/mandelbulb_ss5.png" class="centered" /></p>
<div style="text-align: center"><em>Colorized points:</em></div>
<p><img src="/images/mandelbulb_ss6.png" class="centered" /></p>
<p>The program was written in C# .NET, using the Open Toolkit Library (<a href="http://www.opentk.com/">OpenTK</a>) which provides an excellent OpenGL wrapper.</p>
<p>Of course, this program is very much in its early stages, so don&#8217;t expect it to be perfect. As always, comments and suggestions are welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/11/18/mandelbulb/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Take macro photos with your cell phone</title>
		<link>http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone</link>
		<comments>http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone#comments</comments>
		<pubDate>Sun, 30 Aug 2009 23:24:11 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Daily Events]]></category>
		<category><![CDATA[Photos]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=667</guid>
		<description><![CDATA[A recent article on diyphotography.net talks about the awesome idea of taking apart an old DVD burner, and using the lens to take macro photos with your cell phone&#8217;s camera.  I just couldn&#8217;t resist trying this myself, but all I had was an old CD burner (not DVD). Nevertheless, the lens did the job [...]]]></description>
			<content:encoded><![CDATA[<p>A recent article on <a href="http://www.diyphotography.net/super-macro-your-cellphone-camera-with-a-dvd-lens">diyphotography.net</a> talks about the awesome idea of taking apart an old DVD burner, and using the lens to take macro photos with your cell phone&#8217;s camera.  I just couldn&#8217;t resist trying this myself, but all I had was an old CD burner (not DVD). Nevertheless, the lens did the job well, and the photos I was able to take with the camera in my Motorola RAZR V3xx (1.3mp) turned out pretty great:<br />

<div class="ngg-galleryoverview" id="ngg-gallery-17-667">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-1760" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1760" title=" "  >
								<img title="Pixels on a television screen" alt="Pixels on a television screen" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-28-09_2319.jpg"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1759" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1759" title=" "  >
								<img title="Pixels on my car stereo" alt="Pixels on my car stereo" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-28-09_2118.jpg"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1758" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1758" title=" "  >
								<img title="Detail of kitchen silverware" alt="Detail of kitchen silverware" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-28-09_2046.jpg"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1757" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1757" title=" "  >
								<img title="Button on my shirt" alt="Button on my shirt" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-28-09_1925.jpg"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1756" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1756" title=" "  >
								<img title="My parakeet's eye" alt="My parakeet's eye" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-28-09_1714.jpg"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1755" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1755" title=" "  >
								<img title="Windows Start button" alt="Windows Start button" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-28-09_1711.jpg"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1754" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1754" title=" "  >
								<img title="Denim fabric" alt="Denim fabric" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-28-09_1657.jpg"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1750" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1750" title=" "  >
								<img title="Close-up of fabric" alt="Close-up of fabric" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-27-09_1726.jpg"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1751" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1751" title=" "  >
								<img title="Close-up of microSD card" alt="Close-up of microSD card" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-27-09_1742.jpg"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1752" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1752" title=" "  >
								<img title="My fingerprint" alt="My fingerprint" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-27-09_1745.jpg"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1753" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone?pid=1753" title=" "  >
								<img title="My parakeet's beak" alt="My parakeet's beak" src="http://dmitrybrant.com/wp-content/gallery/cellphonemacro/thumbs/thumbs_08-27-09_1900.jpg"  />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>

</p>
]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/08/30/take-macro-photos-with-your-cell-phone/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Make your USB flash drive indestructible!</title>
		<link>http://dmitrybrant.com/2009/08/27/make-your-usb-flash-drive-indestructible</link>
		<comments>http://dmitrybrant.com/2009/08/27/make-your-usb-flash-drive-indestructible#comments</comments>
		<pubDate>Thu, 27 Aug 2009 23:34:49 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Daily Events]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=658</guid>
		<description><![CDATA[I don&#8217;t know about you, but I&#8217;m absolutely in love with USB flash drives (thumb drives, jump drives, whatever you want to call them). I&#8217;ve been using them since they first became available. The oldest one I still own is a 16MB drive that I bought for $50 in 2001.  The one I currently [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know about you, but I&#8217;m absolutely in love with USB flash drives (thumb drives, jump drives, whatever you want to call them). I&#8217;ve been using them since they first became available. The oldest one I still own is a 16MB drive that I bought for $50 in 2001.  The one I currently use is 16GB. That&#8217;s three orders of magnitude in eight years &#8212; remarkable! </p>
<p>The only problem I have with USB flash drives is when I mistakenly leave them in my pants pockets, and subsequently put the pants into the laundry basket. The flash drive will then suffer the grizzly fate of being spun around the washing machine soaked in soapy water, and will most likely never work again.  This made me think about possible methods of somehow sealing the flash drive to make it <strong>more resistant to the elements, or to physical impact</strong>.</p>
<h3>Background</h3>
<p><img src="/images/hardman0.jpg" class="alignright" />At the office where I work, I had found a supply of epoxy that the hardware engineers use for various purposes.  This epoxy comes in little packets, with each packet composed of two pouches containing different substances that, when mixed together, produce the hardening epoxy.  I knew about the supply of epoxy for a while, but I hadn&#8217;t made the connection between the epoxy and the flash drives until one day, in a moment of total enlightenment, I held up my flash drive in one hand, and an epoxy packet in the other, and began to laugh uncontrollably.</p>
<p>I wasn&#8217;t sure yet how well the epoxy would work, but everything about the epoxy seemed perfect, including the quantity, and what was written on the packet, which is:</p>
<ul>
<li>Work time: 3 to 5 minutes.</li>
<li>Will not shrink.</li>
</ul>
<p>That same day, I took an ordinary USB flash drive, removed the plastic case so that the PC board was completely exposed, mixed up some epoxy, and poured it onto both sides of the board, making sure that all the electronic components were fully covered, and only the USB connector exposed.  After about 5 minutes the epoxy hardened, and the result was even better than I hoped.  <em>The flash drive became indestructible</em>!</p>
<p>Wanting to buy some of these packets for myself, I searched for a distributor of this stuff online.  The brand of the epoxy is Hardman (aptly named!), and the first result is <a href="http://www.ellsworth.com/display/productdetail.html?productid=46&#038;Tab=Products">Ellsworth Adhesives</a>, which sells a box of 100 packets for about $120.  After looking a little harder, it seems that you can get the same box for a lot cheaper, such as from <a href="http://www.hmcelectronics.com/cgi-bin/scripts/product/7920-0001/Hardman-04001/">HMC Electronics</a> which sells it for $80, which is 80 cents per packet &#8212; a great deal.  Plus, the box includes popsicle sticks for easy mixing and spreading.</p>
<p>After I received the box, I encased two more flash drives in epoxy, with the same great results. The epoxy becomes rock-solid and impenetrable!  Since then, I&#8217;ve been epoxying pretty much everything that makes logical sense:  more flash drives, card readers, MP3 players, etc.  Take a look at this brief gallery of stuff that I&#8217;ve done this to:</p>

<div class="ngg-galleryoverview" id="ngg-gallery-16-658">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-1748" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/27/make-your-usb-flash-drive-indestructible?pid=1748" title="128MB flash drive encased in epoxy."  >
								<img title="128MB flash drive" alt="128MB flash drive" src="http://dmitrybrant.com/wp-content/gallery/epoxy/thumbs/thumbs_DSC_0013.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1749" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/27/make-your-usb-flash-drive-indestructible?pid=1749" title="2GB flash drive encased in epoxy."  >
								<img title="2GB flash drive" alt="2GB flash drive" src="http://dmitrybrant.com/wp-content/gallery/epoxy/thumbs/thumbs_DSC_0016.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1746" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/27/make-your-usb-flash-drive-indestructible?pid=1746" title="USB Bluetooth radio encased in epoxy."  >
								<img title="Bluetooth radio" alt="Bluetooth radio" src="http://dmitrybrant.com/wp-content/gallery/epoxy/thumbs/thumbs_DSC_0011.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1747" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/27/make-your-usb-flash-drive-indestructible?pid=1747" title="USB multi card reader encased in epoxy."  >
								<img title="Card reader" alt="Card reader" src="http://dmitrybrant.com/wp-content/gallery/epoxy/thumbs/thumbs_DSC_0012.JPG"  />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


<h3>Advantages</h3>
<p>The benefits of epoxying a USB flash drive (or any other small USB device) include:</p>
<ul>
<li>It looks freakin&#8217; sweet</li>
<li>It becomes virtually indestructible (the only remaining destructible component is the USB connector)</li>
<li>It becomes waterproof. My current flash drive has survived five wash cycles! Of course you have to allow the USB connector to dry completely, but after that, it&#8217;s as if nothing happened.</li>
<li>The epoxy helps dissipate heat from the flash memory and controller chips.</li>
<li>If the device has an LED, it will make the surrounding epoxy glow, which also looks cool.</li>
</ul>
<h3>Instructions</h3>
<p>Here are some brief instructions for encasing your own USB flash drive in epoxy:</p>
<p><em><strong>Safety first</strong>: Make sure you do this in a well-ventilated room, and don&#8217;t get any epoxy on your skin or in your eyes.  And of course, make sure any data that&#8217;s currently on your flash drive is backed up, in case anything &#8220;unexpected&#8221; happens.</em></p>
<ul>
<li>Take apart your USB flash drive. This is usually as simple as pulling apart the plastic cover that encases the PCB (printed circuit board). Be careful not to damage any of the delicate electronic components that are soldered onto the board. Throw the plastic away. All you should have left is the PCB with a USB connector soldered to it. If you like, you can write your initials on the PCB with a felt-tip pen, so that they&#8217;ll be visible through the clear epoxy when you&#8217;re finished.</li>
<li>Mix up some epoxy. I would recommend using two packets of the <a href="http://www.hmcelectronics.com/cgi-bin/scripts/product/7920-0001/Hardman-04001/">Hardman</a> epoxy for an average-size USB drive (one for each side of the PCB). I usually mix the epoxy with a popsicle stick, on top of a sheet of aluminum foil.  The epoxy must be mixed very thoroughly, or it won&#8217;t harden uniformly.  However, don&#8217;t take too long to mix it, since it will begin to harden very quickly.</li>
<li>Hold the flash drive by the USB connector, allowing one side of the PCB to face up (you&#8217;ll repeat this for the other side), and spread some epoxy right onto the exposed PCB with a popsicle stick (or your tool of choice)! Keep adding epoxy until all the electronic components are completely covered by it, right up to the connector (don&#8217;t put any epoxy on or inside the connector itself). Do your best to keep the epoxy well-contained. It can get messy fast.</li>
<li>Keep holding the flash drive with the epoxied side facing up, so that the epoxy settles evenly throughout the surface of the PCB. If some of the epoxy starts to drip off the edge, let it drip, or scrape off the excess with the popsicle stick.  The epoxy creates an exothermic reaction while setting, so it might get a little warm, but don&#8217;t be alarmed &#8212; it won&#8217;t get too hot to touch.  Don&#8217;t let anything come into contact with the epoxy while it&#8217;s setting, so that you&#8217;ll get a smooth, glossy surface.</li>
<li>After holding for a few minutes, the epoxy should harden, at which point you can flip over your flash drive and repeat the procedure on the other side of the PCB.</li>
<li>When the epoxy on both sides of the PCB has hardened, you&#8217;re done!  You might want to wait an additional 24 hours for the epoxy to <em>really</em> harden, though.</li>
<li>Enjoy your flash drive, which is now stronger than ever, looks slick, and is completely impervious to the elements!</li>
</ul>
<p>So, then, aside from USB flash drives, what kind of things are <em>you</em> planning to (or have already) encase in epoxy?</p>
<p>(Thanks to <a href="http://lifehacker.com/5353004/diy-indestructible-thumb-drive">Lifehacker</a> for picking up this story)</p>
]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/08/27/make-your-usb-flash-drive-indestructible/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>The Math Book: Get it Now!</title>
		<link>http://dmitrybrant.com/2009/08/14/the-math-book-get-it-now</link>
		<comments>http://dmitrybrant.com/2009/08/14/the-math-book-get-it-now#comments</comments>
		<pubDate>Sat, 15 Aug 2009 03:51:15 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Daily Events]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=620</guid>
		<description><![CDATA[Cliff Pickover, the prolific author of more than forty popular science and mathematics books, has outdone himself with his latest compilation: The Math Book.  This is a collection of 250 &#8220;milestones&#8221; of mathematics throughout history, complete with breathtaking glossy color illustrations for each entry (a first for his books), as well as insightful descriptions [...]]]></description>
			<content:encoded><![CDATA[<p>Cliff Pickover, the prolific author of more than forty popular science and mathematics books, has outdone himself with his latest compilation: <em><a href="http://sprott.physics.wisc.edu/pickover/math-book.html">The Math Book</a></em>.  This is a collection of 250 &#8220;milestones&#8221; of mathematics throughout history, complete with breathtaking glossy color illustrations for each entry (a first for his books), as well as insightful descriptions that explain the history and the significance of each of these marvels of mathematics.</p>
<p><a href="http://www.amazon.com/gp/product/1402757964?ie=UTF8&#038;tag=dmitrybcom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1402757964"><img src="/images/mathbook_knights.jpg" class="alignright" /></a>This book is especially significant in one other way:  <strong>it contains my artwork</strong>!  The book&#8217;s entry on Knight&#8217;s Tours (p. 186) familiarizes the reader with the history of this problem, dating all the way back to Euler in 1759.  And, alongside the article, Pickover displays a 30&#215;30 knight&#8217;s tour that was solved by my <a href="http://dmitrybrant.com/knights-tour">neural network knight&#8217;s tour implementation</a>.  For the picture in the book, I used a modified version of the program that generated a sufficiently hi-res image. That particular knight&#8217;s tour took about 3 days for my computer to generate.</p>
<p>I&#8217;m deeply grateful to have one of my creations published in a book by someone as influential as Cliff Pickover. Of course, it&#8217;s <em>all</em> of the 250 entries in the book that make it an incredibly fascinating stroll through the history of mathematics.  As mentioned elsewhere, this book definitely has bestseller potential, and could easily be one of Pickover&#8217;s best works. <a href="http://www.amazon.com/gp/product/1402757964?ie=UTF8&#038;tag=dmitrybcom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1402757964">Buy the book</a> now!</p>
]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/08/14/the-math-book-get-it-now/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Weekend at Hocking Hills</title>
		<link>http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills</link>
		<comments>http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills#comments</comments>
		<pubDate>Tue, 11 Aug 2009 00:47:02 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Daily Events]]></category>
		<category><![CDATA[Mycology]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=617</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[
<div class="ngg-galleryoverview" id="ngg-gallery-15-617">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-1665" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1665" title=" "  >
								<img title="DSC_0034" alt="DSC_0034" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0034.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1666" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1666" title=" "  >
								<img title="DSC_0035" alt="DSC_0035" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0035.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1667" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1667" title=" "  >
								<img title="DSC_0036" alt="DSC_0036" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0036.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1668" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1668" title=" "  >
								<img title="DSC_0038" alt="DSC_0038" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0038.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1669" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1669" title=" "  >
								<img title="DSC_0040" alt="DSC_0040" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0040.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1670" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1670" title=" "  >
								<img title="DSC_0041" alt="DSC_0041" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0041.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1672" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1672" title=" "  >
								<img title="DSC_0043" alt="DSC_0043" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0043.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1673" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1673" title=" "  >
								<img title="DSC_0045" alt="DSC_0045" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0045.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1675" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1675" title=" "  >
								<img title="DSC_0047" alt="DSC_0047" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0047.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1677" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1677" title=" "  >
								<img title="DSC_0049" alt="DSC_0049" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0049.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1678" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1678" title=" "  >
								<img title="DSC_0050" alt="DSC_0050" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0050.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1679" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1679" title=" "  >
								<img title="DSC_0051" alt="DSC_0051" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0051.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1681" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1681" title=" "  >
								<img title="DSC_0053" alt="DSC_0053" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0053.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1683" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1683" title=" "  >
								<img title="DSC_0055" alt="DSC_0055" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0055.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1685" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1685" title=" "  >
								<img title="DSC_0058" alt="DSC_0058" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0058.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1686" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1686" title=" "  >
								<img title="DSC_0059" alt="DSC_0059" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0059.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1687" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1687" title=" "  >
								<img title="DSC_0060" alt="DSC_0060" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0060.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1688" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1688" title=" "  >
								<img title="DSC_0061" alt="DSC_0061" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0061.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1689" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1689" title=" "  >
								<img title="DSC_0062" alt="DSC_0062" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0062.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1690" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?pid=1690" title=" "  >
								<img title="DSC_0063" alt="DSC_0063" src="http://dmitrybrant.com/wp-content/gallery/hocking/thumbs/thumbs_DSC_0063.JPG"  />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-navigation'><span>1</span><a class="page-numbers" href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?nggpage=2">2</a><a class="page-numbers" href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?nggpage=3">3</a><a class="next" id="ngg-next-2" href="http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills?nggpage=2">&#9658;</a></div> 	
</div>


]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/08/10/a-weekend-at-hocking-hills/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Beginning Java ME: A Simple Mandelbrot Viewer</title>
		<link>http://dmitrybrant.com/2009/07/19/java-me-mandelbrot-viewer</link>
		<comments>http://dmitrybrant.com/2009/07/19/java-me-mandelbrot-viewer#comments</comments>
		<pubDate>Sun, 19 Jul 2009 21:39:57 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=597</guid>
		<description><![CDATA[Version 3.0 of the Java ME SDK from Sun makes it very easy to start developing Java applications for mobile devices.  The SDK comes with a full-fledged (and surprisingly usable) IDE, as well as a suite of emulators and example applications, all of which allows you to pick up and start writing your own [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/images/screenshot0.png" class="alignright" />Version 3.0 of the <a href="http://java.sun.com/javame/sdk/index.jsp">Java ME SDK</a> from Sun makes it very easy to start developing Java applications for mobile devices.  The SDK comes with a full-fledged (and surprisingly usable) IDE, as well as a suite of emulators and example applications, all of which allows you to pick up and start writing your own apps in no time.  I&#8217;ve always wanted to develop a few small applications that I could run from my phone, so I thought this might be a good time to start.
</p>
<p>
My first idea was to develop a very basic <a href="http://en.wikipedia.org/wiki/Mandelbrot_set">Mandelbrot set</a> renderer and zoomer.  Sure, it&#8217;s not very &quot;useful,&quot; but it&#8217;s definitely pretty, and you&#8217;ll know that you&#8217;ll always have one of the defining symbols of modern mathematics right at your fingertips.
</p>
<p>
And, of course, it&#8217;s an awesome way to pick up chicks at the bar or dance club.  I mean, come on, flash &#8216;em the old Mandelbrot set, and they&#8217;ll be all over you, am I right? Anyone?
</p>
<p>
Just as a refresher, the Mandelbrot set is plotted by iterating through the complex quadratic polynomial <em>z</em><sub>n+1</sub> = <em>z</em><sub>n</sub><sup>2</sup> + <em>c</em>, where <em>c</em> is each &#8220;pixel&#8221; within the range of the complex plane we want to plot.  If the sequence is bounded for a given <em>c</em> (within a certain number of iterations), the point is considered part of the Mandelbrot set, and the pixel is colored black.  If the sequence is unbounded for a given <em>c</em>, the color of the pixel is determined by how &#8220;fast&#8221; the sequence diverges.  The more iterations we take for our calculation, the more &#8220;precise&#8221; the set&#8217;s boundary will be.</p>
<p>
Here are some fundamental requirements for the application:
</p>
<ul>
<li>Render the Mandelbrot set using a predefined color palette</li>
<li>Allow the user to &quot;move&quot; the drawing by pressing the L, R, U, and D keys</li>
<li>Allow the user to &quot;zoom&quot; in and out of the Set by pressing, say, the 1 and 3 keys</li>
<li>Allow the user to decrease/increase iterations by pressing, oh I don&#8217;t know, the 7 and 9 keys, respectively</li>
</ul>
<h3>Creating a New Project</h3>
<p>
Now that we have some requirements, let&#8217;s get down to business. We&#8217;ll create a brand new project in the Java ME SDK, and we&#8217;ll call it something original, like <strong>Mandelbrot</strong>:
</p>
</p>
<div align="center">
<img height="377" width="547" alt="screenshot1.png" src="/images/screenshot1.png" />
</div>
</p>
<p>
Using all of the defaults for the purposes of this project is just fine. The SDK should generate a project that targets CLDC 1.1 (Connected Limited Device Configuration) and MIDP 2.0 (Mobile Information Device Profile).  It will also automatically create a MIDlet class that represents our new application.
</p>
<p>
The automatically-generated class descends from the base <code>MIDlet</code> class, and implements the <code>CommandListener</code> interface, which enables our app to &quot;listen&quot; to commands that we can assign to buttons on your phone. The class will be called something like <code>HelloMIDlet</code>, but we can easily rename it to something more pertinent like <code>MandelbrotApp</code>, and erase the &quot;hello world&quot; code so we have a totally clean class.</p>
<p>
Theoretically, however, in addition to a class that extends <code>MIDlet</code>, we&#8217;ll also need a class that extends the base class <code>Canvas</code> (we&#8217;ll call it <code>MandelbrotCanvas</code>), so that we can perform any kind of graphics operations we need. This class will also be responsible for capturing keystrokes from the phone&#8217;s keypad (this is different from capturing &quot;commands&quot; which the <code>MIDlet</code> class does).
</p>
<h3>The Code</h3>
<p>
Let&#8217;s first go over the <code>MandelbrotApp</code> class. Here are the first few lines of the class, followed by some explanation:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MandelbrotApp <span style="color: #000000; font-weight: bold;">extends</span> MIDlet <span style="color: #000000; font-weight: bold;">implements</span> CommandListener <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Display myDisplay<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> MandelbrotCanvas myCanvas<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command exit <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>Exit<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>, Command.<span style="color: #006633;">EXIT</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> Command about <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Command <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>About<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>, Command.<span style="color: #006633;">ITEM</span>, <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> colorPalette<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> scanlineBuffer<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> screenWidth <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>, screenHeight <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">float</span> rangex1 <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>2F, rangex2 <span style="color: #339933;">=</span> 0.5F, rangey1 <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>1.4F, rangey2 <span style="color: #339933;">=</span> 1.4F<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> numIterations <span style="color: #339933;">=</span> <span style="color: #cc66cc;">24</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> MandelbrotApp <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        myDisplay <span style="color: #339933;">=</span> Display.<span style="color: #006633;">getDisplay</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        myCanvas <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MandelbrotCanvas <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        myCanvas.<span style="color: #006633;">setCommandListener</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        myCanvas.<span style="color: #006633;">addCommand</span> <span style="color: #009900;">&#40;</span>exit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        myCanvas.<span style="color: #006633;">addCommand</span><span style="color: #009900;">&#40;</span>about<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        scanlineBuffer <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        colorPalette <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">256</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #cc66cc;">64</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
            colorPalette<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">*</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">63</span> <span style="color: #339933;">-</span> i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">64</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #cc66cc;">128</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
            colorPalette<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">-</span> <span style="color: #cc66cc;">64</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">127</span> <span style="color: #339933;">-</span> i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">128</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #cc66cc;">192</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
            colorPalette<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">-</span> <span style="color: #cc66cc;">128</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">192</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #cc66cc;">256</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
            colorPalette<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span> <span style="color: #339933;">-</span> i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>
In the above code, we perform some initialization of things we&#8217;ll use later on. First we create an instance of our canvas object (<code>MandelbrotCanvas</code>), and assign two commands (&quot;exit&quot; and &quot;about&quot;) to the canvas. This means that when the canvas becomes visible, these two commands will become available from the two top buttons of your handset&#8217;s keypad. Also, by setting the canvas&#8217; <code>CommandListener</code> to <code>this</code>, we&#8217;re saying that this class will handle the commands issued while the canvas is displayed. The variables <code>rangex1</code>, <code>rangex2</code>, <code>rangey1</code>, and <code>rangey2</code> represent the initial boundaries for our Mandelbrot calculation.  By manipulating these variables we can pan and zoom in and out of the image.</p>
<p>
We also define a color palette that we&#8217;ll use when rendering the Mandelbrot set. The color palette contains 256 entries, and is simply a gradient of colors from red, to green, to blue, and back to red.  Additionally, we define a variable called <code>scanlineBuffer</code> which will actually contain the screen contents before they&#8217;re painted onto the screen. We leave this initialized to <code>null</code>, because we&#8217;ll dynamically allocate this buffer the first time our <code>paint</code> event is called.
</p>
<p>
Next, we&#8217;ll create a function that actually renders the Mandelbrot set onto our screen buffer. This function uses the standard Mandelbrot algorithm without any fancy attempts at optimization, so it may be slower for some phones than others (on some phones it will be god-awful slow; sorry!).
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> RenderMandelbrot<span style="color: #009900;">&#40;</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><span style="color: #009900;">&#40;</span>myCanvas.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> screenWidth<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>myCanvas.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> screenHeight<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            screenWidth <span style="color: #339933;">=</span> myCanvas.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            screenHeight <span style="color: #339933;">=</span> myCanvas.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            scanlineBuffer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span>screenWidth <span style="color: #339933;">*</span> screenHeight<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">float</span> bmpWidth <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span>screenWidth<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">float</span> bmpHeight <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span>screenHeight<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">float</span> x, y, xsquare, ysquare, dx, dy, bail <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span>, j, p<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> i, mul, col<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> xpos, ypos<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> q <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>screenWidth <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> screenHeight<span style="color: #009900;">&#41;</span> q <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span>screenWidth <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">else</span> q <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#91;</span>screenHeight <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        mul <span style="color: #339933;">=</span> <span style="color: #cc66cc;">255</span> <span style="color: #339933;">/</span> numIterations<span style="color: #339933;">;</span>
        dx <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>rangex2 <span style="color: #339933;">-</span> rangex1<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> bmpWidth<span style="color: #339933;">;</span>
        dy <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>rangey2 <span style="color: #339933;">-</span> rangey1<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> bmpHeight<span style="color: #339933;">;</span>
&nbsp;
        q<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> rangey2<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> q.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> q<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> q<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> dy<span style="color: #339933;">;</span>
        xpos <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> ypos <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>p <span style="color: #339933;">=</span> rangex1<span style="color: #339933;">;</span> p <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> rangex2<span style="color: #339933;">;</span> p <span style="color: #339933;">+=</span> dx<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>j <span style="color: #339933;">=</span> rangey1<span style="color: #339933;">;</span> j <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> rangey2<span style="color: #339933;">;</span> j <span style="color: #339933;">+=</span> dy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> xsquare <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> ysquare <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> col <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>col <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> numIterations<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        scanlineBuffer<span style="color: #009900;">&#91;</span>ypos<span style="color: #339933;">*</span>screenWidth <span style="color: #339933;">+</span> xpos<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</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>
                    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>xsquare <span style="color: #339933;">+</span> ysquare<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> bail<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        scanlineBuffer<span style="color: #009900;">&#91;</span>ypos<span style="color: #339933;">*</span>screenWidth <span style="color: #339933;">+</span> xpos<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> colorPalette<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>col<span style="color: #339933;">*</span>mul<span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span>255<span style="color: #009900;">&#93;</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>
                    xsquare <span style="color: #339933;">=</span> x <span style="color: #339933;">*</span> x<span style="color: #339933;">;</span>
                    ysquare <span style="color: #339933;">=</span> y <span style="color: #339933;">*</span> y<span style="color: #339933;">;</span>
                    y <span style="color: #339933;">*=</span> x<span style="color: #339933;">;</span>
                    y <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>y <span style="color: #339933;">+</span> q<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    x <span style="color: #339933;">=</span> xsquare <span style="color: #339933;">-</span> ysquare <span style="color: #339933;">+</span> p<span style="color: #339933;">;</span>
                    col<span style="color: #339933;">++;</span>
                <span style="color: #009900;">&#125;</span>
                i<span style="color: #339933;">++;</span>
                ypos<span style="color: #339933;">++;</span>
                <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>ypos <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> screenHeight<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            myCanvas.<span style="color: #006633;">repaint</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            myCanvas.<span style="color: #006633;">serviceRepaints</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            xpos<span style="color: #339933;">++;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xpos <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> screenWidth<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            ypos <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>
Notice in the above function that, inside the outer loop, we force a repaint of the canvas, so that the user gets a sense of the graphic actually being drawn in real time. If we didn&#8217;t do this, the app would be totally unresponsive until all of the image is rendered.
</p>
<p>
When the app is started, the following function is called, where we set the canvas to be the currently-displayed object, and call the Mandelbrot rendering function:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> startApp <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MIDletStateChangeException <span style="color: #009900;">&#123;</span>
        myDisplay.<span style="color: #006633;">setCurrent</span> <span style="color: #009900;">&#40;</span>myCanvas<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        RenderMandelbrot<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>
Another point of interest in this class is the paint handler. This function actually gets called from the Canvas class (see lower), but I put the paint code in this class for convenience.
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> paint <span style="color: #009900;">&#40;</span><span style="color: #003399;">Graphics</span> g<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        g.<span style="color: #006633;">drawRGB</span><span style="color: #009900;">&#40;</span>scanlineBuffer, <span style="color: #cc66cc;">0</span>, screenWidth, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, screenWidth, screenHeight, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        g.<span style="color: #006633;">setColor</span><span style="color: #009900;">&#40;</span>0xFFFFFF<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> fontHeight <span style="color: #339933;">=</span> g.<span style="color: #006633;">getFont</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getHeight</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;">int</span> strY <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>
        g.<span style="color: #006633;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#40;</span>C<span style="color: #009900;">&#41;</span> Dmitry Brant<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>, <span style="color: #cc66cc;">4</span>, strY, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> strY <span style="color: #339933;">+=</span> fontHeight<span style="color: #339933;">;</span>
        g.<span style="color: #006633;">drawString</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>Iterations<span style="color: #339933;">:</span> <span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>numIterations<span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">4</span>, strY, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> strY <span style="color: #339933;">+=</span> fontHeight<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>
In the above function, all we do is draw our screen buffer to the screen, then write some text over the image, which includes a little copyright message and the current number of iterations used in the Mandelbrot calculation. Note that we dynamically get the height of the phone&#8217;s font (and adjust accordingly), since the font varies greatly between different phone models.
</p>
<p>
The other interesting function in this class is the command handler. This function will be called when either the &quot;Exit&quot; or &quot;About&quot; commands are pressed while our app is running. If &quot;Exit&quot; is pressed, we&#8217;ll destroy the application. If &quot;About&quot; is pressed, we&#8217;ll display a simple <code>Alert</code> message:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> commandAction <span style="color: #009900;">&#40;</span>Command cmd, Displayable disp<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>cmd <span style="color: #339933;">==</span> exit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            destroyApp <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</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;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>cmd <span style="color: #339933;">==</span> about<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            Alert alert <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Alert <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>About...<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            alert.<span style="color: #006633;">setType</span> <span style="color: #009900;">&#40;</span>AlertType.<span style="color: #006633;">INFO</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            alert.<span style="color: #006633;">setTimeout</span> <span style="color: #009900;">&#40;</span>Alert.<span style="color: #006633;">FOREVER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            alert.<span style="color: #006633;">setString</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>Copyright <span style="color: #cc66cc;">2009</span> Dmitry Brant.\nhttp<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//dmitrybrant.com&amp;quot;);</span>
            myDisplay.<span style="color: #006633;">setCurrent</span> <span style="color: #009900;">&#40;</span>alert<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>
Finally, let&#8217;s have a quick look at the <code>MandelbrotCanvas</code> class:
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MandelbrotCanvas <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Canvas</span> <span style="color: #009900;">&#123;</span>
    MandelbrotApp myApp<span style="color: #339933;">;</span>
&nbsp;
    MandelbrotCanvas <span style="color: #009900;">&#40;</span>MandelbrotApp mandelTestlet<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        myApp <span style="color: #339933;">=</span> mandelTestlet<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">void</span> init <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">void</span> destroy <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> paint <span style="color: #009900;">&#40;</span><span style="color: #003399;">Graphics</span> g<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        myApp.<span style="color: #006633;">paint</span> <span style="color: #009900;">&#40;</span>g<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> keyPressed <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> key<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> action <span style="color: #339933;">=</span> getGameAction <span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">float</span> xScale <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>myApp.<span style="color: #006633;">rangex2</span> <span style="color: #339933;">-</span> myApp.<span style="color: #006633;">rangex1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">float</span> yScale <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>myApp.<span style="color: #006633;">rangey2</span> <span style="color: #339933;">-</span> myApp.<span style="color: #006633;">rangey1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">boolean</span> gotAction <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span>, gotKey <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>action<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">case</span> LEFT<span style="color: #339933;">:</span>
            myApp.<span style="color: #006633;">rangex1</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>xScale <span style="color: #339933;">/</span> 16.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            myApp.<span style="color: #006633;">rangex2</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>xScale <span style="color: #339933;">/</span> 16.0F<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: #000000; font-weight: bold;">case</span> RIGHT<span style="color: #339933;">:</span>
            myApp.<span style="color: #006633;">rangex1</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>xScale <span style="color: #339933;">/</span> 16.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            myApp.<span style="color: #006633;">rangex2</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>xScale <span style="color: #339933;">/</span> 16.0F<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: #000000; font-weight: bold;">case</span> UP<span style="color: #339933;">:</span>
            myApp.<span style="color: #006633;">rangey1</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>yScale <span style="color: #339933;">/</span> 16.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            myApp.<span style="color: #006633;">rangey2</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>yScale <span style="color: #339933;">/</span> 16.0F<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: #000000; font-weight: bold;">case</span> DOWN<span style="color: #339933;">:</span>
            myApp.<span style="color: #006633;">rangey1</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>yScale <span style="color: #339933;">/</span> 16.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            myApp.<span style="color: #006633;">rangey2</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>yScale <span style="color: #339933;">/</span> 16.0F<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: #000000; font-weight: bold;">case</span> FIRE<span style="color: #339933;">:</span>
        <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
            gotAction <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>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>gotAction<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">case</span> KEY_NUM1<span style="color: #339933;">:</span>
                myApp.<span style="color: #006633;">rangex1</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>xScale <span style="color: #339933;">/</span> 4.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                myApp.<span style="color: #006633;">rangex2</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>xScale <span style="color: #339933;">/</span> 4.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                myApp.<span style="color: #006633;">rangey1</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>yScale <span style="color: #339933;">/</span> 4.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                myApp.<span style="color: #006633;">rangey2</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>yScale <span style="color: #339933;">/</span> 4.0F<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: #000000; font-weight: bold;">case</span> KEY_NUM3<span style="color: #339933;">:</span>
                myApp.<span style="color: #006633;">rangex1</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>xScale <span style="color: #339933;">/</span> 4.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                myApp.<span style="color: #006633;">rangex2</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>xScale <span style="color: #339933;">/</span> 4.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                myApp.<span style="color: #006633;">rangey1</span> <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>yScale <span style="color: #339933;">/</span> 4.0F<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                myApp.<span style="color: #006633;">rangey2</span> <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span>yScale <span style="color: #339933;">/</span> 4.0F<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: #000000; font-weight: bold;">case</span> KEY_NUM7<span style="color: #339933;">:</span>
                myApp.<span style="color: #006633;">numIterations</span><span style="color: #339933;">-=</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>myApp.<span style="color: #006633;">numIterations</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> myApp.<span style="color: #006633;">numIterations</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">case</span> KEY_NUM9<span style="color: #339933;">:</span>
                myApp.<span style="color: #006633;">numIterations</span><span style="color: #339933;">+=</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
                gotKey <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>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>gotAction <span style="color: #339933;">||</span> gotKey<span style="color: #009900;">&#41;</span>
            myApp.<span style="color: #006633;">RenderMandelbrot</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>
The only relevant functions in the above class are the <code>paint</code> function, which is called automatically whenever the screen needs repainting, and the <code>keyPressed</code> function, which gets called when the user presses any of the keys on the keypad.
</p>
<p>
Notice how pressing the Up/Down/Left/Right buttons causes the x- and y-ranges to be panned to simulate the effect of scrolling, and the &quot;1&quot; and &quot;3&quot; keys have the effect of zooming. Keys &quot;7&quot; and &quot;9&quot; are also programmed to decrease and increase the number of iterations by 4. After any key is pressed, the graphic is redrawn due to <code>RenderMandelbrot()</code> being called again.
</p>
<h3>Testing the App</h3>
<p>
That&#8217;s about all there is to it. The next step is to test how the app works. If we run the app from the IDE of the Java ME SDK, it automatically launches a default emulator and loads the app onto it:
</p>
</p>
<div align="center">
<img height="497" width="225" alt="screenshot2.png" src="/images/screenshot2.png" class="alignright" />
</div>
<p>Seems to work fine on the emulator! Now how about getting it onto an actual phone?  Building the app produces two files: a .JAR file, which is the actual app, and a .JAD file, which is a text file that contains certain descriptions about the app (such as the author, copyright, and URL). But what do we do with these files?</p>
<p>
Loading a Java app onto a phone can be done in a few different ways:
</p>
<ul>
<li>Download from the Web</li>
<li>Download over Bluetooth</li>
<li>Download with Java App Loader (Motorola phones only)</li>
<li>Load from a memory card</li>
<li>Hack right into the phone</li>
</ul>
<p>
I&#8217;m fortunate enough to have a Motorola RAZR V3xx, which has a microSD slot. I was amazed how easy it was to get it up and running on this phone. Here&#8217;s all that&#8217;s required to install a Java app onto this phone (and probably similar Motorola models that accept a microSD card):
</p>
<ul>
<li>With the microSD card in the phone, connect a USB cable from your computer to the phone (it will map as a disk drive)</li>
<li>Copy your app&#8217;s .JAR and .JAD files to the <code>/mobile/kjava</code> directory</li>
<li>Disconnect the USB cable from the phone</li>
<li>On the phone, go to Menu -&gt; My Stuff -&gt; Games &amp; Apps -&gt; [Install New], and select your app from the list</li>
<li>That&#8217;s it! The app will now be installed on the phone!</li>
</ul>
<h3>Installing over the Web</h3>
<p><img height="527" width="220" alt="screenshot3.jpg" src="/images/screenshot3.jpg" class="alignright" /></p>
<p>
If you don&#8217;t have a phone that lets you install apps from a microSD card, you can download the app from the Web using your phone. This is, of course, only if your phone has an active account and supports Web access. You&#8217;ll also probably be paying a few cents for the data transfer, depending on the wireless plan you purchased from your carrier. Oh, and of course, your phone must support CLDC 1.1 (1.0 doesn&#8217;t have floating-point support), and MIDP 2.0, which most modern phones do.
</p>
<p>
Now then, if you want to load an app that you wrote onto your phone over the Web, you need to have access to a web server where you can place your app to be downloaded. For my example, I&#8217;ll use my web server, <code>dmitrybrant.com</code>, and I&#8217;ll put the app in a subdirectory, like so:
</p>
<div align="center">
<p><a href="http://dmitrybrant.com/jme/Mandelbrot.jad">http://dmitrybrant.com/jme/Mandelbrot.jad</a></p>
</div>
<p>
I put both the .JAR and .JAD files in the &quot;jme&quot; subdirectory. To download the app, you only need to link to the .JAD file. <strong>But wait!</strong> There&#8217;s one more crucial step to take before our app can be downloaded from a phone. We need to edit the <code>.htaccess</code> file in this directory, and add the proper MIME types for our files:
</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">AddType text/vnd.sun.j2me.app-descriptor jad
AddType application/java-archive jar</pre></div></div>

<p>
Once this is done, we can try downloading the app to our phone. After a minute of fat-fingering the URL, agreeing to install an unsigned app, and waiting for it to finish installing&#8230; lo and behold:
</p>
<p>
For the record, the above screen took about 20 seconds to draw on my V3xx. Your phone may be significantly slower (or faster, but probably not). So be prepared to wait a bit for the drawing to complete. Or go ahead and optimize the code to use integer-only math! (Let me know if you do!)
</p>
<ul>
<li>Download the <a href="/files/Mandelbrot_me.zip">source code</a> for this app.</li>
<li>See <a href="http://www.codeproject.com/KB/java/java_me_mandelbrot.aspx">this article at CodeProject</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/07/19/java-me-mandelbrot-viewer/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Seven-Segment Display for .NET</title>
		<link>http://dmitrybrant.com/2009/07/01/seven-segment-display-for-dot-net</link>
		<comments>http://dmitrybrant.com/2009/07/01/seven-segment-display-for-dot-net#comments</comments>
		<pubDate>Thu, 02 Jul 2009 01:35:29 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows Programming]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=582</guid>
		<description><![CDATA[I&#8217;m usually not a big fan of custom controls except in the most extreme circumstances. From the point of view of usability, it should always make the most sense to use the controls that are shipped with the Operating System. Your user base is already familiar with the OS&#8217;s native controls, so creating custom controls [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/images/sevensegment.png" alt="Seven-segment display" class="alignright" />I&#8217;m usually not a big fan of custom controls except in the most extreme circumstances. From the point of view of usability, it should always make the most sense to use the controls that are shipped with the Operating System. Your user base is already familiar with the OS&#8217;s native controls, so creating custom controls would only add to the learning curve for your application. But I digress. Sometimes, there are certain controls that just beg to be written, whether they&#8217;re useful or not.</p>
<p>That&#8217;s why I decided to write this seven-segment LED control: not because it&#8217;s any more &quot;useful&quot; than a standard Label control, but because it looks freakin&#8217; sweet. I also wrote the control to become more familiar with the internals of C# and .NET in general. And, if you like the control and are able to use it, or learn from it, so much the better.</p>
<p>Even if you haven&#8217;t heard the name &quot;seven-segment display&quot; before, you&#8217;ve probably seen quite a few in your lifetime. They appear on pretty much every piece of electronic equipment that needs to display numbers for any reason, like the timer on a microwave oven, the display on a CD player, or the time on your digital wristwatch.</p>
<p>They&#8217;re called seven-segment displays because they&#8217;re actually made up of seven &quot;segments&quot; &mdash; seven individual lights (LEDs or otherwise) that light up in different patterns that represent any of the ten digits (0 &#8211; 9).</p>
<p><img src="/images/download1.png" alt="download" align="right" />So, what are you waiting for? <strong><a href="/files/sevensegment.zip">Download the control</a></strong>, or <strong><a href="/files/sevensegtest.zip">download the test application</a></strong> which the screen shot is from.</p>
<h3>Using the code</h3>
<p>This custom control can be built into your application by simply including the &quot;SevenSegment.cs&quot; file in your project. Rebuild your project, and you&#8217;ll be able to select the <code>SevenSegment</code> control from your tool palette and drop it right onto your forms.</p>
<p>To replicate the look of a seven-segment display, I draw seven polygons that precisely match the physical layout of a real display. To model the polygons, I drew them out on graph paper, and recorded the coordinates of each point in each polygon. To draw the polygons on the control, I use the <code>FillPolygon</code> function, passing it the array of points that represent the polygon. Let&#8217;s examine the control&#8217;s <code>Paint</code> event to see exactly what&#8217;s going on:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> SevenSegment_Paint<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, PaintEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">//this will be the bit pattern that gets shown on the segments,</span>
	<span style="color: #008080; font-style: italic;">//bits 0 through 6 corresponding to each segment.</span>
	<span style="color: #FF0000;">int</span> useValue <span style="color: #008000;">=</span> customPattern<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//create brushes that represent the lit and unlit states of the segments</span>
	Brush brushLight <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidBrush<span style="color: #000000;">&#40;</span>colorLight<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	Brush brushDark <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidBrush<span style="color: #000000;">&#40;</span>colorDark<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//Define transformation for our container...</span>
	RectangleF srcRect <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RectangleF<span style="color: #000000;">&#40;</span>0.0F, 0.0F, gridWidth, gridHeight<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	RectangleF destRect <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RectangleF<span style="color: #000000;">&#40;</span>Padding.<span style="color: #0000FF;">Left</span>, Padding.<span style="color: #0000FF;">Top</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Width</span> <span style="color: #008000;">-</span> Padding.<span style="color: #0000FF;">Left</span> <span style="color: #008000;">-</span> Padding.<span style="color: #0000FF;">Right</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">-</span> Padding.<span style="color: #0000FF;">Top</span> <span style="color: #008000;">-</span> Padding.<span style="color: #0000FF;">Bottom</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//Begin graphics container that remaps coordinates for our convenience</span>
	GraphicsContainer containerState <span style="color: #008000;">=</span> e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">BeginContainer</span><span style="color: #000000;">&#40;</span>destRect, srcRect, GraphicsUnit.<span style="color: #0000FF;">Pixel</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//apply a shear transformation based on our &quot;italics&quot; coefficient</span>
	Matrix trans <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Matrix<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	trans.<span style="color: #0000FF;">Shear</span><span style="color: #000000;">&#40;</span>italicFactor, 0.0F<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">Transform</span> <span style="color: #008000;">=</span> trans<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//apply antialiasing</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">SmoothingMode</span> <span style="color: #008000;">=</span> SmoothingMode.<span style="color: #0000FF;">AntiAlias</span><span style="color: #008000;">;</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">PixelOffsetMode</span> <span style="color: #008000;">=</span> PixelOffsetMode.<span style="color: #0000FF;">Default</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// Draw elements based on whether the corresponding bit is high!</span>
	<span style="color: #008080; font-style: italic;">// &quot;segPoints&quot; is a 2D array of points that contains the segment coordinates to draw</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">FillPolygon</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>useValue <span style="color: #008000;">&amp;</span> 0x1<span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> 0x1 <span style="color: #008000;">?</span> brushLight <span style="color: #008000;">:</span> brushDark, segPoints<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">FillPolygon</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>useValue <span style="color: #008000;">&amp;</span> 0x2<span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> 0x2 <span style="color: #008000;">?</span> brushLight <span style="color: #008000;">:</span> brushDark, segPoints<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">FillPolygon</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>useValue <span style="color: #008000;">&amp;</span> 0x4<span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> 0x4 <span style="color: #008000;">?</span> brushLight <span style="color: #008000;">:</span> brushDark, segPoints<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">FillPolygon</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>useValue <span style="color: #008000;">&amp;</span> 0x8<span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> 0x8 <span style="color: #008000;">?</span> brushLight <span style="color: #008000;">:</span> brushDark, segPoints<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">3</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">FillPolygon</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>useValue <span style="color: #008000;">&amp;</span> 0x10<span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> 0x10 <span style="color: #008000;">?</span> brushLight <span style="color: #008000;">:</span> brushDark, segPoints<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">4</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">FillPolygon</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>useValue <span style="color: #008000;">&amp;</span> 0x20<span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> 0x20 <span style="color: #008000;">?</span> brushLight <span style="color: #008000;">:</span> brushDark, segPoints<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">FillPolygon</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>useValue <span style="color: #008000;">&amp;</span> 0x40<span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> 0x40 <span style="color: #008000;">?</span> brushLight <span style="color: #008000;">:</span> brushDark, segPoints<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">6</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//draw the decimal point, if it's enabled</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>showDot<span style="color: #000000;">&#41;</span>
		e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">FillEllipse</span><span style="color: #000000;">&#40;</span>dotOn <span style="color: #008000;">?</span> brushLight <span style="color: #008000;">:</span> brushDark, gridWidth <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span>, gridHeight <span style="color: #008000;">-</span> elementWidth <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span>, elementWidth, elementWidth<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//finished with coordinate container</span>
	e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">EndContainer</span><span style="color: #000000;">&#40;</span>containerState<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>You can set the value displayed in the control through two properties: <code>Value</code> and <code>CustomPattern</code>. The <code>Value</code> property is a string value that can be set to a single character such as &quot;5&quot; or &quot;A&quot;. The character will be automatically translated into the seven-segment bit pattern that looks like the specified character.</p>
<p>If you want to display a custom pattern that may or may not look like any letter or number, you can use the <code>CustomPattern</code> property, and set it to any value from 0 to 127, which gives you full control over each segment, since bits 0 to 6 control the state of each of the corresponding segments.</p>
<p>The way it&#8217;s done in the code is as follows. I have an enumeration that encodes all the predefined values that represent digits and letters displayable on seven segments:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> ValuePattern
<span style="color: #000000;">&#123;</span>
    None <span style="color: #008000;">=</span> 0x0, Zero <span style="color: #008000;">=</span> 0x77, One <span style="color: #008000;">=</span> 0x24, Two <span style="color: #008000;">=</span> 0x5D, Three <span style="color: #008000;">=</span> 0x6D,
    Four <span style="color: #008000;">=</span> 0x2E, Five <span style="color: #008000;">=</span> 0x6B, Six <span style="color: #008000;">=</span> 0x7B, Seven <span style="color: #008000;">=</span> 0x25,
    Eight <span style="color: #008000;">=</span> 0x7F, Nine <span style="color: #008000;">=</span> 0x6F, A <span style="color: #008000;">=</span> 0x3F, B <span style="color: #008000;">=</span> 0x7A, C <span style="color: #008000;">=</span> 0x53,
    D <span style="color: #008000;">=</span> 0x7C, E <span style="color: #008000;">=</span> 0x5B, F <span style="color: #008000;">=</span> 0x1B, G <span style="color: #008000;">=</span> 0x73, H <span style="color: #008000;">=</span> 0x3E,
    J <span style="color: #008000;">=</span> 0x74, L <span style="color: #008000;">=</span> 0x52, N <span style="color: #008000;">=</span> 0x38, O <span style="color: #008000;">=</span> 0x78, 
    P <span style="color: #008000;">=</span> 0x1F, Q <span style="color: #008000;">=</span> 0x2F, R <span style="color: #008000;">=</span> 0x18,
    T <span style="color: #008000;">=</span> 0x5A, U <span style="color: #008000;">=</span> 0x76, Y <span style="color: #008000;">=</span> 0x6E,
    Dash <span style="color: #008000;">=</span> 0x8, Equals <span style="color: #008000;">=</span> 0x48
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Notice that each value is a bit map, with each bit corresponding to one of the seven segments. Now, in the <code>set</code>ter of the Value property, I compare the given character against our known values, and use the corresponding enumeration as the currently displayed bit pattern:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//is it a digit?</span>
<span style="color: #FF0000;">int</span> tempValue <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>tempValue<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">case</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">:</span> customPattern <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>ValuePattern.<span style="color: #0000FF;">Zero</span><span style="color: #008000;">;</span> break<span style="color: #008000;">;</span>
	<span style="color: #0600FF;">case</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">:</span> customPattern <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>ValuePattern.<span style="color: #0000FF;">One</span><span style="color: #008000;">;</span> break<span style="color: #008000;">;</span>
	...
<span style="color: #000000;">&#125;</span>
...
<span style="color: #008080; font-style: italic;">//is it a letter?</span>
<span style="color: #FF0000;">string</span> tempString <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span>value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>tempString.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">case</span> <span style="color: #666666;">'a'</span><span style="color: #008000;">:</span> customPattern <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>ValuePattern.<span style="color: #0000FF;">A</span><span style="color: #008000;">;</span> break<span style="color: #008000;">;</span>
	<span style="color: #0600FF;">case</span> <span style="color: #666666;">'b'</span><span style="color: #008000;">:</span> customPattern <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>ValuePattern.<span style="color: #0000FF;">B</span><span style="color: #008000;">;</span> break<span style="color: #008000;">;</span>
	...
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Either way, the bit pattern to be displayed in the control ends up in the <code>customPattern</code> variable, which is then used in the <code>Paint</code> event as shown above.</p>
<p>You can also &quot;italicize&quot; the display by manipulating the <code>ItalicFactor</code> property. This value is simply a shear factor that gets applied when drawing the control, as seen in the <code>Paint</code> event. An italic factor of -0.1 makes the display look just slightly slanted, and a whole lot more professional.</p>
<p>If you begin noticing that the segments are being drawn outside the boundary of the control (perhaps from too much italicizing), you can use the <code>Padding</code> property and increase the left/right/top/bottom padding until all of the shapes are within the control&#8217;s client rectangle.</p>
<p>The control has several other convenient properties for you to play with, such as the background color, the enabled and disabled color for the segments, and the thickness of the segments.</p>
<h3>Seven-segment array</h3>
<p>In addition to the seven-segment control itself, I&#8217;m throwing in another control which is an <em>array</em> of seven-segment displays. This allows you to display entire strings on an array of 7-seg displays. Check out the demo application, and dig around the source code to see how it&#8217;s used; it&#8217;s really simple.</p>
<p>To use the array control, include the &quot;SevenSegmentArray.cs&quot; file in your project and rebuild. You&#8217;ll then be able to select the <code>SevenSegmentArray</code> control from the tool palette.</p>
<p>This control has an <code>ArrayCount</code> property that specifies the number of 7-seg displays in the array, as well as a <code>Value</code> property that takes any <code>string</code> to be displayed on the array. Easy, right?</p>
<h3>Other thoughts</h3>
<p>I must say I had a lot of fun writing this control, and .NET helped put a lot of the fun into it by making it incredibly easy to draw your own shapes, transform coordinates, and introduce truly powerful properties.</p>
<p>Also, coming from somewhat of an electronics background, for me, seeing this control brings a certain nostalgia for simpler times. I hope you enjoy it.</p>
<ul>
<li>See <a href="http://www.codeproject.com/KB/static/sevensegmentdisplay.aspx">this article at CodeProject</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/07/01/seven-segment-display-for-dot-net/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Star Photos at Machu Picchu</title>
		<link>http://dmitrybrant.com/2009/06/29/star-photos-at-machu-picchu</link>
		<comments>http://dmitrybrant.com/2009/06/29/star-photos-at-machu-picchu#comments</comments>
		<pubDate>Mon, 29 Jun 2009 23:54:06 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Daily Events]]></category>
		<category><![CDATA[Photos]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=565</guid>
		<description><![CDATA[Early in the morning on our way to Machu Picchu, I was able to take a few stunning sky photos. This was done by simply putting the camera on the ground, and setting the exposure to 30 seconds. Here are the photos, followed by copies of the photos that I&#8217;ve annotated with constellation names and [...]]]></description>
			<content:encoded><![CDATA[<p>Early in the morning on our way to Machu Picchu, I was able to take a few stunning sky photos. This was done by simply putting the camera on the ground, and setting the exposure to 30 seconds. Here are the photos, followed by copies of the photos that I&#8217;ve annotated with constellation names and lines.</p>

<div class="ngg-galleryoverview" id="ngg-gallery-13-565">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-1649" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/29/star-photos-at-machu-picchu?pid=1649" title=" "  >
								<img title="DSC_0664" alt="DSC_0664" src="http://dmitrybrant.com/wp-content/gallery/inkastars/thumbs/thumbs_DSC_0664.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1651" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/29/star-photos-at-machu-picchu?pid=1651" title=" "  >
								<img title="DSC_0665" alt="DSC_0665" src="http://dmitrybrant.com/wp-content/gallery/inkastars/thumbs/thumbs_DSC_0665.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1647" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/29/star-photos-at-machu-picchu?pid=1647" title=" "  >
								<img title="DSC_0004" alt="DSC_0004" src="http://dmitrybrant.com/wp-content/gallery/inkastars/thumbs/thumbs_DSC_0004.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-1650" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/29/star-photos-at-machu-picchu?pid=1650" title=" "  >
								<img title="DSC_0664a" alt="DSC_0664a" src="http://dmitrybrant.com/wp-content/gallery/inkastars/thumbs/thumbs_DSC_0664a.jpg"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1652" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/29/star-photos-at-machu-picchu?pid=1652" title=" "  >
								<img title="DSC_0665a" alt="DSC_0665a" src="http://dmitrybrant.com/wp-content/gallery/inkastars/thumbs/thumbs_DSC_0665a.jpg"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-1648" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/29/star-photos-at-machu-picchu?pid=1648" title=" "  >
								<img title="DSC_0004a" alt="DSC_0004a" src="http://dmitrybrant.com/wp-content/gallery/inkastars/thumbs/thumbs_DSC_0004a.jpg"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>


]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/06/29/star-photos-at-machu-picchu/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inca Trail and Machu Picchu, Part 4</title>
		<link>http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4</link>
		<comments>http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4#comments</comments>
		<pubDate>Mon, 29 Jun 2009 00:38:02 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Daily Events]]></category>
		<category><![CDATA[Photos]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=534</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[
<div class="ngg-galleryoverview" id="ngg-gallery-5-534">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-931" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=931" title=" "  >
								<img title="DSC_0001" alt="DSC_0001" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0001.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-932" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=932" title=" "  >
								<img title="DSC_0004" alt="DSC_0004" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0004.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-933" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=933" title=" "  >
								<img title="DSC_0005" alt="DSC_0005" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0005.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-934" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=934" title=" "  >
								<img title="DSC_0007" alt="DSC_0007" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0007.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-935" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=935" title=" "  >
								<img title="DSC_0009" alt="DSC_0009" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0009.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-936" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=936" title=" "  >
								<img title="DSC_0012" alt="DSC_0012" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0012.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-937" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=937" title=" "  >
								<img title="DSC_0013" alt="DSC_0013" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0013.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-938" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=938" title=" "  >
								<img title="DSC_0015" alt="DSC_0015" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0015.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-939" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=939" title=" "  >
								<img title="DSC_0016" alt="DSC_0016" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0016.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-940" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=940" title=" "  >
								<img title="DSC_0017" alt="DSC_0017" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0017.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-941" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=941" title=" "  >
								<img title="DSC_0019" alt="DSC_0019" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0019.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-942" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=942" title=" "  >
								<img title="DSC_0021" alt="DSC_0021" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0021.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-943" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=943" title=" "  >
								<img title="DSC_0023" alt="DSC_0023" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0023.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-944" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=944" title=" "  >
								<img title="DSC_0026" alt="DSC_0026" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0026.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-945" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=945" title=" "  >
								<img title="DSC_0027" alt="DSC_0027" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0027.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-946" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=946" title=" "  >
								<img title="DSC_0029" alt="DSC_0029" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0029.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-947" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=947" title=" "  >
								<img title="DSC_0032" alt="DSC_0032" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0032.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-948" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=948" title=" "  >
								<img title="DSC_0034" alt="DSC_0034" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0034.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-949" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=949" title=" "  >
								<img title="DSC_0035" alt="DSC_0035" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0035.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-950" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?pid=950" title=" "  >
								<img title="DSC_0038" alt="DSC_0038" src="http://dmitrybrant.com/wp-content/gallery/inkatrail4/thumbs/thumbs_DSC_0038.JPG"  />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-navigation'><span>1</span><a class="page-numbers" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?nggpage=2">2</a><a class="page-numbers" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?nggpage=3">3</a><a class="page-numbers" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?nggpage=4">4</a><a class="page-numbers" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?nggpage=5">5</a><a class="page-numbers" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?nggpage=6">6</a><a class="page-numbers" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?nggpage=7">7</a><a class="next" id="ngg-next-2" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4?nggpage=2">&#9658;</a></div> 	
</div>


]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inca Trail and Machu Picchu, Part 3</title>
		<link>http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3</link>
		<comments>http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3#comments</comments>
		<pubDate>Mon, 29 Jun 2009 00:35:30 +0000</pubDate>
		<dc:creator>db</dc:creator>
				<category><![CDATA[Daily Events]]></category>
		<category><![CDATA[Photos]]></category>

		<guid isPermaLink="false">http://dmitrybrant.com/?p=531</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[
<div class="ngg-galleryoverview" id="ngg-gallery-4-531">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-853" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=853" title=" "  >
								<img title="DSC_0001" alt="DSC_0001" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0001.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-854" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=854" title=" "  >
								<img title="DSC_0002" alt="DSC_0002" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0002.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-855" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=855" title=" "  >
								<img title="DSC_0005" alt="DSC_0005" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0005.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-856" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=856" title=" "  >
								<img title="DSC_0006" alt="DSC_0006" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0006.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-857" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=857" title=" "  >
								<img title="DSC_0007" alt="DSC_0007" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0007.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-858" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=858" title=" "  >
								<img title="DSC_0010" alt="DSC_0010" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0010.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-859" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=859" title=" "  >
								<img title="DSC_0013" alt="DSC_0013" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0013.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-860" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=860" title=" "  >
								<img title="DSC_0017" alt="DSC_0017" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0017.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-861" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=861" title=" "  >
								<img title="DSC_0021" alt="DSC_0021" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0021.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-862" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=862" title=" "  >
								<img title="DSC_0023" alt="DSC_0023" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0023.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-863" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=863" title=" "  >
								<img title="DSC_0024" alt="DSC_0024" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0024.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-864" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=864" title=" "  >
								<img title="DSC_0025" alt="DSC_0025" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0025.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-865" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=865" title=" "  >
								<img title="DSC_0026" alt="DSC_0026" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0026.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-866" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=866" title=" "  >
								<img title="DSC_0028" alt="DSC_0028" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0028.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-867" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=867" title=" "  >
								<img title="DSC_0029" alt="DSC_0029" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0029.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-868" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=868" title=" "  >
								<img title="DSC_0031" alt="DSC_0031" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0031.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-869" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=869" title=" "  >
								<img title="DSC_0033" alt="DSC_0033" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0033.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-870" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=870" title=" "  >
								<img title="DSC_0043" alt="DSC_0043" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0043.JPG"  />
							</a>
		</div>
	</div>
	
				<br style="clear: both" />
	
 		
	<div id="ngg-image-871" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=871" title=" "  >
								<img title="DSC_0045" alt="DSC_0045" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0045.JPG"  />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-872" class="ngg-gallery-thumbnail-box" style="width:33%;" >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?pid=872" title=" "  >
								<img title="DSC_0046" alt="DSC_0046" src="http://dmitrybrant.com/wp-content/gallery/inkatrail3/thumbs/thumbs_DSC_0046.JPG"  />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-navigation'><span>1</span><a class="page-numbers" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?nggpage=2">2</a><a class="page-numbers" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?nggpage=3">3</a><a class="page-numbers" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?nggpage=4">4</a><a class="next" id="ngg-next-2" href="http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3?nggpage=2">&#9658;</a></div> 	
</div>


]]></content:encoded>
			<wfw:commentRss>http://dmitrybrant.com/2009/06/28/inca-trail-and-machu-picchu-part-3/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
