<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>degrunt.org: NXT / pbLua dump screen to XPM</title>
    <link>http://www.degrunt.org/articles/2008/06/07/nxt-pblua-dump-screen-to-xpm</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>lego, mindstorms, technics, pneumatic</description>
    <item>
      <title>NXT / pbLua dump screen to XPM</title>
      <description>&lt;p&gt;With very little effort one can change the function DumpDisplay from the tutorial to a DumpDisplayToXPM, which will create a human-readable as well as computer readable file.&lt;/p&gt;


&lt;pre&gt;
/* XPM */
static char *xpm_[] = {
"100 64 2 1",
"* c #000000",
". c #ffffff",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"......*.....*.......................****.........*..................*...*****.*.....................",
"......*.....*.......................*...*........*.................**...*.....*.....................",
"****..*.**..*.....*...*..***........*...*..***..***....***..........*...****..*.**..................",
"*...*.**..*.*.....*...*.....*.......****..*...*..*........*.........*.......*.**..*.................",
"****..*...*.*.....*...*..****.......*...*.*****..*.....****.........*.......*.*...*.................",
"*.....*...*.*.....*..**.*...*.......*...*.*......*..*.*...*.........*...*...*.*...*.................",
"*.....****..*****..**.*..****.......****...***....**...****........***...***..****..................",
"....................................................................................................",
};
&lt;/pre&gt;

	&lt;p&gt;Using &lt;a href="http://www.pixelmator.com/"&gt;PixelMator&lt;/a&gt; this can easily be translated to &lt;span class="caps"&gt;PNG&lt;/span&gt;:&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://degrunt.org/files/nxtscreen.png" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s the function:&lt;/p&gt;


&lt;pre&gt;
function DumpDisplayToXPM()
  print("/* XPM */")
  print("static char *xpm_[] = {")
  print("\"100 64 2 1\",")
  print("\"* c #000000\",")
  print("\". c #ffffff\",")
  for y=0,63 do
    s = "" 
    for x=0,99 do
      if 0 ~= nxt.DisplayGetPixel(x,y) then
        s = s .. "*" 
       else
        s = s .. "." 
      end
    end
    print( "\"" .. s .. "\"," )
  end
  print("};")
end
&lt;/pre&gt;

	&lt;p&gt;Currently this function outputs to the console, which is fine for our purpose, so we can copy and paste it over to our computer.&lt;/p&gt;


	&lt;p&gt;As said earlier, I&amp;#8217;m using &lt;a href="http://code.google.com/p/macvim/"&gt;MacVim&lt;/a&gt; which supports &lt;span class="caps"&gt;XPM&lt;/span&gt; natively.&lt;/p&gt;</description>
      <pubDate>Sat, 07 Jun 2008 12:11:53 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:9e72e95c-af11-43f1-90e4-15c51b625bd3</guid>
      <author>Tom</author>
      <link>http://www.degrunt.org/articles/2008/06/07/nxt-pblua-dump-screen-to-xpm</link>
    </item>
  </channel>
</rss>
