<?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>Algorithm-Forge &#187; Programming</title>
	<atom:link href="http://www.algorithm-forge.com/techblog/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.algorithm-forge.com/techblog</link>
	<description>Java, R, Statistics, Algorithms and other stuff</description>
	<lastBuildDate>Sun, 18 Jul 2010 16:53:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using JavaGD in Java applications</title>
		<link>http://www.algorithm-forge.com/techblog/2010/07/using-javagd-in-java-applications/</link>
		<comments>http://www.algorithm-forge.com/techblog/2010/07/using-javagd-in-java-applications/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 21:54:25 +0000</pubDate>
		<dc:creator>Kornelius Rohmeyer</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://www.algorithm-forge.com/techblog/?p=316</guid>
		<description><![CDATA[Goal: Create a Java application with a JFrame that contains a JGDPanel from JavaGD and plot something via JRI. Solution: The following code is a derivate of JGR code snipplets under GPL-2: import java.awt.Component; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import javax.swing.JFrame; &#8230; <a href="http://www.algorithm-forge.com/techblog/2010/07/using-javagd-in-java-applications/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Goal:</strong> Create a Java application with a <tt>JFrame</tt> that contains a <tt>JGDPanel</tt> from <tt>JavaGD</tt> and plot something via <tt>JRI</tt>.</p>
<p><strong>Solution:</strong> The following code is a derivate of <a href="http://rforge.net/JGR/">JGR</a> code snipplets under GPL-2:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.Component</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.WindowEvent</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.WindowListener</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JFrame</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.rosuda.JRI.Rengine</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.rosuda.javaGD.GDInterface</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.rosuda.javaGD.JGDBufferedPanel</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JavaGDExample <span style="color: #000000; font-weight: bold;">extends</span> GDInterface <span style="color: #000000; font-weight: bold;">implements</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Awindowlistener+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">WindowListener</span></a> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ajframe+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">JFrame</span></a> f<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> gdOpen<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span> w, <span style="color: #000066; font-weight: bold;">double</span> h<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>f<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> gdClose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; f <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ajframe+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">JFrame</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;JavaGD Example&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: #006633;">addWindowListener</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> &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; c <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JGDBufferedPanel<span style="color: #009900;">&#40;</span>w, h<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: #006633;">getContentPane</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Acomponent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Component</span></a><span style="color: #009900;">&#41;</span> c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: #006633;">pack</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: #006633;">setVisible</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: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> gdClose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">gdClose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>f<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: #006633;">removeAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.<span style="color: #006633;">dispose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Rengine engine <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Rengine<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span><span style="color: #0000ff;">&quot;--vanilla&quot;</span><span style="color: #009900;">&#125;</span>, <span style="color: #000066; font-weight: bold;">true</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; engine.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.setenv &lt;- if (exists(<span style="color: #000099; font-weight: bold;">\&quot;</span>Sys.setenv<span style="color: #000099; font-weight: bold;">\&quot;</span>)) Sys.setenv else Sys.putenv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; engine.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.setenv(<span style="color: #000099; font-weight: bold;">\&quot;</span>JAVAGD_CLASS_NAME<span style="color: #000099; font-weight: bold;">\&quot;</span>=<span style="color: #000099; font-weight: bold;">\&quot;</span>JavaGDExample<span style="color: #000099; font-weight: bold;">\&quot;</span>)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; engine.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;library(JavaGD)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; engine.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;JavaGD()&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; engine.<span style="color: #006633;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;plot(rnorm(100))&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/** listener response to &quot;Close&quot; - effectively invokes &lt;code&gt;dev.off()&lt;/code&gt; on the device */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowClosing<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Awindowevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">WindowEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>c<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> executeDevOff<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowClosed<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Awindowevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">WindowEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowOpened<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Awindowevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">WindowEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowIconified<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Awindowevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">WindowEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowDeiconified<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Awindowevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">WindowEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowActivated<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Awindowevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">WindowEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowDeactivated<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Awindowevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">WindowEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Et voilà:</p>
<p><img src="http://www.algorithm-forge.com/techblog/wp-content/uploads/2010/07/JavaGDExample-300x241.png" alt="JavaGDExample" title="JavaGDExample" /></p>
<p>Of course you have to make sure that the JRI native library is in a directory listed in <tt>java.library.path</tt>, for example on my machine via:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">java -Djava.library.path=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>R<span style="color: #000000; font-weight: bold;">/</span>site-library<span style="color: #000000; font-weight: bold;">/</span>rJava<span style="color: #000000; font-weight: bold;">/</span>jri<span style="color: #000000; font-weight: bold;">/</span> JavaGDExample</div></div>
<p>Also you have to provide the correct path for the environment variable <tt>R_HOME</tt> such as:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">R_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib64<span style="color: #000000; font-weight: bold;">/</span>R<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>And of course you need the two jars <tt>javaGD.jar</tt> and <tt>JRIEngine.jar</tt> in your <tt>CLASSPATH</tt>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm-forge.com/techblog/2010/07/using-javagd-in-java-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Because it is autumn</title>
		<link>http://www.algorithm-forge.com/techblog/2009/10/because-it-is-autumn/</link>
		<comments>http://www.algorithm-forge.com/techblog/2009/10/because-it-is-autumn/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 14:19:26 +0000</pubDate>
		<dc:creator>Kornelius Rohmeyer</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://www.algorithm-forge.com/techblog/?p=189</guid>
		<description><![CDATA[library&#40;colorspace&#41; branchvar &#60;- 1 tree &#60;- function&#40;x, y, branch&#41; &#123; &#160; lines&#40;x,y,col=hex&#40;RGB&#40;0.1,0.4,0&#41;&#41;&#41; &#160; wadd &#60;- 0.7 &#160; if&#40;branch&#62;0&#41; &#123; &#160; &#160; alpha &#60;- atan2&#40;&#40;y&#91;2&#93;-y&#91;1&#93;&#41;,&#40;x&#91;2&#93;-x&#91;1&#93;&#41;&#41; &#160; &#160; len &#60;- sqrt&#40;&#40;y&#91;2&#93;-y&#91;1&#93;&#41;^2+&#40;x&#91;2&#93;-x&#91;1&#93;&#41;^2&#41;*0.6 &#160; &#160; tree&#40;c&#40;x&#91;2&#93;,x&#91;2&#93;+abs&#40;rnorm&#40;1,1,branchvar&#41;&#41;*len*cos&#40;alpha&#41;&#41;, &#160; &#160; &#160; &#160; &#160; c&#40;y&#91;2&#93;,y&#91;2&#93;+abs&#40;rnorm&#40;1,1,branchvar&#41;&#41;*len*sin&#40;alpha&#41;&#41;, &#160; &#160; &#8230; <a href="http://www.algorithm-forge.com/techblog/2009/10/because-it-is-autumn/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div id="attachment_194" class="wp-caption alignnone" style="width: 460px"><img src="http://www.algorithm-forge.com/techblog/wp-content/uploads/2009/10/autumn.png" alt="autumn" title="autumn" width="450" height="420" class="size-full wp-image-194" /><p class="wp-caption-text">autumn</p></div>
<div class="codecolorer-container r default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="r codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">library<span style="color: #66cc66;">&#40;</span>colorspace<span style="color: #66cc66;">&#41;</span><br />
branchvar <span style="color: #78aaac;">&lt;-</span> 1<br />
tree <span style="color: #78aaac;">&lt;-</span> <span style="color: #a020f0;">function</span><span style="color: #66cc66;">&#40;</span>x, y, branch<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; lines<span style="color: #66cc66;">&#40;</span>x,y,col<span style="color: #78aaac;">=</span>hex<span style="color: #66cc66;">&#40;</span>RGB<span style="color: #66cc66;">&#40;</span>0.1,0.4,0<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; wadd <span style="color: #78aaac;">&lt;-</span> 0.7<br />
&nbsp; <span style="color: #a020f0;">if</span><span style="color: #66cc66;">&#40;</span>branch<span style="color: #78aaac;">&gt;</span>0<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; alpha <span style="color: #78aaac;">&lt;-</span> atan2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>y<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">-</span>y<span style="color: #66cc66;">&#91;</span>1<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">-</span>x<span style="color: #66cc66;">&#91;</span>1<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; len <span style="color: #78aaac;">&lt;-</span> sqrt<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>y<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">-</span>y<span style="color: #66cc66;">&#91;</span>1<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #78aaac;">^</span>2<span style="color: #78aaac;">+</span><span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">-</span>x<span style="color: #66cc66;">&#91;</span>1<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #78aaac;">^</span>2<span style="color: #66cc66;">&#41;</span><span style="color: #78aaac;">*</span>0.6<br />
&nbsp; &nbsp; tree<span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span>,x<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">+</span>abs<span style="color: #66cc66;">&#40;</span>rnorm<span style="color: #66cc66;">&#40;</span>1,1,branchvar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #78aaac;">*</span>len<span style="color: #78aaac;">*</span>cos<span style="color: #66cc66;">&#40;</span>alpha<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c<span style="color: #66cc66;">&#40;</span>y<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span>,y<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">+</span>abs<span style="color: #66cc66;">&#40;</span>rnorm<span style="color: #66cc66;">&#40;</span>1,1,branchvar<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #78aaac;">*</span>len<span style="color: #78aaac;">*</span>sin<span style="color: #66cc66;">&#40;</span>alpha<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; branch<span style="color: #78aaac;">-</span>1<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; tree<span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span>,x<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">+</span>len<span style="color: #78aaac;">*</span>cos<span style="color: #66cc66;">&#40;</span>alpha<span style="color: #78aaac;">+</span>wadd<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c<span style="color: #66cc66;">&#40;</span>y<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span>,y<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">+</span>len<span style="color: #78aaac;">*</span>sin<span style="color: #66cc66;">&#40;</span>alpha<span style="color: #78aaac;">+</span>wadd<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,branch<span style="color: #78aaac;">-</span>1<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; tree<span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span>,x<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">+</span>len<span style="color: #78aaac;">*</span>cos<span style="color: #66cc66;">&#40;</span>alpha<span style="color: #78aaac;">-</span>wadd<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c<span style="color: #66cc66;">&#40;</span>y<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span>,y<span style="color: #66cc66;">&#91;</span>2<span style="color: #66cc66;">&#93;</span><span style="color: #78aaac;">+</span>len<span style="color: #78aaac;">*</span>sin<span style="color: #66cc66;">&#40;</span>alpha<span style="color: #78aaac;">-</span>wadd<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>,branch<span style="color: #78aaac;">-</span>1<span style="color: #66cc66;">&#41;</span> &nbsp; &nbsp;<br />
&nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #a020f0;">else</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; points<span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>,y<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>,pch<span style="color: #78aaac;">=</span><span style="color: #cc66cc;">16</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;col<span style="color: #78aaac;">=</span>hex<span style="color: #66cc66;">&#40;</span>RGB<span style="color: #66cc66;">&#40;</span>rbeta<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2.6</span>,<span style="color: #cc66cc;">0.5</span><span style="color: #66cc66;">&#41;</span>,rbeta<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">0.5</span>,<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
plot.new<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
tree<span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0.20</span><span style="color: #66cc66;">&#41;</span>,c<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0.20</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #cc66cc;">7</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>You need library colorspace.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm-forge.com/techblog/2009/10/because-it-is-autumn/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Shortcuts in R under Unix from the readline library</title>
		<link>http://www.algorithm-forge.com/techblog/2009/09/shortcuts-in-r-under-unix-from-the-readline-library/</link>
		<comments>http://www.algorithm-forge.com/techblog/2009/09/shortcuts-in-r-under-unix-from-the-readline-library/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 13:49:45 +0000</pubDate>
		<dc:creator>Kornelius Rohmeyer</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://www.algorithm-forge.com/techblog/?p=121</guid>
		<description><![CDATA[Under Unix you can use in R the the advanced features for command editing and command history that the GNU Readline Library provides. Both Emacs and vi editing modes are available and the Emacs-like keybindings are installed by default. Here &#8230; <a href="http://www.algorithm-forge.com/techblog/2009/09/shortcuts-in-r-under-unix-from-the-readline-library/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Under Unix you can use in R the the advanced features for command editing and command history that <a href="http://tiswww.case.edu/php/chet/readline/rltop.html">the GNU Readline Library</a> provides.</p>
<p>Both Emacs and vi editing modes are available and the Emacs-like keybindings are installed by default. Here some Emacs keybindings that also work in R (from the <a href="http://tiswww.case.edu/php/chet/readline/readline.html">documentation of the GNU Readline Library</a>):</p>
<p><strong>Copy and Paste:</strong><br />
<em>Ctrl-u</em> 	Cut from the cursor to the beginning of the line.<br />
<em>Ctrl-k</em> 	Cut from the cursor to the end of the line.<br />
<em>Ctrl-w</em> 	Cut from the cursor to the start of the word.<br />
<em>Ctrl-y</em> 	Pastes text from the clipboard.<br />
<em>Alt-y</em>         Rotate the kill-ring, and paste the new top. You can only do this if the prior command was Ctrl-y or Alt-y.</p>
<p><strong>Moving:</strong><br />
<em>Ctrl-a</em> 	Move to the start of the line.<br />
<em>Ctrl-e</em> 	Move to the end of the line.<br />
<em>Alt-b</em>  	Move back one word.<br />
<em>Alt-f </em> 	Move forward one word.<br />
<em>Ctrl-b</em> 	Move back one character.<br />
<em>Ctrl-f</em> 	Move forward one character.</p>
<p><strong>Undo:</strong><br />
<em>Ctrl-_</em> 	Undo the last changes.<br />
<em>Alt-r</em>  	Undo all changes to the line.</p>
<p><strong>Miscellaneous:</strong><br />
<em>Ctrl-l</em>  	Clear the screen leaving the current line at the top of the screen.</p>
<p><strong>History:</strong><br />
<em>Ctrl-r</em> 	Incremental reverse search of history.<br />
<em>Alt-p</em>  	Non-incremental reverse search of history.</p>
<p>If you want to use the vi-mode just press Ctrl+Alt+j and you can use the usual vi modes and commands (for example take a look at this <a href="http://www.catonmat.net/download/bash-vi-editing-mode-cheat-sheet.pdf">vi-editing-mode-cheat-sheet</a>).</p>
<p>If you want to start in the vi mode by default, put the following line in your <tt>~/.inputrc</tt> (which of course will also effect your bash etc.):</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">set</span> editing-mode <span style="color: #c20cb9; font-weight: bold;">vi</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.algorithm-forge.com/techblog/2009/09/shortcuts-in-r-under-unix-from-the-readline-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
