title: Proper type conversion for printing bytes
body: <p>I'm trying to re-implement the <a href="http://fabiensanglard.net/rayTracing_back_of_business_card/" rel="nofollow">business card ray tracer</a> in rust for fun and profit.  As far as I can tell all of the logic is in place, but for the life of me I can't figure out how correctly convert from my floating point values to the RGB bytes that the ppm file format expects.  In the original code (C++), it looks like this:</p>
  
  <pre><code>printf("%c%c%c",(int)p.x,(int)p.y,(int)p.z);
  </code></pre>
  
  <p>where <code>p</code> is a 3-d vector of floats representing an RGB value.  I didn't have much luck with <code>print!</code>, so after much tweaking I wrote the equivalent expression as:</p>
  
  <pre><code>let mut out = io::stdout();
  out.write(&amp;[(p.x as u8),(p.x as u8),(p.x as u8)]);
  </code></pre>
  
  <p>However, the output is way off (I can post it if you really want, but suffice it to say that the correct output has plenty of non-printable characters, while my version is quite printable).  I honestly don't understand the nuances of type conversion for either language.  Anyone care to lend a hand?</p>
  
  <p><strong>Edit:</strong> <a href="https://gist.github.com/axelmagn/10946425" rel="nofollow">full source</a> (note that I use floats as vector attributes)</p>