<?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"
	>

<channel>
	<title>Pygmalion</title>
	<atom:link href="http://pygmalion.groenefee.nl/feed" rel="self" type="application/rss+xml" />
	<link>http://pygmalion.groenefee.nl</link>
	<description>Geek stuff</description>
	<pubDate>Mon, 22 Feb 2010 15:33:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Drupal 6.x: fatal error in installer</title>
		<link>http://pygmalion.groenefee.nl/drupal-6x-fatal-error-in-installer-15.html</link>
		<comments>http://pygmalion.groenefee.nl/drupal-6x-fatal-error-in-installer-15.html#comments</comments>
		<pubDate>Wed, 03 Feb 2010 13:02:12 +0000</pubDate>
		<dc:creator>Pygmalion</dc:creator>
		
		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://pygmalion.groenefee.nl/?p=15</guid>
		<description><![CDATA[During database setup the following fatal error may occur in the web-installer on some systems:
Fatal error: Call to undefined function _user_password_dynamic_validation() in /var/www/localhost/htdocs/drupal/install.php on line 727
It can be solved by modifying the system table of your Drupal database:
mysql -u  -p
use
UPDATE system SET status = 1 WHERE name = 'block' OR name = 'user' OR [...]]]></description>
			<content:encoded><![CDATA[<p>During database setup the following fatal error may occur in the web-installer on some systems:</p>
<p><code>Fatal error: Call to undefined function _user_password_dynamic_validation() in /var/www/localhost/htdocs/drupal/install.php on line 727</code></p>
<p>It can be solved by modifying the system table of your Drupal database:</p>
<p><code>mysql -u  -p<br />
use<br />
UPDATE system SET status = 1 WHERE name = 'block' OR name = 'user' OR name = 'node' OR name = 'filter';<br />
exit</code></p>
<p>Then reload the installer page on which the error occurred and your installation wil continue.</p>
]]></content:encoded>
			<wfw:commentRss>http://pygmalion.groenefee.nl/drupal-6x-fatal-error-in-installer-15.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Adding a profile box and posting to the feed on facebook</title>
		<link>http://pygmalion.groenefee.nl/adding-a-profile-box-and-posting-to-the-feed-on-facebook-14.html</link>
		<comments>http://pygmalion.groenefee.nl/adding-a-profile-box-and-posting-to-the-feed-on-facebook-14.html#comments</comments>
		<pubDate>Thu, 24 Sep 2009 16:36:35 +0000</pubDate>
		<dc:creator>Pygmalion</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[facebook]]></category>

		<guid isPermaLink="false">http://pygmalion.groenefee.nl/?p=14</guid>
		<description><![CDATA[Building an app is easy. At least that&#8217;s what facebook states. Yet it can be quite a challenge to get started if you&#8217;re not famliar with facebook&#8217;s API as the documentation can be quite confusing. Besides, the API seems to be still under development and therefore subject to changes. Chances are that you&#8217;ll code against [...]]]></description>
			<content:encoded><![CDATA[<p><em>Building an app is easy</em>. At least that&#8217;s what facebook <a href="http://developers.facebook.com/" target="_blank">states</a>. Yet it can be quite a challenge to get started if you&#8217;re not famliar with facebook&#8217;s API as the <a href="http://wiki.developers.facebook.com/index.php/Main_Page" target="_blank">documentation</a> can be quite confusing. Besides, the API seems to be still under development and therefore subject to changes. Chances are that you&#8217;ll code against deprecated API (e.g. after googling for a solution).</p>
<p>We&#8217;ll <a href="http://apps.facebook.com/helfrichabsinthe/" target="_blank">demonstrate</a> how to 1) add a profile box to a user profile and 2) post a message to the news feed.</p>
<p>After we&#8217;ve set up the application in the <a href="http://www.facebook.com/developers/" target="_blank">Developer App</a>, we&#8217;ll start with some code to instantiate a facebook object with our unique API key and application secret. This object contains the api_client object with all the API methods we need. It also contains methods to retrieve some values we&#8217;ll need during the application session, like the user&#8217;s unique ID.</p>
<pre><code>
// the facebook client library
include_once 'facebook-platform/php/facebook.php';

// Get these from http://developers.facebook.com
$api_key = '&lt;your key goes here&gt;';
$secret  = '&lt;your app secret goes here&gt;';

// We may want to use this URL later
$app_url = "http://apps.facebook.com/helfrichabsinthe/";

$facebook = new Facebook($api_key, $secret);
$facebook-&gt;require_frame();
$user = $facebook-&gt;require_login();</code></pre>
<p>We&#8217;ll define a variable that contains the <a href="http://wiki.developers.facebook.com/index.php/FBML" target="_blank">FBML</a> code for our profile box. Actually, we&#8217;ll need two boxes. The &#8220;narrow box&#8221; is the one the users will be prompted to add to their profile. A user will be able to move it to the Boxes tab. This will be our &#8220;wide box.&#8221; There used to be a third box for mobile devices but it&#8217;s deprecated by now. For the sake of simplicity we&#8217;ll fill these boxes with our initial box code. We can modify this later.</p>
<p>The FBML code is passed <a href="http://wiki.developers.facebook.com/index.php/Fb:ref" target="_blank">by reference</a> so we&#8217;ll be able to update it later without having to republish.</p>
<pre><code>$Box = "&lt;a href=\"{$app_url}\"&gt;I love Helfrich Absinthe.&lt;/a&gt;&lt;br/&gt;
&lt;img src=\"http://www.helfrichdranken.nl/eshop/images/helfrich_verte.jpg\"
border=\"0\" height=\"120\" width=\"120\"&gt;&lt;br/&gt;
&lt;a href=\"http://www.helfrichabsinthe.com/\" target=\"_blank\"&gt;
www.helfrichabsinthe.com&lt;/a&gt;";

$facebook-&gt;api_client-&gt;call_method('facebook.Fbml.setRefHandle',
array( 'handle' =&gt; 'BoxHandle', 'fbml' =&gt; "$Box" ,) );
$NarrowBox = "&lt;fb:ref handle=\"BoxHandle\" /&gt;";
$WideBox = $NarrowBox;</code></pre>
<p>Now we have all we need to instantiate the profile box. Note that it will only be visible after the user has added it. NULL values are used for deprecated parameters.</p>
<pre><code>
$ret = $facebook-&gt;api_client-&gt;profile_setFBML(NULL, $user, $WideBox, NULL,
NULL, $NarrowBox); </code></pre>
<p>Next we create a simple FBML canvas for our application to present itself. It contains <a href="http://wiki.developers.facebook.com/index.php/Fb:add-section-button" target="_blank">the button</a> that allows users to actually add the box to their profile.</p>
<pre><code>
&lt;div style="padding: 10px;"&gt;
  &lt;h2&gt;Thanks for loving Helfrich Absinthe. We love you too, &lt;fb:name
firstnameonly="true" uid="&lt;?=$user?&gt;" useyou="false"/&gt;!&lt;/h2&gt;&lt;br/&gt;
Please add us to your profile.&lt;br/&gt; &lt;br/&gt;
&lt;fb:add-section-button section="profile" /&gt;
&lt;br/&gt;
&lt;/div&gt;
&lt;div style="padding: 10px;"&gt;
&lt;img src="http://absintblog.be/wp-content/uploads/helfrich-verte-1.jpg"&gt;
&lt;/div&gt;</code></pre>
<p>Finally we want to prompt users to publish their action to the feed. There are several ways to do this, but most of them seem to be partially or fully deprecated. Facebook encourages the use of the <a href="http://wiki.developers.facebook.com/index.php/FBJS" target="_blank">FBJS</a> function <a href="http://wiki.developers.facebook.com/index.php/Facebook.streamPublish" target="_blank">Facebook.streamPublish</a>.</p>
<p>We won&#8217;t need templates to format the message. Instead we&#8217;ll pass a <a href="http://en.wikipedia.org/wiki/JSON" target="_blank">JSON object</a> as a so-called <a href="http://wiki.developers.facebook.com/index.php/Attachment_(Streams)" target="_blank">attachment</a>. We can also specify some &#8220;<a href="http://wiki.developers.facebook.com/index.php/Action_Links" target="_blank">action links</a>&#8220;. These are added as options to the line below our posting (after Comment, Like, etc.) and need to be passed as an array of JSON objects. It&#8217;s not as complicated as it probably sounds:</p>
<pre><code>&lt;script&gt;
var attachment = {'caption':'{*actor*} loves Helfrich Absinthe.','description':
'Click the link below if you do too.','media':[{'type':'image','src':
'http://www.helfrichdranken.nl/eshop/images/helfrich_verte.jpg','href':
'http://www.helfrichabsinthe.com/'}]};
var actionlink = [{'text':'Click here if you do too.','href':
'http://apps.facebook.com/helfrichabsinthe/'}];
Facebook.streamPublish(&#8217;loves Helfrich Absinthe.&#8217;, attachment, actionlink);
&lt;/script&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://pygmalion.groenefee.nl/adding-a-profile-box-and-posting-to-the-feed-on-facebook-14.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Dilution calculator for distillers</title>
		<link>http://pygmalion.groenefee.nl/dilution-calculator-for-distillers-13.html</link>
		<comments>http://pygmalion.groenefee.nl/dilution-calculator-for-distillers-13.html#comments</comments>
		<pubDate>Thu, 29 Jan 2009 16:29:22 +0000</pubDate>
		<dc:creator>Pygmalion</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://pygmalion.groenefee.nl/?p=13</guid>
		<description><![CDATA[This very simple Java application calculates the volume of water that needs to be added to an alcoholic distillate to reduce it to bottling strength. Although it&#8217;s not a very complex calculation of course, life becomes a tidbit easier when the result is just a mouse click away.
Invoke as follows:
java -jar Dilute.jar
To create a desktop [...]]]></description>
			<content:encoded><![CDATA[<p>This very simple Java application calculates the volume of water that needs to be added to an alcoholic distillate to reduce it to bottling strength. Although it&#8217;s not a very complex calculation of course, life becomes a tidbit easier when the result is just a mouse click away.</p>
<p>Invoke as follows:</p>
<pre>java -jar Dilute.jar</pre>
<p>To create a desktop launcher provide the full path to the jar file.</p>
<p>This tool shouldn&#8217;t be used for commercial purposes. Note that it doesn&#8217;t take the phenomenon of contraction into account.</p>
<p>Download: <a href="Dilute.jar">Dilute.jar</a></p>
<p><img src="pix/dilute.png" alt="Dilute screenshot" /></p>
]]></content:encoded>
			<wfw:commentRss>http://pygmalion.groenefee.nl/dilution-calculator-for-distillers-13.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>WordPress LinkRoll Widget</title>
		<link>http://pygmalion.groenefee.nl/wordpress-linkroll-widget-12.html</link>
		<comments>http://pygmalion.groenefee.nl/wordpress-linkroll-widget-12.html#comments</comments>
		<pubDate>Sun, 29 Jun 2008 15:23:11 +0000</pubDate>
		<dc:creator>Pygmalion</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://pygmalion.groenefee.nl/?p=12</guid>
		<description><![CDATA[The simple widget that runs in our sidebar presents a random selection of stored links.
The script parses the &#60;title&#62; tags on the referred pages to name the links.
To install it copy the script file to your plugin directory. Activate the widget in WordPress under Plugins, add it under Design->Widgets and customize it.
These values can be [...]]]></description>
			<content:encoded><![CDATA[<p>The simple widget that runs in our sidebar presents a random selection of stored links.</p>
<p>The script parses the &lt;title&gt; tags on the referred pages to name the links.</p>
<p>To install it copy the script file to your plugin directory. Activate the widget in WordPress under <i>Plugins</i>, add it under <i>Design->Widgets</i> and customize it.</p>
<p>These values can be edited:</p>
<ul>
<li>Title.</li>
<li>URL list. This is a text field containing all URLs separated by spaces.</li>
<li>The number of random links to display.</li>
</ul>
<p>Download: <a href="linkroll.tgz">linkroll.tgz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pygmalion.groenefee.nl/wordpress-linkroll-widget-12.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>WordPress AdSense Widget</title>
		<link>http://pygmalion.groenefee.nl/wordpress-adsense-widget-10.html</link>
		<comments>http://pygmalion.groenefee.nl/wordpress-adsense-widget-10.html#comments</comments>
		<pubDate>Wed, 25 Jun 2008 12:50:50 +0000</pubDate>
		<dc:creator>Pygmalion</dc:creator>
		
		<category><![CDATA[Google]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://pygmalion.groenefee.nl/?p=10</guid>
		<description><![CDATA[We customized Mike Smullin&#8217;s AdSense to meet the current specs. Our sidebar shows what it looks like. You can find our version right here. After installation and activation you only need to specify google_ad_client (your publisher ID) and google_ad_slot (to be pasted from the code provided by Google) on the Design->Widgets tab.
]]></description>
			<content:encoded><![CDATA[<p>We customized Mike Smullin&#8217;s AdSense to meet the current specs. Our sidebar shows what it looks like. You can find our version right <a href="adsense.tgz">here</a>. After installation and activation you only need to specify google_ad_client (your publisher ID) and google_ad_slot (to be pasted from the code provided by Google) on the Design->Widgets tab.</p>
]]></content:encoded>
			<wfw:commentRss>http://pygmalion.groenefee.nl/wordpress-adsense-widget-10.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Google PageRank in PHP</title>
		<link>http://pygmalion.groenefee.nl/google-pagerank-in-php-8.html</link>
		<comments>http://pygmalion.groenefee.nl/google-pagerank-in-php-8.html#comments</comments>
		<pubDate>Mon, 23 Jun 2008 12:53:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Google]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pygmalion.groenefee.nl/?p=8</guid>
		<description><![CDATA[To obtain your PageRank in PHP without a 403 Forbidden error you&#8217;ll have to calculate the PageRank Checksum and send it with your request. This is the way to go: http://www.hm2k.com/projects/pagerank
We have added a simple demo. Get your PageRank right here.
]]></description>
			<content:encoded><![CDATA[<p>To obtain your PageRank in PHP without a <em>403 Forbidden</em> error you&#8217;ll have to calculate the PageRank Checksum and send it with your request. This is the way to go: <a href="http://www.hm2k.com/projects/pagerank" target="_blank">http://www.hm2k.com/projects/pagerank</a><br />
We have added a simple demo. <a href="pagerank.php" target="_blank">Get your PageRank right here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://pygmalion.groenefee.nl/google-pagerank-in-php-8.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Bypassing a cranky BIOS: boot from CDROM</title>
		<link>http://pygmalion.groenefee.nl/bypassing-a-cranky-bios-boot-from-cdrom-7.html</link>
		<comments>http://pygmalion.groenefee.nl/bypassing-a-cranky-bios-boot-from-cdrom-7.html#comments</comments>
		<pubDate>Mon, 23 Jun 2008 09:57:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://pygmalion.groenefee.nl/?p=7</guid>
		<description><![CDATA[After a major crash of our Acer Aspire 1642 the hard disk needed to be replaced. After booting from a life CD we successfully installed Ubuntu Gutsy on the new drive. Unfortunately, after reboot the BIOS appeared to be completely blind to it. A BIOS upgrade would not fix the problem.
We worked around the problem [...]]]></description>
			<content:encoded><![CDATA[<p>After a major crash of our Acer Aspire 1642 the hard disk needed to be replaced. After booting from a life CD we successfully installed Ubuntu Gutsy on the new drive. Unfortunately, after reboot the BIOS appeared to be completely blind to it. A BIOS upgrade would not fix the problem.</p>
<p>We worked around the problem by creating a boot CD that would load a kernel, recognize the drive and continue booting the root partion on it.</p>
<p>First install the package syslinux.</p>
<p>Create a working directory:</p>
<pre>mkdir bootcd</pre>
<p>Add isolinux.bin:</p>
<pre>cp /usr/lib/syslinux/isolinux.bin bootcd</pre>
<p>Copy the appropriate kernel and ramdisk images to bootcd/linux and bootcd/initrd.img respectively, e.g:</p>
<pre>cp /boot/vmlinuz-2.6.22-14-generic bootcd/linux</pre>
<pre>cp /boot/initrd.img-2.6.22-14-generic bootcd/initrd.img</pre>
<p>Create a file bootcd/isolinux.cfg containg a line that will point to your root partition, e.g. /dev/sda1:</p>
<pre>DEFAULT linux initrd=initrd.img ro root=/dev/sda1</pre>
<p>Create an iso image of the working directory:</p>
<pre>mkisofs -o bootcd.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4</pre>
<pre> -boot-info-table -J -hide-rr-moved -R bootcd/</pre>
<p>Burn the image to CD.</p>
<p>Boot your system.</p>
]]></content:encoded>
			<wfw:commentRss>http://pygmalion.groenefee.nl/bypassing-a-cranky-bios-boot-from-cdrom-7.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Pinnacle PCTV USB2 on Suse 10.x</title>
		<link>http://pygmalion.groenefee.nl/pinnacle-pctv-usb2-on-suse-10x-6.html</link>
		<comments>http://pygmalion.groenefee.nl/pinnacle-pctv-usb2-on-suse-10x-6.html#comments</comments>
		<pubDate>Wed, 04 Jun 2008 21:46:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[SuSe]]></category>

		<category><![CDATA[USB]]></category>

		<category><![CDATA[Add new tag]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pygmalion.groenefee.nl/?p=6</guid>
		<description><![CDATA[Retrieved from the old wiki:
To get the Pinnacle USB2 device working you&#8217;ll need the kernel module for the em28xx chipset. This module is not included in the Suse distribution, so obtain the video4linux package v4l-dvb from linuxtv.org.
Note: You do not need the usbvision package. It only supports USB1.
The sources of your current kernel need to [...]]]></description>
			<content:encoded><![CDATA[<p><!-- start content --><em>Retrieved from the old wiki:</em></p>
<p>To get the Pinnacle USB2 device working you&#8217;ll need the kernel module for the em28xx chipset. This module is not included in the Suse distribution, so obtain the video4linux package v4l-dvb from <a href="http://www.linuxtv.org/">linuxtv.org</a>.</p>
<p>Note: You do <strong>not</strong> need the usbvision package. It only supports USB1.</p>
<p>The sources of your current kernel need to be installed in order to compile the v4l package. Simply get the kernel sources with Yast. Unpack the v4l package, change to its directory and build the modules:</p>
<p><tt>make<br />
make install </tt></p>
<p>Check for the presence of a running ivtv_tveeprom module:</p>
<p><tt>lsmod | grep ivtv_tveeprom </tt></p>
<p>If it is present remove it from the kernel:</p>
<p><tt>modprobe -r ivtv_tveeprom </tt></p>
<p>Insert the appropriate v4l-dvl modules:</p>
<p><tt>modprobe tveeprom<br />
modprobe tuner<br />
modprobe em28xx </tt></p>
<p>If module insertion fails, check out dmesg to find out what goes wrong, e.g.:</p>
<p><tt>dmesg | grep em28<br />
em28xx: module not supported by Novell, setting U taint flag.<br />
em28xx: disagrees about version of symbol tveeprom_hauppauge_analog<br />
em28xx: Unknown symbol tveeprom_hauppauge_analog</tt></p>
<p>The easiest way to solve this problem is to reboot your system after the installation of the v4l modules.</p>
<p>Redirect the DSP sound device with SoX:</p>
<p><tt>sox -t ossdsp -r 48000 -b -c 2 /dev/dsp1 -t ossdsp /dev/dsp </tt></p>
<p>Plug in the PCTV USB2 device.</p>
<p>Functionality has been tested with the TV viewers mplayer and tvtime (PAL modus). These packages are included in the Suse distribution.</p>
<p>Consult the <a href="http://www.linuxtv.org/v4lwiki/index.php/Talk:Em2820">em28xx discussion</a> in the <a href="http://www.linuxtv.org/v4lwiki/index.php/Main_Page">video4linux wiki$</a> if you experience any problems.</p>
<p style="margin-bottom: 0in;">
<p style="margin-bottom: 0in;">
]]></content:encoded>
			<wfw:commentRss>http://pygmalion.groenefee.nl/pinnacle-pctv-usb2-on-suse-10x-6.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Prisoner&#8217;s Dilemma applet</title>
		<link>http://pygmalion.groenefee.nl/prisoners-dilemma-applet-3.html</link>
		<comments>http://pygmalion.groenefee.nl/prisoners-dilemma-applet-3.html#comments</comments>
		<pubDate>Wed, 04 Jun 2008 21:26:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pygmalion.groenefee.nl/?p=3</guid>
		<description><![CDATA[Retrieved from the old wiki:
The Prisoner&#8217;s Dilemma source code has been released, a simple AWT based and multithreaded Java applet.
/** 
The Prisoner&#8217;s Dilemma
@version 0.20
@author Serge Helfrich 03-Aug-2002 (0.01 11-Feb-1998)
*/

   import java.awt.*;
   import java.awt.event.*;
   import java.applet.*;

   public class Pris00 extends Applet
   {  double b = [...]]]></description>
			<content:encoded><![CDATA[<p><em>Retrieved from the old wiki:</em></p>
<p>The <a href="http://prisonersdilemma.groenefee.nl/">Prisoner&#8217;s Dilemma</a> source code has been released, a simple AWT based and multithreaded Java applet.</p>
<pre><tt>/** </tt>
<tt>The Prisoner&#8217;s Dilemma</tt>
<tt>@version 0.20</tt>
<tt>@author Serge Helfrich 03-Aug-2002 (0.01 11-Feb-1998)</tt>
<tt>*/</tt>

<tt>   import java.awt.*;</tt>
<tt>   import java.awt.event.*;</tt>
<tt>   import java.applet.*;</tt>

<tt>   public class Pris00 extends Applet</tt>
<tt>   {  double b = 1.85; </tt>
<tt>      double p = 0.1;  </tt>
<tt>      int delay = 100; // increased for green thread support</tt>
<tt>      boolean paused;</tt>
<tt>      PrisCanv cv;</tt>
<tt>      PrisPan pn;</tt>
<tt>   </tt>
<tt>      public void init()</tt>
<tt>      {  paused = false;</tt>
<tt>         Color bg = new Color(255,255,192);</tt>
<tt>         setBackground(Color.black);</tt>
<tt>         setLayout(new BorderLayout());</tt>
<tt>         cv = new PrisCanv(this);</tt>
<tt>         add(&#8221;Center&#8221;, cv);</tt>
<tt>         pn = new PrisPan(this);</tt>
<tt>         add(&#8221;North&#8221;, pn);</tt>
<tt>      </tt>
<tt>      }</tt>
<tt>   </tt>
<tt>      public void stop()</tt>
<tt>      {  cv.stop();</tt>
<tt>         cv.thr = null;</tt>
<tt>         remove(cv);</tt>
<tt>         remove(pn);</tt>
<tt>      }</tt>
<tt>   }</tt>

<tt>   class PrisPan extends Panel</tt>
<tt>   implements ActionListener, ItemListener</tt>
<tt>   {  Pris00 ap;</tt>
<tt>   </tt>
<tt>      TextField tfb, tfp, tfd;</tt>
<tt>      Button bR,bB;</tt>
<tt>      Checkbox cb;</tt>
<tt>      Label lb;</tt>
<tt>   </tt>
<tt>      public PrisPan(Pris00 ap)</tt>
<tt>      {  this.ap=ap;</tt>
<tt>         Color bg = new Color(255,255,192);</tt>
<tt>         setBackground(bg);</tt>
<tt>         Label lbb = new Label(&#8221;b =&#8221;,Label.RIGHT);</tt>
<tt>         Label lbp = new Label(&#8221;p =&#8221;,Label.RIGHT);</tt>
<tt>         Label lbd = new Label(&#8221;delay:&#8221;,Label.RIGHT);</tt>
<tt>         tfb = new TextField(5);</tt>
<tt>         tfp = new TextField(5);</tt>
<tt>         tfd = new TextField(5);</tt>
<tt>         tfb.setText(String.valueOf(ap.b));</tt>
<tt>         tfp.setText(String.valueOf(ap.p));</tt>
<tt>         tfd.setText(String.valueOf(ap.delay));</tt>
<tt>         lb = new Label(&#8221;   &#8220;);</tt>
<tt>         bR = new Button(&#8221;Run&#8221;);</tt>
<tt>         bR.addActionListener(this);</tt>
<tt>         bB = new Button(&#8221;Break&#8221;);</tt>
<tt>         bB.addActionListener(this);</tt>
<tt>         bB.setEnabled(false);</tt>
<tt>         cb = new Checkbox(&#8221;pause&#8221;);</tt>
<tt>         cb.addItemListener(this);</tt>
<tt>         cb.setEnabled(false);</tt>
<tt>         add(lbb);</tt>
<tt>         add(tfb);</tt>
<tt>         add(lbp);</tt>
<tt>         add(tfp);</tt>
<tt>         add(lbd);</tt>
<tt>         add(tfd);</tt>
<tt>         add(lb);</tt>
<tt>         add(bR);</tt>
<tt>         add(bB);</tt>
<tt>         add(cb);</tt>
<tt>      }</tt>
<tt>   </tt>
<tt>      public void actionPerformed(ActionEvent evt)</tt>
<tt>      {  String tb = tfb.getText();</tt>
<tt>         String tp = tfp.getText();</tt>
<tt>         String td = tfd.getText();</tt>
<tt>         ap.b = Double.valueOf(tb).floatValue();</tt>
<tt>         ap.p = Double.valueOf(tp).floatValue();</tt>
<tt>         ap.delay = Integer.valueOf(td).intValue();</tt>
<tt>         if (evt.getSource() == bR)</tt>
<tt>         {  </tt>
<tt>            if (ap.cv.thr == null)</tt>
<tt>            {  ap.cv.start();</tt>
<tt>               tfb.setEnabled(false);</tt>
<tt>               tfp.setEnabled(false);</tt>
<tt>               tfd.setEnabled(false);</tt>
<tt>               bR.setEnabled(false);</tt>
<tt>               bB.setEnabled(true);</tt>
<tt>               cb.setState(false);</tt>
<tt>               ap.paused = false;</tt>
<tt>               cb.setEnabled(true);</tt>
<tt>            }</tt>
<tt>         }</tt>
<tt>         if (evt.getSource() == bB)</tt>
<tt>         {  </tt>
<tt>            if (ap.cv.thr != null)</tt>
<tt>            {  ap.cv.stop(); </tt>
<tt>               ap.cv.repaint();</tt>
<tt>               tfb.setEnabled(true);</tt>
<tt>               tfp.setEnabled(true);</tt>
<tt>               tfd.setEnabled(true);</tt>
<tt>               bR.setEnabled(true);</tt>
<tt>               bB.setEnabled(false);</tt>
<tt>               cb.setState(false); // -&gt; NA</tt>
<tt>               ap.paused = false;</tt>
<tt>               cb.setEnabled(false);               </tt>
<tt>            }</tt>
<tt>         }</tt>
<tt>      }</tt>

<tt>      public void itemStateChanged(ItemEvent evt)</tt>
<tt>      {  ap.paused = cb.getState();</tt>
<tt>      }</tt>
<tt>   }</tt>

<tt>   class PrisCanv extends Canvas</tt>
<tt>   implements Runnable</tt>
<tt>   {  Pris00 ap;</tt>
<tt>      Thread thr = null;</tt>
<tt>      double p;                        </tt>
<tt>      int n;                         </tt>
<tt>      int[][] s; </tt>
<tt>      int[][]sn; </tt>
<tt>      int[] bc;                      </tt>
<tt>      double[][] pm;                  </tt>
<tt>      double[][] payoff;              </tt>
<tt>      double b;             </tt>
<tt>      Color c[][];</tt>
<tt>      int ssn[][];</tt>
<tt>      double h;</tt>
<tt>      Image im;</tt>
<tt>      Graphics gIm;</tt>
<tt>      Dimension d;</tt>
<tt>      int x,y;</tt>
<tt>      boolean painted;</tt>
<tt>   </tt>
<tt>      PrisCanv(Pris00 ap)</tt>
<tt>      {  Color bg = new Color(255,255,192);</tt>
<tt>         setBackground(bg);</tt>
<tt>         this.ap = ap;</tt>
<tt>      }</tt>
<tt>   </tt>
<tt>   </tt>
<tt>      void start()</tt>
<tt>      {  </tt>
<tt>         if (thr == null)</tt>
<tt>         {  thr = new Thread(this);</tt>
<tt>            thr.start();</tt>
<tt>         }</tt>
<tt>      }</tt>
<tt>   </tt>
<tt>      void stop()</tt>
<tt>      {  </tt>
<tt>         if (thr != null)</tt>
<tt>         {  thr.stop();</tt>
<tt>            thr = null;</tt>
<tt>         }</tt>
<tt>      }</tt>
<tt>   </tt>
<tt>      public void run()</tt>
<tt>      {  initialize();</tt>
<tt>         for (;;) </tt>
<tt>         {  if (!ap.paused)</tt>
<tt>            {  </tt>
<tt>               calculate();                                               </tt>
<tt>               if (im == null)</tt>
<tt>               {  im = createImage(5*n,5*n);</tt>
<tt>                  gIm = im.getGraphics();</tt>
<tt>               }</tt>
<tt>               {  for (int i=1; i&lt;=n; i++)                                                          </tt>
<tt>                  {                                                                                 </tt>
<tt>                     for (int j=1; j&lt;=n; j++)                                                       </tt>
<tt>                     {                                                                              </tt>
<tt>                        gIm.setColor(c[sn[i][j]][s[i][j]]);                                           </tt>
<tt>                        gIm.fillRect(j*5,i*5,5,5);</tt>
<tt>                        s[i][j] = sn[i][j];</tt>
<tt>                     }                                                                              </tt>
<tt>                  }</tt>
<tt>               }</tt>
<tt>               painted = false;               </tt>
<tt>               repaint();</tt>
<tt>               try {Thread.sleep(ap.delay);} </tt>
<tt>               catch(InterruptedException e){}</tt>
<tt>               while (!painted) {;}        </tt>
<tt>            }</tt>
<tt>         }</tt>
<tt>      }</tt>
<tt>   </tt>
<tt>      void initialize()</tt>
<tt>      {  b = ap.b;                            </tt>
<tt>         p = ap.p;                               </tt>
<tt>         n=60;</tt>
<tt>         int bc[] = new int[n+1];</tt>
<tt>         double pm[][] = new double[3][3];         </tt>
<tt>         pm[1][1]=1;                                                                            </tt>
<tt>         pm[1][2]=0;                                                                            </tt>
<tt>         pm[2][1]=b;                                                                            </tt>
<tt>         pm[2][2]=0;                                                                            </tt>
<tt>         this.pm=pm;                                                                                       </tt>
<tt>         Color c[][] = new Color[3][3];                                                       </tt>
<tt>         c[1][1] = new Color(0,0,255);    // blue                                             </tt>
<tt>         c[2][2] = new Color(255,0,0);    // red                                              </tt>
<tt>         c[1][2] = new Color(0,255,0);    // green                                           </tt>
<tt>         c[2][1] = new Color(255,255,0);  // yellow</tt>
<tt>         this.c=c;</tt>
<tt>         bc = setBoundary(n);</tt>
<tt>         this.bc=bc;</tt>
<tt>         s=generate(n,p);</tt>
<tt>         sn=new int[n+1][n+1];</tt>
<tt>         this.s=s;</tt>
<tt>         this.sn=sn;</tt>
<tt>         payoff = new double[61][61];</tt>
<tt>         d = getSize();</tt>
<tt>         this.d = d;</tt>
<tt>         x = (int)(d.width/2 - 5*n / 2);                                             </tt>
<tt>         y = (int)(d.height/2 - 5*n / 2);</tt>
<tt>         painted = false;                                            </tt>
<tt>      }</tt>
<tt>   </tt>
<tt>      public void update(Graphics g)</tt>
<tt>      {</tt>
<tt>         paint(g);</tt>
<tt>      }</tt>
<tt>   </tt>
<tt>      public void paint(Graphics g)</tt>
<tt>      {  if (thr == null) </tt>
<tt>         {  if (d != null) </tt>
<tt>            {  g.clearRect(0, 0, d.width, d.height);</tt>
<tt>            }</tt>
<tt>            return;</tt>
<tt>         }</tt>
<tt>         painted = g.drawImage(im, x, y, null); </tt>
<tt>      }</tt>
<tt>   </tt>
<tt>      int[][] generate(int n, double p)                       </tt>
<tt>      {  int s[][] = new int[n+1][n+1];                      </tt>
<tt>         for (int i=1; i&lt;=n; i++)                            </tt>
<tt>         {                                                   </tt>
<tt>            for (int j=1; j&lt;=n; j++)                         </tt>
<tt>            {                                                </tt>
<tt>               s[i][j] = 1;                                  </tt>
<tt>               if (Math.random()&lt;p) s[i][j] = 2;             </tt>
<tt>            }                                                </tt>
<tt>         }                                                   </tt>
<tt>         return s;                                              </tt>
<tt>      }                                                      </tt>
<tt>   </tt>
<tt>      int[] setBoundary(int n)                        </tt>
<tt>      {  int bc[] = new int[n+2];                            </tt>
<tt>         for (int i=1; i&lt;=n; i++)                            </tt>
<tt>         { bc[i]=i;                                          </tt>
<tt>         }                                                   </tt>
<tt>         bc[0]=n;                                            </tt>
<tt>         bc[n+1]=1;                                          </tt>
<tt>         return bc;                                          </tt>
<tt>      }                                                      </tt>
<tt>   </tt>
<tt>      void calculate()</tt>
<tt>      {  int i,j,k,l;                                                                         </tt>
<tt>         double pa,hp;                                                                             </tt>
<tt>         for (i=1; i&lt;=n; i++)                                                                     </tt>
<tt>         {  for (j=1; j&lt;=n; j++)                                                                  </tt>
<tt>            {  pa=0;                                                                              </tt>
<tt>               for (k=-1; k&lt;=1; k++)                                                              </tt>
<tt>               {  for (l=-1; l&lt;=1; l++)                                                           </tt>
<tt>                  {  pa += pm[s[i][j]][s[bc[i+k]][bc[j+l]]];                                      </tt>
<tt>                  }                                                                               </tt>
<tt>               }                                                                                  </tt>
<tt>               payoff[i][j] = pa;                                                                 </tt>
<tt>            }                                                                                     </tt>
<tt>         }                                                                                        </tt>
<tt>      </tt>
<tt>         for (i=1; i&lt;=n; i++)                                                                     </tt>
<tt>         {  </tt>
<tt>            for (j=1; j&lt;=n; j++)                                                                  </tt>
<tt>            {  hp = payoff[i][j];                                                                 </tt>
<tt>               sn[i][j] = s[i][j];                                                                 </tt>
<tt>               for (k=-1; k&lt;=1; k++)                                                              </tt>
<tt>               {  </tt>
<tt>                  for (l=-1; l&lt;=1; l++)                                                           </tt>
<tt>                  {  </tt>
<tt>                     if (payoff[bc[i+k]][bc[j+l]] &gt; hp)                                           </tt>
<tt>                     {  hp = payoff[bc[i+k]][bc[j+l]];                                            </tt>
<tt>                        sn[i][j] = s[bc[i+k]][bc[j+l]];                                                </tt>
<tt>                     }                                                                            </tt>
<tt>                  }                                                                               </tt>
<tt>               }                                                                                  </tt>
<tt>            }                                                                                     </tt>
<tt>         }                                                                                        </tt>
<tt>      }</tt>
<tt>   }</tt></pre>
]]></content:encoded>
			<wfw:commentRss>http://pygmalion.groenefee.nl/prisoners-dilemma-applet-3.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
