<?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>Joe Doliner</title>
	<atom:link href="http://joedoliner.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://joedoliner.com</link>
	<description></description>
	<lastBuildDate>Fri, 04 Feb 2011 07:58:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Ray Tracer: Reflection and Transparency</title>
		<link>http://joedoliner.com/2011/02/04/ray-tracer-reflection-and-transparency/</link>
		<comments>http://joedoliner.com/2011/02/04/ray-tracer-reflection-and-transparency/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 07:58:42 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=217</guid>
		<description><![CDATA[Next up are transparency and reflection. In keeping with the them: we get these by first adding more information to the Ray Paths and then writing shaders that leverage this new information. Recall that Ray Paths contain information about how a ray from the camera travels through the scene, currently it just records what it [...]]]></description>
			<content:encoded><![CDATA[<p>
Next up are transparency and reflection. In keeping with the them: we get these by first adding more information to the Ray Paths and then writing shaders that leverage this new information. Recall that Ray Paths contain information about how a ray from the camera travels through the scene, currently it just records what it hits and how that point is illuminated. To that we&#8217;ll be adding a Ray Path for the ray constructed by reflecting the incoming ray over the intersections normal and a Ray Path for if the ray continued going through the object. Here&#8217;s the new Ray Path:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Ray<span style="color: #339933; font-weight: bold;">_</span>Path <span style="color: #339933; font-weight: bold;">=</span> Ray<span style="color: #339933; font-weight: bold;">_</span>Path <span style="color: green;">&#123;</span>hit <span style="color: #339933; font-weight: bold;">::</span> Intersection<span style="color: #339933; font-weight: bold;">,</span> 
                          ref <span style="color: #339933; font-weight: bold;">::</span> Ray<span style="color: #339933; font-weight: bold;">_</span>Path<span style="color: #339933; font-weight: bold;">,</span> 
                          thru <span style="color: #339933; font-weight: bold;">::</span> Ray<span style="color: #339933; font-weight: bold;">_</span>Path<span style="color: #339933; font-weight: bold;">,</span> 
                          light<span style="color: #339933; font-weight: bold;">_</span>hits <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>Light<span style="color: #339933; font-weight: bold;">_</span>Castback<span style="color: green;">&#93;</span><span style="color: green;">&#125;</span></pre></div></div>

</p>
<p>
Now we have the data in the Ray Paths, we need to write some shaders that use them:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">shader<span style="color: #339933; font-weight: bold;">_</span>lit<span style="color: #339933; font-weight: bold;">_</span>red<span style="color: #339933; font-weight: bold;">_</span>ref <span style="color: #339933; font-weight: bold;">::</span> Shader
shader<span style="color: #339933; font-weight: bold;">_</span>lit<span style="color: #339933; font-weight: bold;">_</span>red<span style="color: #339933; font-weight: bold;">_</span>ref depth rp 
    <span style="color: #339933; font-weight: bold;">|</span> depth <span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: red;">10</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">|</span> <span style="font-weight: bold;">otherwise</span> <span style="color: #339933; font-weight: bold;">=</span> blend <span style="color: green;">&#91;</span><span style="color: red;">0.7</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0.3</span><span style="color: green;">&#93;</span> 
                        <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>shader<span style="color: #339933; font-weight: bold;">_</span>lit<span style="color: #339933; font-weight: bold;">_</span>red depth rp<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>shade <span style="color: green;">&#40;</span>depth <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>ref rp<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#93;</span></pre></div></div>

<p>What this does is blend (a weighted average) the color we would get if we just did a simple diffuse shading with a red color and the color we get from the reflection. Notice that we&#8217;ve needed to add a counter for the depth to occur the infinite recursion you&#8217;d get if you held 2 mirrors up facing each other. This shader is the same idea but blends both the reflected and the through ray:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">glass <span style="color: #339933; font-weight: bold;">::</span> Shader
glass depth rp 
    <span style="color: #339933; font-weight: bold;">|</span> depth <span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: red;">10</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">|</span> <span style="font-weight: bold;">otherwise</span> <span style="color: #339933; font-weight: bold;">=</span> blend <span style="color: green;">&#91;</span><span style="color: red;">0.2</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0.4</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0.4</span><span style="color: green;">&#93;</span> 
                        <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>shader<span style="color: #339933; font-weight: bold;">_</span>lit<span style="color: #339933; font-weight: bold;">_</span>grey depth rp<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>shade <span style="color: green;">&#40;</span>depth <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span><span style="color: green;">&#40;</span>ref rp<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>shade <span style="color: green;">&#40;</span>depth <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>thru rp<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#93;</span></pre></div></div>

<p>And here&#8217;s an image of a reflective red plane with a glass sphere (which really doesn&#8217;t look much like glass) on it:<br />
<div id="attachment_222" class="wp-caption aligncenter" style="width: 310px"><a href="http://joedoliner.com/wp-content/uploads/2011/02/ref.png"><img src="http://joedoliner.com/wp-content/uploads/2011/02/ref-300x300.png" alt="" title="Reflection and transparency." width="300" height="300" class="size-medium wp-image-222" /></a><p class="wp-caption-text">A reflective transparent sphere sitting on a reflective plane.</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2011/02/04/ray-tracer-reflection-and-transparency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ray Tracing: Shadows</title>
		<link>http://joedoliner.com/2011/01/30/ray-tracing-shadows/</link>
		<comments>http://joedoliner.com/2011/01/30/ray-tracing-shadows/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 03:12:00 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=201</guid>
		<description><![CDATA[Shadows are the first place where ray tracing has an advantage pipelined graphics (OpenGL). Not that shadows in pipelined graphics are impossible, but they can be a bit of a struggle (or at least they have been for me.) But as we&#8217;ll see: with ray tracing they&#8217;re actually quite pleasant. We actually already have everything [...]]]></description>
			<content:encoded><![CDATA[<p>Shadows are the first place where ray tracing has an advantage pipelined graphics (OpenGL). Not that shadows in pipelined graphics are impossible, but they can be a bit of a struggle (or at least they have been for me.) But as we&#8217;ll see: with ray tracing they&#8217;re actually quite pleasant.</p>
<p>We actually already have everything we need with the castback idea; we just need to extend them a bit so that we give shaders empty castbacks when the path to the light is blocked. What&#8217;s great is that we already have exactly that function built in, it&#8217;s the same function we use to intersect the scene. Here&#8217;s what the castback construction code looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">light<span style="color: #339933; font-weight: bold;">_</span>castback <span style="color: #339933; font-weight: bold;">::</span> Scene <span style="color: #339933; font-weight: bold;">-&gt;</span> Intersection <span style="color: #339933; font-weight: bold;">-&gt;</span> Light <span style="color: #339933; font-weight: bold;">-&gt;</span> Light<span style="color: #339933; font-weight: bold;">_</span>Castback
light<span style="color: #339933; font-weight: bold;">_</span>castback scene <span style="color: green;">&#40;</span>Intersection <span style="color: #339933; font-weight: bold;">_</span> inter<span style="color: #339933; font-weight: bold;">_</span>loc <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>Point light<span style="color: #339933; font-weight: bold;">_</span>loc color intensity<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span>
    <span style="color: #06c; font-weight: bold;">if</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>miss scene<span style="color: #339933; font-weight: bold;">_</span>xn<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">||</span> light<span style="color: #339933; font-weight: bold;">_</span>t <span style="color: #339933; font-weight: bold;">&lt;</span> <span style="color: green;">&#40;</span>t scene<span style="color: #339933; font-weight: bold;">_</span>xn<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">then</span> <span style="color: green;">&#40;</span>Light<span style="color: #339933; font-weight: bold;">_</span>Castback <span style="color: green;">&#40;</span>light<span style="color: #339933; font-weight: bold;">_</span>loc <span style="color: #339933; font-weight: bold;">&lt;-&gt;</span> inter<span style="color: #339933; font-weight: bold;">_</span>loc<span style="color: green;">&#41;</span> color intensity<span style="color: green;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">else</span> empty<span style="color: #339933; font-weight: bold;">_</span>light<span style="color: #339933; font-weight: bold;">_</span>castback
&nbsp;
    <span style="color: #06c; font-weight: bold;">where</span> ray <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>ray<span style="color: #339933; font-weight: bold;">_</span>from<span style="color: #339933; font-weight: bold;">_</span>to inter<span style="color: #339933; font-weight: bold;">_</span>loc light<span style="color: #339933; font-weight: bold;">_</span>loc<span style="color: green;">&#41;</span>
          scene<span style="color: #339933; font-weight: bold;">_</span>xn <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>intersect<span style="color: #339933; font-weight: bold;">_</span>scene scene ray<span style="color: green;">&#41;</span> <span style="color: #5d478b; font-style: italic;">--intersection with the scene</span>
          light<span style="color: #339933; font-weight: bold;">_</span>dir <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>light<span style="color: #339933; font-weight: bold;">_</span>loc <span style="color: #339933; font-weight: bold;">&lt;-&gt;</span> inter<span style="color: #339933; font-weight: bold;">_</span>loc<span style="color: green;">&#41;</span>
          light<span style="color: #339933; font-weight: bold;">_</span>t <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>len light<span style="color: #339933; font-weight: bold;">_</span>dir<span style="color: green;">&#41;</span> <span style="color: #5d478b; font-style: italic;">--parameter at which we hit the light</span></pre></div></div>

<p>Simple enough: we intersect with the scene and if the intersection is closer the to castbacks origin than the light we&#8217;re aiming at, we have an empty castback. So let&#8217;s see how it works:</p>
<div id="attachment_203" class="wp-caption aligncenter" style="width: 310px"><a href="http://joedoliner.com/wp-content/uploads/2011/01/surface_acne_sphere_plane.png"><img src="http://joedoliner.com/wp-content/uploads/2011/01/surface_acne_sphere_plane-300x300.png" alt="" title="Surface Acne" width="300" height="300" class="size-medium wp-image-203" /></a><p class="wp-caption-text">Something is very wrong.</p></div>
<p>Hmm, not so well at all, although that is a cool looking bug. This type of effect is generally called surface acne and it&#8217;s normally down to a floating point error somewhere. In this case the problem is that the castback ray that I shoot out is, depending on roundoff errors, hitting or missing the object whose illumination we&#8217;re computing (the object it originally hit.) The easiest way to solve this is to just nudge the ray&#8217;s origin points off of the objects they&#8217;re intersecting using a function like this:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">epsilon <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: red;">10</span> <span style="color: #339933; font-weight: bold;">**</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">4</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
&nbsp;
nudge <span style="color: #339933; font-weight: bold;">::</span> Ray <span style="color: #339933; font-weight: bold;">-&gt;</span> Ray
nudge ray <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>Ray <span style="color: green;">&#40;</span>ray `at` epsilon<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>dir ray<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span></pre></div></div>

<div id="attachment_204" class="wp-caption aligncenter" style="width: 310px"><a href="http://joedoliner.com/wp-content/uploads/2011/01/sphere-plane.png"><img src="http://joedoliner.com/wp-content/uploads/2011/01/sphere-plane-300x300.png" alt="" title="sphere-plane" width="300" height="300" class="size-medium wp-image-204" /></a><p class="wp-caption-text">Bug fixed.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2011/01/30/ray-tracing-shadows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ray Tracer: Lighting (Part 1)</title>
		<link>http://joedoliner.com/2011/01/24/ray-tracer-lighting-part-1/</link>
		<comments>http://joedoliner.com/2011/01/24/ray-tracer-lighting-part-1/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 09:11:30 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=173</guid>
		<description><![CDATA[Up until now I&#8217;ve been cheating in creating images (although cheating is really the point of graphics). As we all know there can be no images without light so let&#8217;s add some. First off we need a few structures to represent our lights: data Light = Point &#123;loc :: Vec3f, color :: Color, intensity :: [...]]]></description>
			<content:encoded><![CDATA[<p>
Up until now I&#8217;ve been cheating in creating images (although cheating is really the point of graphics). As we all know there can be no images without light so let&#8217;s add some. First off we need a few structures to represent our lights:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Light <span style="color: #339933; font-weight: bold;">=</span> Point <span style="color: green;">&#123;</span>loc <span style="color: #339933; font-weight: bold;">::</span> Vec3f<span style="color: #339933; font-weight: bold;">,</span> 
                    color <span style="color: #339933; font-weight: bold;">::</span> Color<span style="color: #339933; font-weight: bold;">,</span> 
                    intensity <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Float</span><span style="color: green;">&#125;</span> <span style="color: #339933; font-weight: bold;">|</span>
             Spot <span style="color: green;">&#123;</span>loc <span style="color: #339933; font-weight: bold;">::</span> Vec3f<span style="color: #339933; font-weight: bold;">,</span> 
                   look<span style="color: #339933; font-weight: bold;">_</span>at <span style="color: #339933; font-weight: bold;">::</span> Vec3f<span style="color: #339933; font-weight: bold;">,</span> 
                   color <span style="color: #339933; font-weight: bold;">::</span> Color<span style="color: #339933; font-weight: bold;">,</span> 
                   angle <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Float</span><span style="color: #339933; font-weight: bold;">,</span> 
                   intensity <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Float</span><span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span></pre></div></div>

<p>A point light is the simplest light, it simply shines light in every direction from a single point. A spot light is a little more complicated: it shines light in a cone (like a spotlight).
</p>
<p>
So now what can we do with these things? In an ideal world we would do with them exactly what the real world does with them: We would simulate lightrays spraying out of them bouncing around the scene and eventually entering our simulated camera. However a randomly shot lightray has a very small chance of making it to the camera so it&#8217;s computationally infeasible to start from the lights and make our way to the cameras. So we do exactly the opposite, we start from the Camera and anytime we hit a solid we try to find the lights that this ray could have started from. And we call what we find &#8220;Light castbacks&#8221;
</p>
<div id="attachment_177" class="wp-caption aligncenter" style="width: 310px"><a href="http://joedoliner.com/wp-content/uploads/2011/01/camera.jpg"><img src="http://joedoliner.com/wp-content/uploads/2011/01/camera-300x186.jpg" alt="" title="camera" width="300" height="186" class="size-medium wp-image-177" /></a><p class="wp-caption-text">Where castbacks come from</p></div>
<p>
Light castbacks are an extra piece of information that we can pass in to our shaders; they look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Light<span style="color: #339933; font-weight: bold;">_</span>Castback <span style="color: #339933; font-weight: bold;">=</span> Light<span style="color: #339933; font-weight: bold;">_</span>Castback <span style="color: green;">&#123;</span>dir <span style="color: #339933; font-weight: bold;">::</span> Vec3f<span style="color: #339933; font-weight: bold;">,</span> 
                                      color <span style="color: #339933; font-weight: bold;">::</span> Color<span style="color: #339933; font-weight: bold;">,</span> 
                                      intensity <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Float</span><span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span></pre></div></div>

<p>With these things we have everything we need to implement some basic lighting. Here&#8217;s what the shader looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">shader<span style="color: #339933; font-weight: bold;">_</span>lit <span style="color: #339933; font-weight: bold;">::</span> Shader
shader<span style="color: #339933; font-weight: bold;">_</span>lit <span style="color: green;">&#40;</span>Ray<span style="color: #339933; font-weight: bold;">_</span>Path <span style="color: green;">&#40;</span>Intersection <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> norm <span style="color: #339933; font-weight: bold;">_</span> False<span style="color: green;">&#41;</span> cbs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>clamp <span style="color: red;">0</span> <span style="color: red;">255</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">floor</span> <span style="color: green;">&#40;</span><span style="color: red;">220</span> <span style="color: #339933; font-weight: bold;">*</span> <span style="font-weight: bold;">foldr</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">+</span><span style="color: green;">&#41;</span> <span style="color: red;">0</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>\x <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>normed norm<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;.&gt;</span> <span style="color: green;">&#40;</span>normed <span style="color: green;">&#40;</span>dir x<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> cbs<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;*&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;+&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">35</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">35</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">35</span><span style="color: green;">&#41;</span></pre></div></div>

<p>What this does is take all the castbacks from the scene and compute the dot product of the direction of the light and the normal of the surface (clamping it to within an acceptable range and boosting it to a minimum (hacky way to make there be some ambient lighting.) The fruits:<br />
<div id="attachment_178" class="wp-caption aligncenter" style="width: 310px"><a href="http://joedoliner.com/wp-content/uploads/2011/01/lit.png"><img src="http://joedoliner.com/wp-content/uploads/2011/01/lit-300x300.png" alt="" title="lit" width="300" height="300" class="size-medium wp-image-178" /></a><p class="wp-caption-text">Diffuse Lighting</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2011/01/24/ray-tracer-lighting-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ray Tracer: Shaders</title>
		<link>http://joedoliner.com/2011/01/18/ray-tracer-shaders/</link>
		<comments>http://joedoliner.com/2011/01/18/ray-tracer-shaders/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 10:04:39 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Ray Tracer]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=163</guid>
		<description><![CDATA[Now that we can get intersections from our solids, we&#8217;re almost ready to start producing some images. We still need two things: first we need a little bit more information about the surrounding world and second we need a way to convert this information to color. For the more information we&#8217;ll introduce a Ray_Path which [...]]]></description>
			<content:encoded><![CDATA[<p>
Now that we can get intersections from our solids, we&#8217;re almost ready to start producing some images. We still need two things: first we need a little bit more information about the surrounding world and second we need a way to convert this information to color.
</p>
<p>
For the more information we&#8217;ll introduce a Ray_Path which looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Ray<span style="color: #339933; font-weight: bold;">_</span>Path <span style="color: #339933; font-weight: bold;">=</span> Ray<span style="color: #339933; font-weight: bold;">_</span>Path <span style="color: green;">&#123;</span>hit <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Maybe</span> Intersection<span style="color: #339933; font-weight: bold;">,</span> light<span style="color: #339933; font-weight: bold;">_</span>hits <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#91;</span>Light<span style="color: #339933; font-weight: bold;">_</span>Castback<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> shader <span style="color: #339933; font-weight: bold;">::</span> Shader<span style="color: green;">&#125;</span></pre></div></div>

<p>A Ray_Path gives us everything we need to understand how a ray travelled through our scene (things will have to be added to what we have right now) and convert that to color. The hit field is just an intersection from the previous post. The light_hits contain Light_Castbacks which I&#8217;m not going to define just yet&#8211;they&#8217;ll be covered in a post called &#8220;Lighting&#8221;&#8211;for now let it suffice to say that a Light_Castback will tell you everything you need to know about how this ray interacted with the lights in the scene. However we are going to talk about the shader. Shaders are the second thing we need, they&#8217;re a way to convert a Ray_Path into color. In case you don&#8217;t trust me, here&#8217;s the type signature:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">type</span> Shader <span style="color: #339933; font-weight: bold;">=</span> Ray<span style="color: #339933; font-weight: bold;">_</span>Path <span style="color: #339933; font-weight: bold;">-&gt;</span> Color</pre></div></div>

<p>Shaders are a pretty pervasive idea in graphics, and eventually I&#8217;m going to implement a full blown shader language. However for right now they&#8217;re just described in terms of a Haskell function.
</p>
<p>
This is all we need to start doing some really simple ray tracing, so here it is: this is a simple scene with a single sphere and a shader attached to it that always returns red. Nothing too fancy, but it proves that everything underneath the hood is working:<br />
<div id="attachment_164" class="wp-caption aligncenter" style="width: 310px"><a href="http://joedoliner.com/wp-content/uploads/2011/01/sphere.png"><img src="http://joedoliner.com/wp-content/uploads/2011/01/sphere-300x300.png" alt="" title="First render: a simple sphere" width="300" height="300" class="size-medium wp-image-164" /></a><p class="wp-caption-text">The first render.</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2011/01/18/ray-tracer-shaders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ray Tracer: Geometry</title>
		<link>http://joedoliner.com/2011/01/18/ray-tracer-geometry/</link>
		<comments>http://joedoliner.com/2011/01/18/ray-tracer-geometry/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 09:00:29 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Ray Tracer]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=151</guid>
		<description><![CDATA[The first thing we&#8217;re going to need is some geometry to shoot our rays at: class Solid a where intersect :: Ray -&#62; a -&#62; Maybe Intersection Basically something is a solid if we can shoot rays at it and possibly get back an Intersection (we may miss and not get back an intersection). An [...]]]></description>
			<content:encoded><![CDATA[<p>
The first thing we&#8217;re going to need is some geometry to shoot our rays at:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">class</span> Solid a <span style="color: #06c; font-weight: bold;">where</span>
    intersect <span style="color: #339933; font-weight: bold;">::</span> Ray <span style="color: #339933; font-weight: bold;">-&gt;</span> a <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Maybe</span> Intersection</pre></div></div>

<p>Basically something is a solid if we can shoot rays at it and possibly get back an Intersection (we may miss and not get back an intersection).
</p>
<p>
An Intersection is just what a record of a Ray hitting a Solid, defined as:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Intersection <span style="color: #339933; font-weight: bold;">=</span> Intersection <span style="color: green;">&#123;</span>t <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Float</span><span style="color: #339933; font-weight: bold;">,</span> loc <span style="color: #339933; font-weight: bold;">::</span> Vec3f<span style="color: #339933; font-weight: bold;">,</span> normal <span style="color: #339933; font-weight: bold;">::</span> Vec3f<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span></pre></div></div>

<p>Right now it only records the parameter of the ray, the location of the intersection and the normal. We&#8217;re going to need to extend that to get more sophisticated effects but we can get some simple stuff going with this.
</p>
<p>
Now that we have that we can implement our first actual primitive solid, a sphere:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Sphere <span style="color: #339933; font-weight: bold;">=</span> Sphere Vec3f <span style="color: #cccc00; font-weight: bold;">Float</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">instance</span> Solid Sphere <span style="color: #06c; font-weight: bold;">where</span>
    intersect <span style="color: green;">&#40;</span>Ray p0 d<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>Sphere c r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> t <span style="color: #06c; font-weight: bold;">of</span>
        Nothing <span style="color: #339933; font-weight: bold;">-&gt;</span> Nothing
        Just s <span style="color: #339933; font-weight: bold;">-&gt;</span> Just <span style="color: green;">&#40;</span>Intersection s pt <span style="color: green;">&#40;</span>normed <span style="color: green;">&#40;</span>pt <span style="color: #339933; font-weight: bold;">&lt;-&gt;</span> c<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
            <span style="color: #06c; font-weight: bold;">where</span> pt <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>at <span style="color: green;">&#40;</span>Ray p0 d<span style="color: green;">&#41;</span> s<span style="color: green;">&#41;</span>
        <span style="color: #06c; font-weight: bold;">where</span> t <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>min<span style="color: #339933; font-weight: bold;">_</span>over<span style="color: #339933; font-weight: bold;">_</span>zero <span style="color: green;">&#40;</span>real<span style="color: #339933; font-weight: bold;">_</span>quadratic <span style="color: green;">&#40;</span>d <span style="color: #339933; font-weight: bold;">&lt;.&gt;</span> d<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">2</span> <span style="color: #339933; font-weight: bold;">&lt;*&gt;</span> d<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;.&gt;</span> <span style="color: green;">&#40;</span>p0 <span style="color: #339933; font-weight: bold;">&lt;-&gt;</span> c<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>p0 <span style="color: #339933; font-weight: bold;">&lt;-&gt;</span> c<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;.&gt;</span> <span style="color: green;">&#40;</span>p0 <span style="color: #339933; font-weight: bold;">&lt;-&gt;</span> c<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-</span> r <span style="color: #339933; font-weight: bold;">^</span> <span style="color: red;">2</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2011/01/18/ray-tracer-geometry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ray Tracer: Vector Module</title>
		<link>http://joedoliner.com/2011/01/15/vector-module/</link>
		<comments>http://joedoliner.com/2011/01/15/vector-module/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 06:04:14 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Ray Tracer]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=131</guid>
		<description><![CDATA[The is going to be some of the most used code and it&#8217;s going to be a hot spot for bugs. A nice thing that Haskell does is make it very easy to define your own infix operators this should help a lot to keep things readable. Here&#8217;s the code: module Vector &#40;Vec3f, Color, &#40;&#60;+&#62;&#41;, [...]]]></description>
			<content:encoded><![CDATA[<p>The is going to be some of the most used code and it&#8217;s going to be a hot spot for bugs. A nice thing that Haskell does is make it very easy to define your own infix operators this should help a lot to keep things readable. Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Vector <span style="color: green;">&#40;</span>Vec3f<span style="color: #339933; font-weight: bold;">,</span> Color<span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;+&gt;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;-&gt;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;*&gt;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;/&gt;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;.&gt;</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> x<span style="color: #339933; font-weight: bold;">,</span> len<span style="color: #339933; font-weight: bold;">,</span> normed<span style="color: #339933; font-weight: bold;">,</span> Ray<span style="color: green;">&#40;</span>Ray<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> at<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">--general purpose 3 field vector</span>
<span style="color: #06c; font-weight: bold;">type</span> Vec3 a <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>a<span style="color: #339933; font-weight: bold;">,</span> a<span style="color: #339933; font-weight: bold;">,</span> a<span style="color: green;">&#41;</span>
&nbsp;
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;+&gt;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;+&gt;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>x1<span style="color: #339933; font-weight: bold;">,</span>y1<span style="color: #339933; font-weight: bold;">,</span>z1<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>x2<span style="color: #339933; font-weight: bold;">,</span>y2<span style="color: #339933; font-weight: bold;">,</span>z2<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>x1 <span style="color: #339933; font-weight: bold;">+</span> x2<span style="color: #339933; font-weight: bold;">,</span> y1 <span style="color: #339933; font-weight: bold;">+</span> y2<span style="color: #339933; font-weight: bold;">,</span> z1 <span style="color: #339933; font-weight: bold;">+</span> z2<span style="color: green;">&#41;</span> 
&nbsp;
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;-&gt;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;-&gt;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>x1<span style="color: #339933; font-weight: bold;">,</span>y1<span style="color: #339933; font-weight: bold;">,</span>z1<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>x2<span style="color: #339933; font-weight: bold;">,</span>y2<span style="color: #339933; font-weight: bold;">,</span>z2<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>x1 <span style="color: #339933; font-weight: bold;">-</span> x2<span style="color: #339933; font-weight: bold;">,</span> y1 <span style="color: #339933; font-weight: bold;">-</span> y2<span style="color: #339933; font-weight: bold;">,</span> z1 <span style="color: #339933; font-weight: bold;">-</span> z2<span style="color: green;">&#41;</span> 
&nbsp;
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;*&gt;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;*&gt;</span><span style="color: green;">&#41;</span> r <span style="color: green;">&#40;</span>x<span style="color: #339933; font-weight: bold;">,</span>y<span style="color: #339933; font-weight: bold;">,</span>z<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>r <span style="color: #339933; font-weight: bold;">*</span> x<span style="color: #339933; font-weight: bold;">,</span> r <span style="color: #339933; font-weight: bold;">*</span> y<span style="color: #339933; font-weight: bold;">,</span> r <span style="color: #339933; font-weight: bold;">*</span> z<span style="color: green;">&#41;</span>
&nbsp;
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;/&gt;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Fractional</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;/&gt;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>x<span style="color: #339933; font-weight: bold;">,</span>y<span style="color: #339933; font-weight: bold;">,</span>z<span style="color: green;">&#41;</span> r <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>x <span style="color: #339933; font-weight: bold;">/</span> r<span style="color: #339933; font-weight: bold;">,</span> y <span style="color: #339933; font-weight: bold;">/</span> r<span style="color: #339933; font-weight: bold;">,</span> z <span style="color: #339933; font-weight: bold;">/</span> r<span style="color: green;">&#41;</span>
&nbsp;
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;.&gt;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> a
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;.&gt;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>x1<span style="color: #339933; font-weight: bold;">,</span>y1<span style="color: #339933; font-weight: bold;">,</span>z1<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>x2<span style="color: #339933; font-weight: bold;">,</span>y2<span style="color: #339933; font-weight: bold;">,</span>z2<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>x1 <span style="color: #339933; font-weight: bold;">*</span> x2<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">+</span> <span style="color: green;">&#40;</span>y1 <span style="color: #339933; font-weight: bold;">*</span> y2<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">+</span> <span style="color: green;">&#40;</span>z1 <span style="color: #339933; font-weight: bold;">*</span> z2<span style="color: green;">&#41;</span> 
&nbsp;
<span style="color: #5d478b; font-style: italic;">--cross product</span>
x <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Num</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a
x <span style="color: green;">&#40;</span>x1<span style="color: #339933; font-weight: bold;">,</span>y1<span style="color: #339933; font-weight: bold;">,</span>z1<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>x2<span style="color: #339933; font-weight: bold;">,</span>y2<span style="color: #339933; font-weight: bold;">,</span>z2<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>y1 <span style="color: #339933; font-weight: bold;">*</span> z2 <span style="color: #339933; font-weight: bold;">-</span> y2 <span style="color: #339933; font-weight: bold;">*</span> z1<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>x1<span style="color: #339933; font-weight: bold;">*</span>z2 <span style="color: #339933; font-weight: bold;">-</span> x2<span style="color: #339933; font-weight: bold;">*</span>z1<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>x1 <span style="color: #339933; font-weight: bold;">*</span> y2 <span style="color: #339933; font-weight: bold;">-</span> y1 <span style="color: #339933; font-weight: bold;">*</span> x2<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
&nbsp;
len <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Floating</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> a
len v <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">sqrt</span> <span style="color: green;">&#40;</span>v <span style="color: #339933; font-weight: bold;">&lt;.&gt;</span> v<span style="color: green;">&#41;</span>
&nbsp;
normed <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Floating</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> Vec3 a <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 a
normed v <span style="color: #339933; font-weight: bold;">=</span> v <span style="color: #339933; font-weight: bold;">&lt;/&gt;</span> len v
&nbsp;
<span style="color: #06c; font-weight: bold;">type</span> Vec3f <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>Vec3 <span style="color: #cccc00; font-weight: bold;">Float</span><span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">type</span> Color <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>Vec3 <span style="color: #cccc00; font-weight: bold;">Int</span><span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">--Rays</span>
<span style="color: #06c; font-weight: bold;">data</span> Ray <span style="color: #339933; font-weight: bold;">=</span> Ray <span style="color: green;">&#123;</span>orig <span style="color: #339933; font-weight: bold;">::</span> Vec3f<span style="color: #339933; font-weight: bold;">,</span>
                  dir  <span style="color: #339933; font-weight: bold;">::</span> Vec3f
                 <span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span>
&nbsp;
at<span style="color: #339933; font-weight: bold;">::</span>Ray <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Float</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> Vec3 <span style="color: #cccc00; font-weight: bold;">Float</span>
at <span style="color: green;">&#40;</span>Ray orig dir<span style="color: green;">&#41;</span> t <span style="color: #339933; font-weight: bold;">=</span> orig <span style="color: #339933; font-weight: bold;">&lt;+&gt;</span> <span style="color: green;">&#40;</span>t <span style="color: #339933; font-weight: bold;">&lt;*&gt;</span> dir<span style="color: green;">&#41;</span></pre></div></div>

<p>Pretty basic so far, but this should be enough to get me started. Haskell wasn&#8217;t happy when I tried to make the infix operators without the &#8220;<>&#8220;s so I guess I&#8217;m stuck with them (unless someone can tell me how to fix it.) However this does still look pretty nice:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;+&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">5</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">5</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">5</span><span style="color: green;">&#41;</span>
<span style="color: green;">&#40;</span><span style="color: red;">6</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">6</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">6</span><span style="color: green;">&#41;</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">5</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">5</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">5</span><span style="color: green;">&#41;</span>
<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">4</span><span style="color: #339933; font-weight: bold;">,-</span><span style="color: red;">4</span><span style="color: #339933; font-weight: bold;">,-</span><span style="color: red;">4</span><span style="color: green;">&#41;</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: red;">5</span> <span style="color: #339933; font-weight: bold;">&lt;*&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: green;">&#41;</span>
<span style="color: green;">&#40;</span><span style="color: red;">5</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">10</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">15</span><span style="color: green;">&#41;</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;/&gt;</span> <span style="color: red;">5</span>
<span style="color: green;">&#40;</span><span style="color: red;">0.2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0.4</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0.6</span><span style="color: green;">&#41;</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;.&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">3</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: green;">&#41;</span>
<span style="color: red;">10</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: green;">&#41;</span> `x` <span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: green;">&#41;</span>
<span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: green;">&#41;</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> len <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: green;">&#41;</span>
<span style="color: red;">1.4142135623730951</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="font-weight: bold;">sqrt</span> <span style="color: red;">2</span>
<span style="color: red;">1.4142135623730951</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> normed <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: green;">&#41;</span>
<span style="color: green;">&#40;</span><span style="color: red;">0.2672612419124244</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0.5345224838248488</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0.8017837257372732</span><span style="color: green;">&#41;</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> len <span style="color: green;">&#40;</span>normed <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
<span style="color: red;">1.0</span>
<span style="color: #339933; font-weight: bold;">*</span>Vector<span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: green;">&#40;</span>Ray <span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: red;">4</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> `at` <span style="color: red;">100</span>
<span style="color: green;">&#40;</span><span style="color: red;">400.0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">300.0</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">200.0</span><span style="color: green;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2011/01/15/vector-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi Slicing</title>
		<link>http://joedoliner.com/2010/08/25/multi-slicing/</link>
		<comments>http://joedoliner.com/2010/08/25/multi-slicing/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 23:46:58 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=122</guid>
		<description><![CDATA[Article available at: http://www.rethinkdb.com/blog/2010/08/multi-slicing/]]></description>
			<content:encoded><![CDATA[<p>Article available at: <a href="http://www.rethinkdb.com/blog/2010/08/multi-slicing/"> http://www.rethinkdb.com/blog/2010/08/multi-slicing/ </a></p>
]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2010/08/25/multi-slicing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Enrico Fermi Takes Integrals</title>
		<link>http://joedoliner.com/2010/03/14/how-enrico-fermi-takes-integrals/</link>
		<comments>http://joedoliner.com/2010/03/14/how-enrico-fermi-takes-integrals/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 09:47:48 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Anecdotes]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[science]]></category>
		<category><![CDATA[Enrico.Fermi]]></category>
		<category><![CDATA[Fermi]]></category>
		<category><![CDATA[Folklore]]></category>
		<category><![CDATA[Physics]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=100</guid>
		<description><![CDATA[You know those interview questions? The ones where you&#8217;re supposed to make spurious assumptions and use them to compute something like: &#8220;How many piano tuners are there in Chicago?&#8221; The correct term for one of these is a &#8220;Fermi Problem&#8221; after Enrico Fermi the physicist, who apparently was spectacularly good at such problems. Legend has [...]]]></description>
			<content:encoded><![CDATA[<p>You know those interview questions? The ones where you&#8217;re supposed to make spurious assumptions and use them to compute something like: &#8220;How many piano tuners are there in Chicago?&#8221;<br />
The correct term for one of these is a &#8220;Fermi Problem&#8221; after Enrico Fermi the physicist, who apparently was spectacularly good at such problems.<br />
Legend has it he made a stunningly accurate guess at the power of a Nuclear Explosion based on how far some nearby scraps of paper moved.</p>
<p>The point of Fermi Problems&#8212;and the reason they&#8217;re so popular in interviews&#8212;is to find the quickest possible path to an answer.<br />
Even if the answer itself isn&#8217;t close enough to be useful the intuition it gives you is.<br />
And Fermi had a great love for finding this intuition in a problem.</p>
<p><a href="http://joedoliner.com/wp-content/uploads/2010/02/sqrt.png"><img class="aligncenter size-full wp-image-102" title="Square Root" src="http://joedoliner.com/wp-content/uploads/2010/02/sqrt.png" alt="Square Root" width="527" height="466" /></a></p>
<p>Integration is one of the most deceptively intuitive problems out there, in the picture above for example the answer is just the red.<br />
This easy to digest definition is what you get in the first 5 minutes of a calculus class, and then the other 1795 minutes everything is complicated and unrelated to the red.<br />
And integrals aren&#8217;t just hard for you, it really doesn&#8217;t take much to make an integral impossible for everyone.<br />
For example <img src='http://s.wordpress.com/latex.php?latex=%5Cint%20%5Csin%28x%29%5E%7B%5Csin%28x%29%7D%20%5C%20dx&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\int \sin(x)^{\sin(x)} \ dx' title='\int \sin(x)^{\sin(x)} \ dx' class='latex' /> gets you a forlorn &#8220;<a href="http://www.wolframalpha.com/input/?i=Integral[sin[x]^sin[x],x]">no result found in terms of standard mathematical functions</a>&#8221; from Wolfram Alpha. Math just doesn&#8217;t have a good answer for it.</p>
<p>But this shouldn&#8217;t sit well with any of us because you know, and I know that that function has some red under it.<br />
And it really didn&#8217;t sit well with Fermi so here&#8217;s what he&#8217;d do: he&#8217;d draw the function out with pencil and paper, cut it out and then weigh it.<br />
Divide that weight by that of a 1 by 1 square of the same paper and that&#8217;s the answer.<br />
All he needed was the first 5 minutes.</p>
<p><a href="http://joedoliner.com/wp-content/uploads/2010/02/graph2.png"><img class="aligncenter size-full wp-image-103" title="Sin(x)^Sin(x)" src="http://joedoliner.com/wp-content/uploads/2010/02/graph2.png" alt="Sin(x)^Sin(x)" width="527" height="466" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2010/03/14/how-enrico-fermi-takes-integrals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programming Praxis Growable Arrays</title>
		<link>http://joedoliner.com/2009/10/16/programming-praxis-growable-arrays/</link>
		<comments>http://joedoliner.com/2009/10/16/programming-praxis-growable-arrays/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 00:07:53 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Programming Praxis]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=79</guid>
		<description><![CDATA[Exercise from: http://programmingpraxis.com/2009/10/16/growable-arrays/ Our goal here is to implement an array which is capable of dynamically growing as we add elements to it at the cost of logarithmic runtime for put and get functions instead of the constant runtime of standard arrays. The indexing scheme seems a bit weird at first until we notice the [...]]]></description>
			<content:encoded><![CDATA[<p>Exercise from: <a href="http://programmingpraxis.com/2009/10/16/growable-arrays/"> http://programmingpraxis.com/2009/10/16/growable-arrays/ </a></p>
<p>Our goal here is to implement an array which is capable of dynamically growing as we add elements to it at the cost of logarithmic runtime for put and get functions instead of the constant runtime of standard arrays. <img class="alignleft size-full wp-image-80" title="growable_arrays" src="http://joedoliner.com/wp-content/uploads/2009/10/growable_arrays.jpg" alt="growable_arrays" width="600" height="254" /></p>
<p>The indexing scheme seems a bit weird at first until we notice the pattern that the left subtree of 1 is all even and the right subtree is all odd. So given and index we simply consider its parity and choose the correct subtree. Then we apply this recursively to the subtree with the index halved (rounded down). Here it is implemented in python:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> exArray<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
	key = <span style="color: #008000;">None</span>
	left = <span style="color: #008000;">None</span>
	right = <span style="color: #008000;">None</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, index<span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>index == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'index out of bounds'</span>
		<span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>index == <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
			<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">key</span> == <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
				<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'index out of bounds'</span>
			<span style="color: #ff7700;font-weight:bold;">else</span>:
				<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">key</span>
		<span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>index<span style="color: #66cc66;">%</span>2 == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
			<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">left</span><span style="color: black;">&#41;</span>:
				<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">left</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span>index <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">else</span>:
				<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'index out of bounds'</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">right</span><span style="color: black;">&#41;</span>:
				<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">right</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span>index <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">else</span>:
				<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'index out of bounds'</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> put<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, index, key<span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>index == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'index out of bounds'</span>
		<span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>index == <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
			<span style="color: #008000;">self</span>.<span style="color: black;">key</span> = key
		<span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: black;">&#40;</span>index<span style="color: #66cc66;">%</span>2 == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
			<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">self</span>.<span style="color: black;">left</span><span style="color: black;">&#41;</span>:
				<span style="color: #008000;">self</span>.<span style="color: black;">left</span> = exArray<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			<span style="color: #008000;">self</span>.<span style="color: black;">left</span>.<span style="color: black;">put</span><span style="color: black;">&#40;</span>index <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff4500;">1</span>, key<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">self</span>.<span style="color: black;">right</span><span style="color: black;">&#41;</span>:
				<span style="color: #008000;">self</span>.<span style="color: black;">right</span> = exArray<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			<span style="color: #008000;">self</span>.<span style="color: black;">right</span>.<span style="color: black;">put</span><span style="color: black;">&#40;</span>index <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff4500;">1</span>, key<span style="color: black;">&#41;</span></pre></div></div>

<p>Full code: <a href="http://joedoliner.com/wp-content/uploads/2009/10/exArray.py">exArray.py</a><br />
To use:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> exArray
exArray.<span style="color: #dc143c;">test</span><span style="color: black;">&#40;</span>array_size<span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2009/10/16/programming-praxis-growable-arrays/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Netflix Zen Master Revisited</title>
		<link>http://joedoliner.com/2009/08/29/the-netflix-zen-master-revisited/</link>
		<comments>http://joedoliner.com/2009/08/29/the-netflix-zen-master-revisited/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 10:14:26 +0000</pubDate>
		<dc:creator>Joe Doliner</dc:creator>
				<category><![CDATA[Anecdotes]]></category>
		<category><![CDATA[character sketch]]></category>
		<category><![CDATA[Netflix]]></category>

		<guid isPermaLink="false">http://joedoliner.com/?p=74</guid>
		<description><![CDATA[I was recently forwarded the response of the Netflix Zenmaster himself to my article about him. There were a few charming details I thought I might share with you. Apparently what I published was actually yesterday&#8217;s story. The Zenmaster has upped his game quite a bit since then. Nowadays content is stored on a 8TB [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently forwarded the response of the Netflix Zenmaster himself to my <a href="http://joedoliner.com/2009/08/12/the-netflix-zen-master/">article</a> about him. There were a few charming details I thought I might share with you. Apparently what I published was actually yesterday&#8217;s story. The Zenmaster has upped his game quite a bit since then. Nowadays content is stored on a 8TB file server he has setup in his home and streamed via wireless to all the computers and TVs in the house. It even allows for remote access through FTP. Here&#8217;s the truly golden bit: the movies have been edited to what they should have been. Annoying actors are completely edited out. As are superfluous scenes. Endings in particular are improved by this process. An example: his version of The Lord of the Rings has Frodo and Sam completely erased.</p>
]]></content:encoded>
			<wfw:commentRss>http://joedoliner.com/2009/08/29/the-netflix-zen-master-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
