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

<channel>
	<title>Ken-Soft</title>
	<atom:link href="http://ken-soft.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://ken-soft.com</link>
	<description>Software Development and the World</description>
	<pubDate>Fri, 03 Sep 2010 02:19:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Base N to 10 Conversion Class - PHP (Base 62 Implementation)</title>
		<link>http://ken-soft.com/?p=544</link>
		<comments>http://ken-soft.com/?p=544#comments</comments>
		<pubDate>Wed, 01 Sep 2010 02:11:38 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[PHP]]></category>

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

		<category><![CDATA[Web Development]]></category>

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

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

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

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

		<category><![CDATA[URL Shortener]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=544</guid>
		<description><![CDATA[This class can be used convert a base N number into base 10, and back. (Which makes it ideal for usage in technologies such as URL shorteners.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
&#60;?php
/**
 * BNID - Base N &#60;=&#62; 10 converter
 *
 * @author kenny cason
 * @site www.ken-soft.com
 */
class BNID &#123;
        // Alphabet [...]]]></description>
			<content:encoded><![CDATA[<p>This class can be used convert a base N number into base 10, and back. (Which makes it ideal for usage in technologies such as URL shorteners.)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * BNID - Base N &lt;=&gt; 10 converter
 *
 * @author kenny cason
 * @site www.ken-soft.com
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> BNID <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Alphabet of Base N (This is a Base 62 Implementation)</span>
        <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$bN</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'2'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'3'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'4'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'5'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'6'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'7'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'8'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'9'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'A'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'C'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'D'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'E'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'F'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'G'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'H'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'I'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'J'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'K'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'L'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'M'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'N'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'O'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'P'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Q'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'R'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'S'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'T'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'U'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'V'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'W'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'X'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Y'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Z'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'e'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'f'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'g'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'h'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'i'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'j'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'k'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'l'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'m'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'n'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'o'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'p'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'q'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'r'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'s'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'t'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'u'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'v'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'y'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'z'</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
       <span style="color: #666666; font-style: italic;">// Alphabet of Base 86 (comment out the B62 array and comment this to try it out)</span>
       <span style="color: #666666; font-style: italic;">/*var $bN = array(
            '0','1','2','3','4','5','6','7','8','9',
            'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
            'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
	    '-','+','_','%','|','@','!','$','*','~','`','#','(',')','=','&amp;','[',']','{','}','&lt;','&gt;',':',';'
        );*/</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$baseN</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseN</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// convert base 10 to base N</span>
        <span style="color: #000000; font-weight: bold;">function</span> base10ToN<span style="color: #009900;">&#40;</span><span style="color: #000088;">$b10num</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$bNnum</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$bNnum</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bN</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$b10num</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseN</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$bNnum</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$b10num</span> <span style="color: #339933;">/=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseN</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$b10num</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$bNnum</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// convert base N to base 10</span>
        <span style="color: #000000; font-weight: bold;">function</span> baseNTo10<span style="color: #009900;">&#40;</span><span style="color: #000088;">$bNnum</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #000088;">$b10num</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bNnum</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$len</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bN</span><span style="color: #339933;">,</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bNnum</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$b10num</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseN</span><span style="color: #339933;">,</span> <span style="color: #000088;">$len</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$b10num</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/*
// test, uncomment and call this script to demonstrate it's functionality
$conv = new BNID();
$max = pow($conv-&gt;baseN, 2);
for($i = 0; $i &lt;= $max; $i++) {
    echo $conv-&gt;base10ToN($i).&quot;, &quot;;
}
echo &quot;&lt;br/&gt;&lt;br/&gt;&quot;;
for($i = 0; $i &lt;= $max; $i++) {
    $x = $conv-&gt;base10ToN($i);
    echo $conv-&gt;baseNTo10($x).&quot;, &quot;;
}
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If you want to use this as a URL shortener, below is a quick demo of how to use URL Rewrite to accept www.page.com/<BaseNID> and forward it to some page to process the ID (i.e. convert to base 10 ID and query a URL from the Database using the ID). The below implementation will work for a base 62 alphabet comprised of [0-9][A-Z][a-z], which is the demo I posted.<br />
place the below text in <b>.htaccess</b> in your websites root directory<br/><br />
<code>Options +FollowSymlinks<br />
RewriteEngine on<br />
RewriteBase /yourrootdirectory/<br />
RewriteRule ^(([A-Z]*[a-z]*[0-9]*)*)$ main.php?b62id=$1 [L,QSA]<br />
</code></p>
<p>So it should take a domain  www.abc.com, if you specify <b>www.abc.com/zA4F</b>, it would forward to <b>www.abc.com/main.php?id=14576711</b><br />
<b>Here is a sample Demo</b><a href="http://www.ken-soft.com/code/php/baseconvert/AABCz23" target="blank">http://www.ken-soft.com/code/php/baseconvert/AABCz23</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=544</wfw:commentRss>
		</item>
		<item>
		<title>Ackermann–Péter function (2 arguments) - C/C++ - Recursive Implentation</title>
		<link>http://ken-soft.com/?p=524</link>
		<comments>http://ken-soft.com/?p=524#comments</comments>
		<pubDate>Fri, 16 Jul 2010 19:06:22 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

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

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

		<category><![CDATA[Ackermann–Péter]]></category>

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

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

		<category><![CDATA[total computable]]></category>

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

		<guid isPermaLink="false">http://ken-soft.com/?p=524</guid>
		<description><![CDATA[This is an implementation of the 2 argument version of the Ackermann Function (i.e. Ackermann-Péter function). In essence, this is an example of a very simple recursive function is an example of a total computable function that is not primitive recursive. Instead of making the internet even more redundant with unnecessary text, just click the [...]]]></description>
			<content:encoded><![CDATA[<p>This is an implementation of the 2 argument version of the <a target="blank" href="http://en.wikipedia.org/wiki/Ackermann_function">Ackermann Function</a> (i.e. Ackermann-Péter function). In essence, this is an example of a very simple recursive function is an example of a total computable function that is not primitive recursive. Instead of making the internet even more redundant with unnecessary text, just click the above link to view the entire Wikipedia article.<br />
Function&#8217;s like these are very fun to play with. I often think about the human brain and how it functions when I see these kinds of functions. Taking input from the environment and processing it, sometimes recursively (like in a thought cycle), then converging to some or many outputs.<br />
C Implentation:<br />
<b>note</b>This function grows extremely fast, such that it quickly out grows any primitive type in C, including the largest &#8220;unsigned long long&#8221; type. Though the program will likely crash with a 0xC0000005 error from too much recursion <img src='http://ken-soft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
It should run fine from A(0,0) to A(4,0) and likely crash while computing A(4,1), which is 65533. A(4,0) is 13, so the number of recursive calls jumps up enormously! I will be working on a custom, larger data type as well as a way around the error caused by too much recursion.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * Ackermann function - recursive implementation
 */</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> <span style="color: #993333;">long</span> A<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> <span style="color: #993333;">long</span> m<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> <span style="color: #993333;">long</span> n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>m <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> n <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>n <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> A<span style="color: #009900;">&#40;</span>m <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> A<span style="color: #009900;">&#40;</span>m <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> A<span style="color: #009900;">&#40;</span>m<span style="color: #339933;">,</span> n <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The entire source implentation can be found <a target="blank" href="http://ken-soft.com/code/c/ackermann/main.cpp">here</a><br />
I obtained a list of some of the expected values from this site ->     <a target="blank" href="http://www-users.cs.york.ac.uk/susan/cyc/a/ackermnn.htm">http://www-users.cs.york.ac.uk/susan/cyc/a/ackermnn.htm</a><br />
Here are some of the values for 0 < m < 5, 0 < n < 6</p>
<table color="#000000" align="left" bgcolor="#eeeeee" border="0">
<tbody>
<tr bgcolor="#cccccc">
<td></td>
<td>n=0</td>
<td>n=1</td>
<td>n=2</td>
<td>n=3</td>
<td>n=4</td>
<td>n=5</td>
</tr>
<tr>
<td bgcolor="#cccccc">m=0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td bgcolor="#cccccc">m=1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td bgcolor="#cccccc">m=2</td>
<td>3</td>
<td>5</td>
<td>7</td>
<td>9</td>
<td>11</td>
<td>13</td>
</tr>
<tr>
<td bgcolor="#cccccc">m=3</td>
<td>5</td>
<td>13</td>
<td>29</td>
<td>61</td>
<td>125</td>
<td>253</td>
</tr>
<tr>
<td bgcolor="#cccccc">m=4</td>
<td>13</td>
<td>65533</td>
<td>265536-3</td>
<td>2265536-3</td>
<td>A(3,2265536-3)</td>
<td>A(3,A(4,4))</td>
</tr>
</tbody>
</table>
<p>Some of the patterns formed are very amazing. For example: A(2, n), 0 <= n < infinite, will list odd numbers starting from 3 to infinite.<br />
To demonstrate this just insert the below loop into your code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> n <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> n <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">100</span><span style="color: #339933;">;</span> n<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      std<span style="color: #339933;">::</span><span style="color: #000066;">cout</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #ff0000;">&quot;A(2, &quot;</span> <span style="color: #339933;">&lt;&lt;</span> n <span style="color: #339933;">&lt;&lt;</span> <span style="color: #ff0000;">&quot;) = &quot;</span> <span style="color: #339933;">&lt;&lt;</span> A<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> n<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> std<span style="color: #339933;">::</span><span style="color: #202020;">endl</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=524</wfw:commentRss>
		</item>
		<item>
		<title>Simulation Program (Motivated John Conway&#8217;s Game of Life) - C/C++</title>
		<link>http://ken-soft.com/?p=512</link>
		<comments>http://ken-soft.com/?p=512#comments</comments>
		<pubDate>Wed, 14 Jul 2010 03:33:44 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

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

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

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

		<category><![CDATA[Game of Life]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=512</guid>
		<description><![CDATA[In this little simulation demo I created four simple rules, of which can be activated by uncommenting them out in the source code. Though nothing too complex emerges, I still liked some the resulting behavior.
Particularly, rule1(), results in colors slowly grouping together in various forms. It may be hard to immediately noticed so watch carefully. [...]]]></description>
			<content:encoded><![CDATA[<p>In this little simulation demo I created four simple rules, of which can be activated by uncommenting them out in the source code. Though nothing too complex emerges, I still liked some the resulting behavior.<br />
Particularly, rule1(), results in colors slowly grouping together in various forms. It may be hard to immediately noticed so watch carefully. This was motivated by <a href="http://ken-soft.com/?p=481">John Conway&#8217;s Game of Life</a>.<br />
The program was written in C/C++, all graphics are done using <a href="http://www.libsdl.org">SDL</a><br />
The whole source can be found here <a href="http://ken-soft.com/code/c/Life2/main.cpp">main.cpp</a><br />
<b>Compile</b><code>g++ main.cpp -lSDL</code><br />
<b>Run</b><code>./a.out</code></p>
<table>
<tr>
<td><a href="http://ken-soft.com/code/c/Life2/Life-1.png" target="_blank"><img src="http://ken-soft.com/code/c/Life2/Life-1.png" width="275" alt="Game of Life Patterns" /></td>
<td><a href="http://ken-soft.com/code/c/Life2/Life-4.png" target="_blank"><img src="http://ken-soft.com/code/c/Life2/Life-4.png" width="275" alt="Game of Life Patterns" /></td>
</tr>
<tr>
<td><a href="http://ken-soft.com/code/c/Life2/Life-8.png" target="_blank"><img src="http://ken-soft.com/code/c/Life2/Life-8.png" width="275" alt="Game of Life Patterns" /></td>
<td><a href="http://ken-soft.com/code/c/Life2/Life-9.png" target="_blank"><img src="http://ken-soft.com/code/c/Life2/Life-9.png" width="275" alt="Game of Life Patterns" /></td>
</tr>
</table>
<p>Rule1()</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> worldWidth<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> worldHeight<span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">int</span> r <span style="color: #339933;">=</span> world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> g <span style="color: #339933;">=</span> world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> b <span style="color: #339933;">=</span> world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span><span style="color: #339933;">;</span>
        <span style="color: #808080; font-style: italic;">/*
          o o o
          o x o
          o o o
        */</span>
        <span style="color: #666666; font-style: italic;">// RULES</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">&amp;&amp;</span> y <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// top left</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>y <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// top</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&lt;</span> worldWidth <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">&amp;&amp;</span> y <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// top right</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//  left</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&lt;</span> worldWidth <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// right</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">&amp;&amp;</span> y <span style="color: #339933;">&lt;</span> worldHeight <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// bottom left</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>y <span style="color: #339933;">&lt;</span> worldHeight <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// bottom</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&lt;</span> worldWidth <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">&amp;&amp;</span> y <span style="color: #339933;">&lt;</span> worldHeight <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// bottom right</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> b<span style="color: #339933;">--;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>world<span style="color: #009900;">&#91;</span>x <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                r<span style="color: #339933;">--;</span> g<span style="color: #339933;">--;</span> b<span style="color: #339933;">+=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>r <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            r <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>g <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            g <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>b <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            b <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>r <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">255</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            r <span style="color: #339933;">=</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>g <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">255</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            g <span style="color: #339933;">=</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>b <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">255</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            b <span style="color: #339933;">=</span> <span style="color: #0000dd;">255</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">r</span> <span style="color: #339933;">=</span> r<span style="color: #339933;">;</span>
        world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">g</span> <span style="color: #339933;">=</span> g<span style="color: #339933;">;</span>
        world<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">b</span> <span style="color: #339933;">=</span> b<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=512</wfw:commentRss>
		</item>
		<item>
		<title>Is Prime Number Algorithm</title>
		<link>http://ken-soft.com/?p=502</link>
		<comments>http://ken-soft.com/?p=502#comments</comments>
		<pubDate>Mon, 12 Jul 2010 18:03:43 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

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

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

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

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=502</guid>
		<description><![CDATA[I was randomly surfing around the internet when I stumbled upon Google Labs Aptitude Test (GLAT)(Found here). I can&#8217;t really remember which links I followed from there but I stumbled into a question that asks to find the first 10 consecutive digits of E that are prime. While definitely not a hard task I wrote [...]]]></description>
			<content:encoded><![CDATA[<p>I was randomly surfing around the internet when I stumbled upon Google Labs Aptitude Test (GLAT)<a href="http://cruftbox.com/blog/archives/001031.html">(Found here)</a>. I can&#8217;t really remember which links I followed from there but I stumbled into a question that asks to find the first 10 consecutive digits of E that are prime. While definitely not a hard task I wrote a small program in C to test whether or not a number is prime. </p>
<p>The core function isPrime() is below</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">long</span> <span style="color: #993333;">long</span> isPrime<span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #993333;">double</span> n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// is n an integer ?</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>n <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span> n <span style="color: #339933;">!=</span> <span style="color:#800080;">1.0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// is n even? (half of the numbers)</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span>n <span style="color: #339933;">%</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>n <span style="color: #339933;">==</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #993333;">long</span> <span style="color: #993333;">long</span> root <span style="color: #339933;">=</span> sqrtl<span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// is the number divisible by n, such that n &gt; 2 and n &lt;= sqrt(number)?</span>
    <span style="color: #666666; font-style: italic;">// if so then the number is composite</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #993333;">long</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> root<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">long</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span> n <span style="color: #339933;">%</span> i <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> i<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// it is prime!</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><b>note:</b> I use long long just to allow the calculation of bigger numbers. Though if the number gets to large enough this algorithm can still slow down a bit, as it could potentially have to iterate from 3 to the square root of the number being tested. For most cases this algorithm executes plenty fast enough and it is definitely better than iterating over every number between 1 and N, as many sites do.<br />
the entire implementation is here:<a target="blank" href="http://ken-soft.com/code/c/prime/main.cpp">main.cpp</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=502</wfw:commentRss>
		</item>
		<item>
		<title>Create a Multilingual Website in PHP using a MySQL database</title>
		<link>http://ken-soft.com/?p=496</link>
		<comments>http://ken-soft.com/?p=496#comments</comments>
		<pubDate>Tue, 12 Jan 2010 22:32:02 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Language Software]]></category>

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

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

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[Web Development]]></category>

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

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

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

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=496</guid>
		<description><![CDATA[In a previous post I showed how to make a simple multilingual website using a hash array. This post will demonstrate how to design a multilingual website in PHP backed by a MySQL database. To see a simple demo open the following link HERE
1. Create the DataBase
First create a MySQL Database called language (or whatever [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://ken-soft.com/?p=6" target="_blank">previous post</a> I showed how to make a simple multilingual website using a hash array. This post will demonstrate how to design a multilingual website in PHP backed by a MySQL database. To see a simple demo open the following link <a href="http://ken-soft.com/code/php/langDB/index.php" target="_blank">HERE</a></p>
<p><b>1. Create the DataBase</b><br />
First create a MySQL Database called language (or whatever you want). Next, copy the below code into a file (language.sql) and import into your database (import as utf8). You can of course also enter the commands manually. Each language is in it&#8217;s own database and has a charset of utf8 to support multiple languages. Every &#8216;text&#8217; entry is referenced by a corresponding &#8216;textid&#8217;. The textid, for example &#8216;FNAME&#8217; will appear in each database, but will correspond to a different word depending on the langauge.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`languages`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`lang`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`description`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>   <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8 COLLATE<span style="color: #66cc66;">=</span>utf8_unicode_ci;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`lang_en`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`textid`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> collate latin1_general_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`text`</span> longtext charset utf8 collate utf8_unicode_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8 COLLATE<span style="color: #66cc66;">=</span>utf8_unicode_ci;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`lang_jp`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`textid`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> collate latin1_general_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`text`</span> longtext charset utf8 collate utf8_unicode_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8 COLLATE<span style="color: #66cc66;">=</span>utf8_unicode_ci;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`lang_zh`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`textid`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> collate latin1_general_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`text`</span> longtext charset utf8 collate utf8_unicode_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8 COLLATE<span style="color: #66cc66;">=</span>utf8_unicode_ci;
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`languages`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`lang`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`description`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'en'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'English'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'jp'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Japanese'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'zh'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Chinese'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`lang_en`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`textid`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`text`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'FNAME'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'First Name'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LNAME'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Last Name'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SUBMIT'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Submit'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LANG_EN'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'English'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LANG_JP'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Japanese'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LANG_ZH'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'Chinese'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`lang_jp`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`textid`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`text`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'FNAME'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'名'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LNAME'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'姓'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SUBMIT'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'確認'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LANG_EN'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'英語'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LANG_JP'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'日本語'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LANG_ZH'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'中国語'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #ff0000;">`lang_zh`</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`textid`</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">`text`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'FNAME'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'名'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LNAME'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'姓'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SUBMIT'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'确定'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LANG_EN'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'英语'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LANG_JP'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'日语'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'LANG_ZH'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'中文简体'</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p><b>2. Create Language Class in PHP</b><br />
The below class is just one implementation, so feel free to customize this however you want to fit your needs. Note the usage of the default language. I implement this just in case a user stumbles across a page where the text is not translated so that it can resort to a default. Some text looks better than none <img src='http://ken-soft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Having everything in one function get() makes it easy for me to affect all the text on the whole website at once. It also allows me to later add in a &#8220;Suggest better translation &#8221; button, or any other number of features that you wish.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Small Wrapper class to manage Languages stored in a MySQL DB
 * Extended functionality will be added soon
 * @author Kenny Cason
 * @site www.ken-soft.com
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> Language <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$defaultlang</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;en&quot;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">// Default Language</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$languages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;en&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// mysqli instance;</span>
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$db</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$defaultlang</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$defaultlang</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaultlang</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$defaultlang</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLanguageIDs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Get text from DB given a specific Text ID and Language
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$textid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$langid</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$langid</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$langid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaultlang</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT text FROM lang_<span style="color: #006699; font-weight: bold;">$langid</span> WHERE textid='<span style="color: #006699; font-weight: bold;">$textid</span>'&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$langid</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaultlang</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  <span style="color: #666666; font-style: italic;">// if language is default, return the langauge unchecked.</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Is text field un-translated? (i.e. not empty string)</span>
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// If not, query using default language</span>
                <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$textid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaultlang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Return an Array of Language IDs of each language in the Database
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getLanguageIDs<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$languages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT lang FROM languages&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$result</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$languages</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$languages</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Return an Array of Descriptions of each language in the Database.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getLanguageDescriptions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$languagesDesc</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT description FROM languages&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$result</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$languagesDesc</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$languagesDesc</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Delete a Text ID from all Language Tables
     * @param $textid
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deleteTextID<span style="color: #009900;">&#40;</span><span style="color: #000088;">$textid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$textid</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$numLanguages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$numLanguages</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DELETE FROM lang_&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE textid='<span style="color: #006699; font-weight: bold;">$textid</span>'&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Deleted TextID &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$textid</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$status</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Update Text for a specific Language
     * @param $langid
     * @param $textid
     * @param $text
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> updateText<span style="color: #009900;">&#40;</span><span style="color: #000088;">$langid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$textid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$langid</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$textid</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$text</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UPDATE lang_<span style="color: #006699; font-weight: bold;">$langid</span> SET text='<span style="color: #006699; font-weight: bold;">$text</span>' WHERE textid='<span style="color: #006699; font-weight: bold;">$textid</span>' &quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Updated Entry&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$status</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Delete a Language from the Database
     * @param $langid
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deleteLanguage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$langid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$langid</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DROP TABLE IF EXISTS lang_&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$langid</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DELETE FROM languages WHERE lang='<span style="color: #006699; font-weight: bold;">$langid</span>'&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;Deleted Language Table &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$langid</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Add TextID field to all language databases
     * @param $textid
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addTextID<span style="color: #009900;">&#40;</span><span style="color: #000088;">$textid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$numLanguages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$numLanguages</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$status</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO lang_&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">languages</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; (`textid`, `text`) VALUES ('<span style="color: #006699; font-weight: bold;">$textid</span>', '')&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$status</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Added Text ID&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$status</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Add a new Language
     * @paam $langID is typically a 2 letter ID (English is 'en', Japanese is 'jp')
     * The created database is 'lang_$langID' (lang_en, lang_jp)
     * @param $langDesc is the Description for the language.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addLanguage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$langid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$langdesc</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$langid</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$langdesc</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO languages (`lang`, `description`) VALUES ('<span style="color: #006699; font-weight: bold;">$langid</span>', '<span style="color: #006699; font-weight: bold;">$langdesc</span>')&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;CREATE TABLE IF NOT EXISTS `lang_<span style="color: #006699; font-weight: bold;">$langid</span>` (
        	`textid` varchar(255) collate latin1_general_ci NOT NULL,
                `text` longtext charset utf8 collate utf8_unicode_ci NOT NULL
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT textid FROM lang_en&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO lang_<span style="color: #006699; font-weight: bold;">$langid</span> (`textid`, `text`) VALUES ('<span style="color: #006699; font-weight: bold;">$row[0]</span>', '')&quot;</span><span style="color: #339933;">;</span>
        	<span style="color: #000088;">$result2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Added Language&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$status</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><b>3. Put everything together</b><br />
Finally we will create our index.php file to demonstrate how to use everything. In the beginning of the code connect to the Database of your choice. For the purpose of this simple demo the language parameter ($lang) can be passed to the page, and is English (en) by default. This could ideally be queried from the users profile, etc. Also notice that each time you want to print text just call the appropriate function in the Language class. The below example demonstrates to ways to print the Japanese text (名) referred to by the textid FNAME</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$lang</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jp&quot;</span> <span style="color: #666666; font-style: italic;">// Japanese</span>
<span style="color: #666666; font-style: italic;">// create a new Langauge Object</span>
<span style="color: #000088;">$obj_lang</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Language<span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FNAME'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Two other <b>VERY IMPORTANT</b> lines are:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;/&gt;</pre></td></tr></table></div>

<p>Set the page incoding to UTF-8.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_charset</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>AND, set the charset for your mysql queries. Otherwise you&#8217;ll get a bunch of &#8220;?&#8221;&#8217;s and likely wonder what it is your doing wrong&#8230; or at least I did. <img src='http://ken-soft.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
Here is the whole index.php</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Language.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to a MySql DB, usually have a seperate file, or DB class to do this.</span>
<span style="color: #000088;">$DB_HOST</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;HOSTNAME&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$DB_USER</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;USERNAME&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$DB_PASSWORD</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;PASSWORD&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$DB_DATABASE</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'language'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$DB_PORT</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;</span>PORT<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #000088;">$DB_HOST</span><span style="color: #339933;">,</span> <span style="color: #000088;">$DB_USER</span><span style="color: #339933;">,</span> <span style="color: #000088;">$DB_PASSWORD</span><span style="color: #339933;">,</span> <span style="color: #000088;">$DB_DATABASE</span><span style="color: #339933;">,</span><span style="color: #000088;">$DB_PORT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_charset</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utf8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// create a new Langauge Object</span>
<span style="color: #000088;">$obj_lang</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Language<span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// ideally pull this from a users profile.</span>
<span style="color: #000088;">$lang</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;lang&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;html&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;/&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
	&lt;a href=&quot;index.php?lang=en&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LANG_EN'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;|&lt;a href=&quot;index.php?lang=jp&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LANG_JP'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;|&lt;a href=&quot;index.php?lang=zh&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LANG_ZH'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;
	&lt;form&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FNAME'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>:&lt;input type=&quot;text&quot; name=&quot;firstname&quot; /&gt;&lt;br /&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LNAME'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>:&lt;input type=&quot;text&quot; name=&quot;lastname&quot; /&gt;&lt;br /&gt;
		&lt;select name=&quot;lang&quot;&gt;
			&lt;option value=&quot;en&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LANG_EN'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/option&gt;
			&lt;option value=&quot;jp&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LANG_JP'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/option&gt;
			&lt;option value=&quot;zh&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LANG_ZH'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/option&gt;
		&lt;/select&gt;&lt;br /&gt;
		&lt;input type=&quot;submit&quot; value=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000088;">$obj_lang</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SUBMIT'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> /&gt;
	&lt;/form&gt; 
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Again, the link to the demo using the following code can be found <a href="http://ken-soft.com/code/php/langDB/index.php" target="_blank">HERE</a><br />
Hope this is useful to someone.<br />
<b>Note: these are recent updates. Let me know if you find any bugs. <img src='http://ken-soft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> thanks</b></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=496</wfw:commentRss>
		</item>
		<item>
		<title>John Conway&#8217;s Game of Life + Mutation (C/C++)</title>
		<link>http://ken-soft.com/?p=481</link>
		<comments>http://ken-soft.com/?p=481#comments</comments>
		<pubDate>Tue, 22 Dec 2009 14:37:49 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[General Development]]></category>

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

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

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

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[C++]]></category>

		<category><![CDATA[cellular automata]]></category>

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

		<category><![CDATA[John Conways Game of Life]]></category>

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

		<category><![CDATA[self-organization]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=481</guid>
		<description><![CDATA[I&#8217;ve always been interested in AI, evolution simulations, and other interesting problems. But I will never forget one of my all time favorite classics, John Conway&#8217;s Game of Life..
This simulation implements a few just a few simple rules, yet relatively complex structures emerge.
The rules are:
1. Any live cell with fewer than two live neighbors dies, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always been interested in AI, evolution simulations, and other interesting problems. But I will never forget one of my all time favorite classics, <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank">John Conway&#8217;s Game of Life.</a>.<br />
This simulation implements a few just a few simple rules, yet relatively complex structures emerge.<br />
The rules are:<br />
<b>1.</b> Any live cell with fewer than two live neighbors dies, as if caused by underpopulation.<br />
<b>2.</b> Any live cell with more than three live neighbors dies, as if by overcrowding.<br />
<b>3.</b> Any live cell with two or three live neighbors lives on to the next generation.<br />
<b>4.</b> Any dead cell with exactly three live neighbors becomes a live cell.</p>
<p>Below are some of the patterns that I found and thought were interesting:</p>
<table>
<tr>
<td><a href="http://ken-soft.com/code/c/Life/Life-SimplePatterns.png" target="_blank"><img src="http://ken-soft.com/code/c/Life/Life-SimplePatterns.png" alt="Game of Life Simple Patterns" /></td>
<td><a href="http://ken-soft.com/code/c/Life/Life-ComplexPatterns.png" target="_blank"><img src="http://ken-soft.com/code/c/Life/Life-ComplexPatterns.png" alt="Game of Life Complex Patterns" /></td>
</tr>
</table>
<p>After watching many trails I noticed one thing immediately; The simulation always eventually &#8220;dies down&#8221;, or reaches some equilibrium state and it is usually comprised of a bunch of simple structures. So I decided to add a <b>mutation</b> factor to the simulation such that upon mutation, A living cell dies and a dead cell comes to life. This significantly increased the life of the simulation. In fact with the right mutation rate the simulation will continue endlessly. </p>
<p>In my quick little simulation I also introduced a &#8220;wrap around&#8221; feature so that structures can move infinitely in any direction.</p>
<p>The demo is written in C and uses the <a href="http://www.libsdl.org"  target="_blank">SDL Library</a> for drawing the points and is in 640&#215;480 resolution. The source can be downloaded <a href="http://www.ken-soft.com/code/c/Life/Life.zip">here</a>.<br />
To Compile:<br />
<code>g++ main.cpp -o LIFE -lSDL</code><br />
To Run:<br />
<code>./LIFE</code></p>
<p>Every thing from mutation rate to cell generation at startup is configurable. Read the <b>ReadMe.txt</b> file included to see what&#8217;s configurable.</p>
<p>Screenshots:</p>
<table>
<tr>
<td><a href="http://ken-soft.com/code/c/Life/Life-1.png" target="_blank"><img src="http://ken-soft.com/code/c/Life/Life-1.png" alt="Life Screenshot"  width="175"/></td>
<td><a href="http://ken-soft.com/code/c/Life/Life-2.png" target="_blank"><img src="http://ken-soft.com/code/c/Life/Life-2.png" alt="Life Screenshot"  width="175" /></td>
<td><a href="http://ken-soft.com/code/c/Life/Life-ChangedRules.png" target="_blank"><img src="http://ken-soft.com/code/c/Life/Life-ChangedRules.png" alt="Life Screenshot Changed Rule"  width="175" /></td>
</tr>
</table>
<p>Notice that the 3rd Image is a result of changing rule 4 to &#8221; Any dead cell with <b>two or three</b> live neighbors becomes a live cell.&#8221; (I made this typo when first writing the program and was surprised by the result :)) Try changing the rules and see what results you find.<br />
I hope to release a more complex version in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=481</wfw:commentRss>
		</item>
		<item>
		<title>Neural Network (Back-Error Propagation) C++</title>
		<link>http://ken-soft.com/?p=475</link>
		<comments>http://ken-soft.com/?p=475#comments</comments>
		<pubDate>Sun, 20 Dec 2009 11:42:46 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Artificial Intelligence]]></category>

		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[General Development]]></category>

		<category><![CDATA[Neural Networks]]></category>

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

		<category><![CDATA[Software Development]]></category>

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

		<category><![CDATA[Back-Error Propagation]]></category>

		<category><![CDATA[C++]]></category>

		<category><![CDATA[Neural Network]]></category>

		<category><![CDATA[ニューラルネット]]></category>

		<category><![CDATA[人工知能]]></category>

		<category><![CDATA[誤差逆伝播法]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=475</guid>
		<description><![CDATA[Here is yet another simple Neural Network that implements Back-Error Propagation as a form of Reinforced Learning.
The entire project is written in C++ and requires no special libraries to compile and run.
main.cpp contains code to train both a 2 and 3-input Logical AND gate.
The zipped source code can be downloaded here
A Linux executable is already [...]]]></description>
			<content:encoded><![CDATA[<p>Here is yet another simple Neural Network that implements Back-Error Propagation as a form of Reinforced Learning.<br />
The entire project is written in C++ and requires no special libraries to compile and run.<br />
main.cpp contains code to train both a 2 and 3-input Logical AND gate.<br />
The zipped source code can be downloaded <a href="http://www.ken-soft.com/code/c/nn01/NeuralNetwork.zip">here</a><br />
A Linux executable is already compiled and included in the zip, but feel free to recompile it. A Code::Blocks Project file is also included.</p>
<p><b>To Compile</b><br />
<code>g++ *.cpp -o NeuralNetwork</code><br />
It will output an executable name &#8220;NeuralNetwork&#8221;<br />
<b>To Run</b><br />
open a terminal and type:<br />
<code>./NeuralNetwork</code><br />
<b>Sample Output</b><br />
<code>Neural Network Connections Inited<br />
 Trained in 10000 trails within an error of 1.03127e-05<br />
0 &#038; 0 = 4.63117e-05<br />
0 &#038; 1 = 0.00349833<br />
1 &#038; 0 = 0.00290835<br />
1 &#038; 1 = 0.995469<br />
Train Logical AND 2 Inputs Demo End<br />
Neural Network Connections Inited<br />
Training...<br />
 Trained in 5584 trails within an error of 9.99977e-06<br />
0 &#038; 0 &#038; 0 = 3.62242e-05<br />
0 &#038; 0 &#038; 1 = 0.00194301<br />
0 &#038; 1 &#038; 0 = 0.000102096<br />
0 &#038; 1 &#038; 1 = 0.00344352<br />
1 &#038; 0 &#038; 0 = 0.000142368<br />
1 &#038; 0 &#038; 1 = 0.00333881<br />
1 &#038; 1 &#038; 0 = 0.0035418<br />
1 &#038; 1 &#038; 1 = 0.993633<br />
Logical AND 3 Inputs Demo End<br />
</code></p>
<p><b>Resources:</b><br />
<a href="http://ken-soft.com/?p=70" target="_blank" >About Neural Networks (English)</a><br />
<a href="http://ken-soft.com/?p=65" target="_blank" >About Neural Networks (Japanese/日本語)</a><br />
<a href="http://ken-soft.com/?p=162">Java Implementation of a Neural Network</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=475</wfw:commentRss>
		</item>
		<item>
		<title>Graph 3D (Vector Rotation Source Included) C++</title>
		<link>http://ken-soft.com/?p=458</link>
		<comments>http://ken-soft.com/?p=458#comments</comments>
		<pubDate>Sat, 19 Dec 2009 11:17:06 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[General Development]]></category>

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

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

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[3D]]></category>

		<category><![CDATA[C++]]></category>

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=458</guid>
		<description><![CDATA[This program implements my simple Vector3D.h source to draw simple graphs using SDL. While it&#8217;s not terribly advanced, it should be pretty fun to tinker with. To learn more about 3D rotations including the mathematics and more source (Java) examples, view my previous post &#8211;> 3D Rotation Matrix - Graph3D.
The source code and linux executables [...]]]></description>
			<content:encoded><![CDATA[<p>This program implements my simple Vector3D.h source to draw simple graphs using <a href="http://www.libsdl.org" target="blank">SDL</a>. While it&#8217;s not terribly advanced, it should be pretty fun to tinker with. To learn more about 3D rotations including the mathematics and more source (Java) examples, view my previous post &#8211;> <a href="http://ken-soft.com/?p=147" target="blank">3D Rotation Matrix - Graph3D</a>.<br />
The source code and linux executables can be downloaded <a href="http://ken-soft.com/code/c/vector3D/Vector3D.zip" >here</a>.<br />
If you don&#8217;t want the Graph utility the single Vector3D.h file can be downloaded <a href="http://ken-soft.com/code/c/vector3D/Vector3D.h" >here</a>.</p>
<p>Below is a few of the graphs that I created. All of which can be found in main.cpp (there is a section in the code where you can uncomment the function that you want to graph!)</p>
<table>
<tr>
<td><a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-01.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-01.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-02.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-02.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-03.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-03.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-32.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-32.png" width="140" alt="3D  graph" /></a></td>
</tr>
<tr>
<td><a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-33.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-33.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-07.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-07.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-26.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-26.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-27.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-27.png" width="140" alt="3D  graph" /></a></td>
</tr>
<tr>
<td><a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-12.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-12.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-13.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-13.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-14.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-14.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-28.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-28.png" width="140" alt="3D  graph" /></a></td>
</tr>
<tr>
<td><a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-16.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-16.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-17.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-17.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-19.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-19.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-29.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-29.png" width="140" alt="3D  graph" /></a></td>
</tr>
<tr>
<td><a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-21.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-21.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-22.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-22.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-24.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-24.png" width="140" alt="3D  graph" /></a></td>
<td>
<a href="http://www.ken-soft.com/code/c/vector3D/Vector3D-25.png" target="_blank" ><img src="http://www.ken-soft.com/code/c/vector3D/Vector3D-25.png" width="140" alt="3D  graph" /></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=458</wfw:commentRss>
		</item>
		<item>
		<title>SDL - Simple Space Shooter Game Demo</title>
		<link>http://ken-soft.com/?p=419</link>
		<comments>http://ken-soft.com/?p=419#comments</comments>
		<pubDate>Mon, 21 Sep 2009 03:32:11 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[Game Development]]></category>

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

		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=419</guid>
		<description><![CDATA[






This page contains source code for a simple space shooter game written in C++ using the SDL library. There are no enemies or levels, but only a ship that shoots bullets. This is meant for a beginner who is interested in getting started with SDL for use of making games. (This will be an ongoing [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><a href="http://www.ken-soft.com/code/c/SDL/Game_Demo/gamedemo.png" target="_blank" alt="SDL Space Shooter Game Demo" ><img src="http://www.ken-soft.com/code/c/SDL/Game_Demo/gamedemo.png" width="190" /></a></td>
<td><a href="http://www.ken-soft.com/code/c/SDL/Game_Demo/gamedemo2.png" target="_blank" alt="SDL Space Shooter Game Demo" ><img src="http://www.ken-soft.com/code/c/SDL/Game_Demo/gamedemo2.png" width="190" /></a></td>
<td><a href="http://www.ken-soft.com/code/c/SDL/Game_Demo/gamedemo3.png" target="_blank" alt="SDL Space Shooter Game Demo" ><img src="http://www.ken-soft.com/code/c/SDL/Game_Demo/gamedemo3.png" width="190" /></a></td>
</tr>
</table>
<p>This page contains source code for a simple space shooter game written in C++ using the SDL library. There are no enemies or levels, but only a ship that shoots bullets. This is meant for a beginner who is interested in getting started with SDL for use of making games. (This will be an ongoing tutorial)</p>
<p>All source code can be found in the ZIP file<br />
Version Downloads with project files (All you really need is the source):<br />
<a href="http://ken-soft.com/code/c/SDL/Game_Demo/Game_Demo_3.zip">Version 3: </a>Enemies, Event Queue(timer based), explosions, bullet &#038; enemy collision, some minor code fixes<br />
<a href="http://ken-soft.com/code/c/SDL/Game_Demo/Game_Demo_2.zip">Version 2:</a> Animated sprites, uses custom sprite class<br />
<b>New to SDL? Start with Version 1 below</b><br />
<a href="http://www.ken-soft.com/code/c/SDL/Game_Demo/Game_Demo_windows_devcpp.zip">Version 1: Project file for DevCpp (Windows)</a><br />
<a href="http://www.ken-soft.com/code/c/SDL/Game_Demo/Game_Demo_linux_codeblocks.zip">Version 1: Project file for Code::Blocks (Linux)</a></p>
<p>Also, for a Sprite class with rotations, animations, etc. Check out my ongoing Sprite library, also written in C++ using SDL<br />
<a href="http://ken-soft.com/?p=234">SDL Sprite Library</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=419</wfw:commentRss>
		</item>
		<item>
		<title>3D Cube Engine - Java</title>
		<link>http://ken-soft.com/?p=368</link>
		<comments>http://ken-soft.com/?p=368#comments</comments>
		<pubDate>Sat, 27 Jun 2009 17:35:51 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Game Development]]></category>

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

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

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[3D]]></category>

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

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

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

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

		<category><![CDATA[Rubik's Cube]]></category>

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

		<guid isPermaLink="false">http://ken-soft.com/?p=368</guid>
		<description><![CDATA[



 3&#215;3x3
Y - Increase dimensions. i.e. 4&#215;4x4 -> 5&#215;5x5 (not that if solid mode is true, then it will render slower
Arrows - Translate the cubes across the screen

If you&#8217;re only interested in the Transformation algorithms, check the below link:
Graph4D - demonstrates methods and actual source code for rotating a 4D vector.
Graph3D - demonstrates methods and [...]]]></description>
			<content:encoded><![CDATA[<table >
<tr>
<td><a href="http://www.ken-soft.com/code/java/cube3D/Screenshot-Cubes3D-4.png" target="_blank" alt="3D rotating cube engine java" ><img src="http://www.ken-soft.com/code/java/cube3D/Screenshot-Cubes3D-4.png" width="190" /></a></td>
<td>
<div<a href="http://www.ken-soft.com/code/java/kubix/Screenshot-Kubix-8.png" target="_blank" alt="3D rotating cube engine java" ><img src="http://www.ken-soft.com/code/java/kubix/Screenshot-Kubix-8.png" width="190" /></a></td>
<td><a href="http://www.ken-soft.com/code/java/cube3D/Screenshot-Cubes3D-2.png" target="_blank" alt="3D rotating cube engine java" ><img src="http://www.ken-soft.com/code/java/cube3D/Screenshot-Cubes3D-2.png" width="190" /></a></td>
</tr>
</table>
<p>This is a recent project of mine for building 3D puzzle games, (like Rubik&#8217;s Cubes). </p>
<p>While the code could be optimized quite a bit, this is mainly for those who wish to better understand concepts of 3D programming. For example, one way to create, store, and manipulate a 3D polygon, whether it be a Cube, or an ellipsoid. This project contains code and algorithm&#8217;s to rotate 3D polygons, around the origin, and themselves. Ability to draw 3D objects in order of increasing Z-values. Draw wireframe or solid color polygons. Keyboard and Mouse controls to move and alter the Polygons. It is a work in progress and not intended for use in graphic intensive games.</p>
<p>Note: later I will add rotateAroundVector() for more general rotation<br />
Note: Ellipse3D is still very primitive but demonstrates one method creating an ellipsoid<br />
Note: Not all Jar files contain the same versions of code. Each Jar file contains code specific to what it is supposed to do.</p>
<p>All source code can be found in the JAR files<br />
Downloadable Jars (simple to complex):<br />
1. <a href="http://www.ken-soft.com/code/java/cube3D/RenderWiredCubes3D-demo.jar">RenderWiredCubes3D-demo.jar</a>: this code rotates 4 rotating cubes about the origin.<br />
2.  <a href="http://www.ken-soft.com/code/java/cube3D/RenderPolygons3D-demo.jar">RenderPolygons3D-demo.jar</a>: this code demonstrates various ellipsoids and cubes rotating around unique axises.<br />
3. <a href="http://www.ken-soft.com/code/java/cube3D/Cubes3D-demo.jar">Cubes3D-demo.jar</a>: this code demonstrates more of the functionality of the 3D Cube engine by creating a Rubik&#8217;s cube like look and feel.<br />
<b>Controls</b></p>
<ul>
<li>Mouse: click and drag the cube</li>
<li>A - reset</li>
<li>S - toggle between solid and non-solid mode. (i.e. the inside is filled with cubes or not)</li>
<li>D - randomly select an internally defined color scheme</li>
<li>F - toggle between random rotate mode. Just try it <img src='http://ken-soft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>Q - Decrease space between pieces</li>
<li>W - Increase space between pieces</li>
<li>E - Decrease size of cubes</li>
<li>R - Increase size of cubes</li>
<li>T - Decrease dimensions. i.e. 4&#215;4x4 -> 3&#215;3x3</li>
<li>Y - Increase dimensions. i.e. 4&#215;4x4 -> 5&#215;5x5 (not that if solid mode is true, then it will render slower</li>
<li>Arrows - Translate the cubes across the screen</li>
</ul>
<p>If you&#8217;re only interested in the Transformation algorithms, check the below link:<br />
<a href="http://ken-soft.com/?p=297" >Graph4D</a> - demonstrates methods and actual source code for rotating a 4D vector.<br />
<a href="http://ken-soft.com/?p=147" >Graph3D</a> - demonstrates methods and actual source code for rotating a 3D vector.</p>
<table >
<tr>
<td><a href="http://www.ken-soft.com/code/java/kubix/Kubix-RandomCubes.png" target="_blank" alt="3D rotating cube engine java" ><img src="http://www.ken-soft.com/code/java/kubix/Kubix-RandomCubes.png" width="190" /></a></td>
<td><a href="http://www.ken-soft.com/images/cube3D/Screenshot-Cubes3D.png" target="_blank" alt="3D rotating cube engine java" ><img src="http://www.ken-soft.com/code/java/cube3D/Screenshot-Cubes3D.png" width="190" /></a></td>
<td><a href="http://www.ken-soft.com/code/java/kubix/Screenshot-Kubix-1.png" target="_blank" alt="3D rotating cube engine java" ><img src="http://www.ken-soft.com/code/java/kubix/Screenshot-Kubix-1.png" width="190" /></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=368</wfw:commentRss>
		</item>
		<item>
		<title>太陽系</title>
		<link>http://ken-soft.com/?p=334</link>
		<comments>http://ken-soft.com/?p=334#comments</comments>
		<pubDate>Tue, 03 Mar 2009 02:31:21 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Learning]]></category>

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

		<category><![CDATA[Solar System]]></category>

		<category><![CDATA[太陽系]]></category>

		<category><![CDATA[宇宙]]></category>

		<category><![CDATA[惑星]]></category>

		<category><![CDATA[理系]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=334</guid>
		<description><![CDATA[これは僕が関西外国語大学にいる時、書いた論文で、内容はそんなに難しくなく、日本語を勉強している人にとって役に立つかもしれません。
  
]]></description>
			<content:encoded><![CDATA[<p>これは僕が関西外国語大学にいる時、書いた論文で、内容はそんなに難しくなく、日本語を勉強している人にとって役に立つかもしれません。<br />
<embed wmode="transparent" src="http://www.ken-soft.com/doc/Solar_System-jp.pdf" width="100%" height="600">  </p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=334</wfw:commentRss>
		</item>
		<item>
		<title>4D Maze - (Java)</title>
		<link>http://ken-soft.com/?p=315</link>
		<comments>http://ken-soft.com/?p=315#comments</comments>
		<pubDate>Wed, 14 Jan 2009 07:23:55 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[General Development]]></category>

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

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

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[4D]]></category>

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=315</guid>
		<description><![CDATA[This is a simple implementation of a 4D maze written in Java. As of now it is entirely text based however, a simple GUI is currently under development. Either way, this simple implementation should be useful to modify and/or build off of.
The algorithm used to generate the map is quite simple and always generates a [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple implementation of a 4D maze written in Java. As of now it is entirely text based however, a simple GUI is currently under development. Either way, this simple implementation should be useful to modify and/or build off of.<br />
The algorithm used to generate the map is quite simple and always generates a perfect maze.</p>
<blockquote><p>
<b>1.</b> Randomly choose a starting room<br />
<b>2.</b> Add all surrounding rooms that have not been visited, or  to a list<br />
<b>3.</b> While their are rooms in the list randomly select one<br />
<b>4.</b> Set the room to visited, and start again from step 2 using the current room
</p></blockquote>
<p>Note: the Java version used in this implementation uses recursion to do this.<br />
This code has not been thoroughly checked for possible bugs, and I am sure there is a more efficient method to write a 4D maze. But, at the very least, it is flexible and each room of the maze is of class type Room4D and should be easy to modify.<br />
The Jar file can be downloaded here: <a href="http://www.ken-soft.com/code/java/maze4D/Maze4D.jar">Maze4D.jar</a><br />
To run from the command line:</p>
<blockquote><p>java -jar Maze4D.java dimXYZU</p></blockquote>
<p>Ex:</p>
<blockquote><p>java -jar Maze4D.java 5</p></blockquote>
<p>This initializes a 5&#215;5x5&#215;5 maze. Start = (0,0,0,0), Finish = (5,5,5,5)<br />
that&#8217;s 5^4 rooms, 625 rooms, that&#8217;s a lot of rooms to navigate in 4D. <img src='http://ken-soft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<blockquote><p>java -jar Maze4D.java dimX dimY dimZ dimU</p></blockquote>
<p>Ex:</p>
<blockquote><p>java -jar Maze4D.java 5 5 3 2</p></blockquote>
<p>This initializes a 5&#215;5x3&#215;2 maze. Start = (0,0,0,0), Finish = (5,5,3,2)<br />
5&#215;5x3&#215;2 = 150 rooms.</p>
<blockquote><p>java -jar Maze4D.java</p></blockquote>
<p>creates a default maze of dimensions 4&#215;4x4&#215;4</p>
<p>Note: be careful not to load a 4D maze that&#8217;s too big or Java will run out of memory, depending on your Java settings. For example creating a room that is 10&#215;10x10&#215;10, 10000 rooms, will likely cause an error caused by using too much memory. besides, a 10000 room is very, very complicated, especially in 4D.<br />
<a href="http://www.ken-soft.com/code/java/maze4D/maze4D.png" target="_blank" ><img src="http://www.ken-soft.com/code/java/maze4D/maze4D.png" width="230" alt="4D maze java"/></a></p>
<p><a href="http://www.ken-soft.com/code/java/maze4D/Rect4D.java">Rect4D.java</a></p>
<p><a href="http://www.ken-soft.com/code/java/maze4D/Point4D.java" >Point4D.java</a></p>
<p><a href="http://www.ken-soft.com/code/java/maze4D/Room4D.java" >Room4D.java</a></p>
<p><a href="http://www.ken-soft.com/code/java/maze4D/Maze4D.java" >Maze4D.java</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=315</wfw:commentRss>
		</item>
		<item>
		<title>4D Rotation Matrix - Graph 4D</title>
		<link>http://ken-soft.com/?p=296</link>
		<comments>http://ken-soft.com/?p=296#comments</comments>
		<pubDate>Thu, 08 Jan 2009 22:52:36 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[General Development]]></category>

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

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

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

		<category><![CDATA[3D]]></category>

		<category><![CDATA[4D]]></category>

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

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

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

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=296</guid>
		<description><![CDATA[This program rotates points about the XY, YZ, XZ, XU, YU, and ZU axises. I then projects each 4D vector to the 2D canvas.
The Jar file can be downloaded here: Graph4D.jar








Before looking at the source, let&#8217;s take a look at some of the fundamental mathematics behind the software.
If you are uncomfortable with the thought of [...]]]></description>
			<content:encoded><![CDATA[<p>This program rotates points about the XY, YZ, XZ, XU, YU, and ZU axises. I then projects each 4D vector to the 2D canvas.<br />
The Jar file can be downloaded here: <a href="http://www.ken-soft.com/code/java/graph4D/Graph4D.jar">Graph4D.jar</a></p>
<table>
<tr>
<td>
<a href="http://www.ken-soft.com/code/java/graph4D/graph4D.png" target="_blank" ><img src="http://www.ken-soft.com/code/java/graph4D/graph4D.png" width="150" alt="4D rotation matrix java"/></a></td>
<td>
<a href="http://www.ken-soft.com/code/java/graph4D/graph4D2.png" target="_blank" ><img src="http://www.ken-soft.com/code/java/graph4D/graph4D2.png" width="150" alt="4D rotation matrix java"/></a></td>
</tr>
</table>
<p>Before looking at the source, let&#8217;s take a look at some of the fundamental mathematics behind the software.<br />
If you are uncomfortable with the thought of 4D matrix rotations, then I recommend reading Wikipedia, or checking out my article about 3D graphing, which can be found <a href="http://ken-soft.com/?p=147">here</a>. In this example, I will only show the 4D rotation matrices. Note that for each rotation matrix, 2 axises are held still while the vector is rotated around the other two axises. This may be hard to visualize at first, but It will become clear after a while.<br />
<img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_386f86decb4f40b917dfd6db830318eb.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotXY = delim{[}{matrix{4}{4}{{cos(theta)} {sin(theta)} 0 0 {-sin(theta)} {cos(theta)} 0 0 0 0 1 0 0 0 0 1}}{]}" title="rotXY = delim{[}{matrix{4}{4}{{cos(theta)} {sin(theta)} 0 0 {-sin(theta)} {cos(theta)} 0 0 0 0 1 0 0 0 0 1}}{]}"/><img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_d339828f569aa5fef53964595e60e7dc.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotYZ = delim{[}{matrix{4}{4}{1 0 0 0 0 {cos(theta)} {sin(theta)} 0 0 {-sin(theta)} {cos(theta)} 0 0 0 0 1}}{]}" title="rotYZ = delim{[}{matrix{4}{4}{1 0 0 0 0 {cos(theta)} {sin(theta)} 0 0 {-sin(theta)} {cos(theta)} 0 0 0 0 1}}{]}"/><img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_68fa0611192405b45f28bdf0af541d03.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotXZ = delim{[}{matrix{4}{4}{{cos(theta)} 0 {-sin(theta)} 0 0 1 0 0 {sin(theta)} 0 {cos(theta)} 0 0 0 0 1}}{]}" title="rotXZ = delim{[}{matrix{4}{4}{{cos(theta)} 0 {-sin(theta)} 0 0 1 0 0 {sin(theta)} 0 {cos(theta)} 0 0 0 0 1}}{]}"/><img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_bae5dc667d825cb897c4d017c7a422d3.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotXU = delim{[}{matrix{4}{4}{{cos(theta)} 0 0 {sin(theta)} 0 1 0 0 0 0 1 0 {-sin(theta)} 0 0 {cos(theta)}}}{]}" title="rotXU = delim{[}{matrix{4}{4}{{cos(theta)} 0 0 {sin(theta)} 0 1 0 0 0 0 1 0 {-sin(theta)} 0 0 {cos(theta)}}}{]}"/><img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_ab7a54a79ef160a0aa918151d9d55ce9.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotYU = delim{[}{matrix{4}{4}{1 0 0 0 0 {cos(theta)} 0 {-sin(theta)} 0 0 1 0  0 {sin(theta)} 0 {cos(theta)}}}{]}" title="rotYU = delim{[}{matrix{4}{4}{1 0 0 0 0 {cos(theta)} 0 {-sin(theta)} 0 0 1 0  0 {sin(theta)} 0 {cos(theta)}}}{]}"/><img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_75c90de6d3b518ddba1001f07fa85adf.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotZU = delim{[}{matrix{4}{4}{1 0 0 0 0 1 0 0 0 0 {cos(theta)} {-sin(theta)} 0 0 {sin(theta)} {cos(theta)}}}{]}" title="rotZU = delim{[}{matrix{4}{4}{1 0 0 0 0 1 0 0 0 0 {cos(theta)} {-sin(theta)} 0 0 {sin(theta)} {cos(theta)}}}{]}"/></p>
<p>The source code can be found below as well as being bundled into the Jar file.</p>
<p>Transform4D.java - contains method for rotating a 4D vector</p>
<p><a href="http://ken-soft.com/code/java/graph4D/Transform4D.java" class="code">Transform4D.java</a></p>
<p><a href="http://ken-soft.com/code/java/graph4D/Point4D.java">Point4D.java</a></p>
<p><a href="http://ken-soft.com/code/java/graph4D/Graph4D.java">Graph4D.java</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=296</wfw:commentRss>
		</item>
		<item>
		<title>Thog Problem</title>
		<link>http://ken-soft.com/?p=269</link>
		<comments>http://ken-soft.com/?p=269#comments</comments>
		<pubDate>Thu, 08 Jan 2009 12:04:30 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Learning]]></category>

		<category><![CDATA[Logic Problems]]></category>

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

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=269</guid>
		<description><![CDATA[Given the following combinations of shapes and colors:
]]></description>
			<content:encoded><![CDATA[<p>Given the following combinations of shapes and colors:</p>
<table width=100% align=center">
<td><a href="#" onClick="alert1()"><img class="center"　width="100" src="http://ken-soft.com/images/thog/black_sqr.jpg" border=0></a></td>
<td><a href="#" onClick="alert2()"><img class="center"　width="100" src="http://ken-soft.com/images/thog/black_crc.jpg" border=0></a></td>
<td><a href="#" onClick="alert3()"><img class="center"　width="100" src="http://ken-soft.com/images/thog/white_sqr.jpg" border=0></a></td>
<td><a href="#" onClick="alert4()"><img class="center"  width="100" src="http://ken-soft.com/images/thog/white_crc.jpg" border=0></a></td>
</table>
<p> The experimenter makes the following statement:</p>
<blockquote><p>&#8220;I am thinking of one color (black or white) and one shape (square or circle). Any figure that has either the color I am thinking of, or the shape I am thinking of, but not both, is a THOG. Given that the black square is a THOG what, if anything, can you say about whether the other figures are THOGS?&#8221;</p>
</blockquote>
<p>Select the THOG by clicking on one of the shapes above</p>
<p><script langauage="JavaScript">
function alert1() {
    alert("No, the Black Square is the original THOG");
}
function alert2() {
    alert("No, the experimenter could be thinking of either (Black and Circle) or (White and Square). " +
	"If the experimenter is thinking of (Black and Circle) " +
	"the Black Circle has BOTH properties. If the experimenter is "+
	"thinking of (White and Square) the Black Circle has NEITHER property.");
}
function alert3() {
    alert("No, the experimenter could be thinking of either (Black and Circle) or (White and Square). " +
	"If the experimenter is thinking of (Black and Circle) " +
	"the white square has NEITHER property; if the experimenter is "+
	"thinking of (White and Square) the White Square has BOTH properties.");
}
function alert4() {
    alert("Yes, the experimenter could be thinking of either (Black and Circle) or (White and Square). " +
	"If the experimenter is thinking of (Black and Circle)" +
	"the White Circle has one property: Circle; if the experimenter is" +
	"thinking of (White and Square) the White Circle has one property: White.");
}
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=269</wfw:commentRss>
		</item>
		<item>
		<title>C++ Dynamic Memory Allocation (2D and 3D)</title>
		<link>http://ken-soft.com/?p=246</link>
		<comments>http://ken-soft.com/?p=246#comments</comments>
		<pubDate>Thu, 08 Jan 2009 11:04:20 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

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

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

		<category><![CDATA[C++]]></category>

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=246</guid>
		<description><![CDATA[This snipped of code is for allocating memory when using a multidimensional array. The following examples are for 2D ([][]) and 3D ([][][]) structures.
First:
to allocate memory for a two dimensional structure: (i.e. int[][] array)

1
2
3
4
5
6
7
8
9
int** array;    // 2D array definition;
// begin memory allocation
array = new int*&#91;dimX&#93;;
for&#40;int x = 0; x &#60; dimX; ++x&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>This snipped of code is for allocating memory when using a multidimensional array. The following examples are for 2D ([][]) and 3D ([][][]) structures.</p>
<p>First:<br />
to allocate memory for a two dimensional structure: (i.e. int[][] array)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span><span style="color: #339933;">**</span> array<span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// 2D array definition;</span>
<span style="color: #666666; font-style: italic;">// begin memory allocation</span>
array <span style="color: #339933;">=</span> new <span style="color: #993333;">int</span><span style="color: #339933;">*</span><span style="color: #009900;">&#91;</span>dimX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> dimX<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     array<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> new <span style="color: #993333;">int</span><span style="color: #009900;">&#91;</span>dimY<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> dimY<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// initialize the values, this is optional, but recommended</span>
          array<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Next, to allocate memory for a three dimensional structure: (i.e. int[][][] array)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span><span style="color: #339933;">***</span> array<span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// 3D array definition;</span>
<span style="color: #666666; font-style: italic;">// begin memory allocation</span>
array <span style="color: #339933;">=</span> new <span style="color: #993333;">int</span><span style="color: #339933;">**</span><span style="color: #009900;">&#91;</span>dimX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> dimX<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    array<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> new <span style="color: #993333;">int</span><span style="color: #339933;">*</span><span style="color: #009900;">&#91;</span>dimY<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> dimY<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        array<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> new <span style="color: #993333;">int</span><span style="color: #009900;">&#91;</span>dimZ<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> z <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> z <span style="color: #339933;">&lt;</span> dimZ<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>z<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// initialize the values, again, not necessary, but recommended</span>
            array<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>z<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=246</wfw:commentRss>
		</item>
		<item>
		<title>SDL Sprite Class in C++</title>
		<link>http://ken-soft.com/?p=234</link>
		<comments>http://ken-soft.com/?p=234#comments</comments>
		<pubDate>Sat, 03 Jan 2009 04:58:43 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[Game Development]]></category>

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

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[2D]]></category>

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

		<category><![CDATA[C++]]></category>

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

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

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

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=234</guid>
		<description><![CDATA[This is a simple Sprite class that I use for game development in C++ using SDL (www.libsdl.org).
Features include sprite animation, rotation, stretching, transparencies, and other commonly used sprite functions.
I hope this is somewhat useful. The source is available and should be fairly simple to work with.
Feel free to modify it however you want. please comment [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple Sprite class that I use for game development in C++ using SDL (<a href="http://www.libsdl.org/" target="_blank">www.libsdl.org</a>).<br />
Features include sprite animation, rotation, stretching, transparencies, and other commonly used sprite functions.</p>
<p>I hope this is somewhat useful. The source is available and should be fairly simple to work with.<br />
Feel free to modify it however you want. please comment about any bugs are suggestions that you have. Thanks.</p>
<p><b>Last Updated</b><br />
2010 July 18 - implemented a builder design to all setter/modifying operations that return void. They now return the object it&#8217;s self, (*this). This results in being able to set up a Sprite with less code. i.e.<br />
<code>sprite->setTransparency(0xFF, 0, 0xFF)->flipHorizontal()->reverseAnimation()->zoom(50);</code><br />
<code>sprite->animate()->draw(screen, 100, 100);</code><br />
2010 June 1 - fixed some minor bugs</p>
<p><a href="http://www.ken-soft.com/code/c/SDL/Sprite/sshot.PNG" target="_blank" ><img src="http://www.ken-soft.com/code/c/SDL/Sprite/sshot.PNG" width="250" alt="SDL Sprite C++"/></a><br />
<strong>Version 1d (With demo &#038; source)</strong>  <a href="http://www.ken-soft.com/code/c/SDL/Sprite/SDL_Sprite_1d.zip">SDL_Sprite_1d.zip</a><br/><br />
<strong>Individual source files</strong></p>
<p><a href="http://ken-soft.com/code/c/SDL/Sprite/Sprite.h"  target="_blank" >Sprite.h</a></p>
<p><a href="http://ken-soft.com/code/c/SDL/Sprite/Sprite.cpp"  target="_blank" >Sprite.cpp</a></p>
<p><a href="http://ken-soft.com/code/c/SDL/Sprite/Main.h"  target="_blank" >Main.h</a></p>
<p><a href="http://ken-soft.com/code/c/SDL/Sprite/main.cpp"  target="_blank" >main.cpp</a></p>
<p>To view a demo of some of the Sprites classes features, and have access to some sample Bitmap images used with the Sprite library,  download the following zip file. It also contains the project settings that I used in Dev C++ and SDL 1.2.12 to compile.</p>
<p>All examples use these sprites</p>
<table>
<tr>
<td><a href="http://www.ken-soft.com/code/c/SDL/Sprite/samus_normal_run.bmp" target="_blank" ><img width="90%" src="http://www.ken-soft.com/code/c/SDL/Sprite/samus_normal_run.bmp"  alt="SDL Sprite C++"/></a></td>
<td><a href="http://ken-soft.com/code/c/SDL/Sprite/character.bmp" target="_blank" ><img width="90%" src="http://ken-soft.com/code/c/SDL/Sprite/character.bmp"  alt="SDL Sprite C++"/></a></td>
</tr>
</table>
<p><b>Demo using special effects </b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">    <span style="color: #666666;">// Initialize SDL, etc</span>
   ...
   ...
   <span style="color: #007788;">Sprite</span><span style="color: #000040;">*</span> s1 <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> Sprite<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;sprites/samus_normal_run.bmp&quot;</span>,<span style="color: #0000dd;">10</span>,<span style="color: #0000dd;">60</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// load a BMP that contains 10 frames</span>
                                                <span style="color: #666666;">// set the animation speed to 60 milliseconds</span>
      <span style="color: #666666;">// set RGB(255,0,255) as transparent, rotate 180 degrees, flip horizontal and reverse animation</span>
  s1<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setTransparency<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">255</span>,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">255</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>rotate180<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>flipHorizontal<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>reverseAnimation<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   <span style="color: #666666;">// etc</span>
    ...
    ...
&nbsp;
    <span style="color: #666666;">// Main loop</span>
    <span style="color: #666666;">// clear background to black, RGB(0,0,0)</span>
    SDL_FillRect<span style="color: #008000;">&#40;</span>screen, <span style="color: #0000dd;">0</span>, SDL_MapRGB<span style="color: #008000;">&#40;</span>screen<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>format, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">// animate and draw the sprite</span>
    s1<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>animate<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>draw<span style="color: #008000;">&#40;</span>screen,<span style="color: #0000dd;">0</span>,<span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    SDL_Flip<span style="color: #008000;">&#40;</span>screen<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=234</wfw:commentRss>
		</item>
		<item>
		<title>Rubik&#8217;s Cube - 2D Implementation - Java</title>
		<link>http://ken-soft.com/?p=179</link>
		<comments>http://ken-soft.com/?p=179#comments</comments>
		<pubDate>Fri, 26 Dec 2008 06:43:44 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Game Development]]></category>

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

		<category><![CDATA[Logic Problems]]></category>

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

		<category><![CDATA[Rubik's Cube]]></category>

		<category><![CDATA[Software Development]]></category>

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

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

		<category><![CDATA[ルービックキューブ]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=179</guid>
		<description><![CDATA[This is a simple 2D representation of a Rubik&#8217;s Cube written in Java. Its main purpose to be easily integrated with other software. I.e. A Rubik&#8217;s Cube solving Neural Network. Therefore, the UI is not extremely eye catching. But it serves a good test to demonstrate that the software is working. Later implementations will better [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple 2D representation of a Rubik&#8217;s Cube written in Java. Its main purpose to be easily integrated with other software. I.e. A Rubik&#8217;s Cube solving Neural Network. Therefore, the UI is not extremely eye catching. But it serves a good test to demonstrate that the software is working. Later implementations will better support NxNxN cubes.</p>
<p>The Jar file can be downloaded here: <a href="http://www.ken-soft.com/code/java/rc/RC.jar">Rubik&#8217;s Cube.jar</a> Just click it to run it. If you have any problems running it, check to ensure that Java is correctly installed on your machine.</p>
<table width=100%>
<tr>
<td>
<a href="http://www.ken-soft.com/code/java/rc/rcjava/RC01.png" target="_blank" ><img src="http://www.ken-soft.com/code/java/rc/RC01.png" width="295" alt="Rubik's Cube 2D java"/></a></td>
<td>
<a href="http://www.ken-soft.com/code/java/rc/RC02.png" target="_blank" ><img src="http://www.ken-soft.com/code/java/rc/RC02.png" width="295"  alt="Rubik's Cube 2D java"/></a></td>
</tr>
</table>
<p><a href="http://ken-soft.com/code/java/rc/RubiksCubeGUI.java">RubiksCubeGUI.java</a></p>
<p>RubiksCube.java is the main wrapper class to Cube3D</p>
<p><a href="http://ken-soft.com/code/java/rc/RubiksCube.java">RubiksCube.java</a></p>
<p><a href="http://ken-soft.com/code/java/rc/Cube3D.java">Cube3D.java</a></p>
<p>Each of the 27 cubes that make up a standard 3&#215;3 Rubik&#8217;s Cube, I call a Cubit.</p>
<p><a href="code/java/rc/Cubit.java">Cubit.java</a></p>
<p><a href="code/java/rc/Cube3DTest.java">Cube3DTest.java</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=179</wfw:commentRss>
		</item>
		<item>
		<title>Load Neural Network Training data from XML (PDF)</title>
		<link>http://ken-soft.com/?p=174</link>
		<comments>http://ken-soft.com/?p=174#comments</comments>
		<pubDate>Fri, 26 Dec 2008 05:05:19 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Artificial Intelligence]]></category>

		<category><![CDATA[General Development]]></category>

		<category><![CDATA[Neural Networks]]></category>

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

		<category><![CDATA[Software Development]]></category>

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

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

		<category><![CDATA[Neural Network]]></category>

		<category><![CDATA[Train Data]]></category>

		<category><![CDATA[ニューラルネット]]></category>

		<category><![CDATA[人工知能]]></category>

		<category><![CDATA[神経回路]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=174</guid>
		<description><![CDATA[



]]></description>
			<content:encoded><![CDATA[<p><object><br />
<PARAM NAME="wmode" value="transparent"><br />
<embed wmode="transparent" src="http://www.ken-soft.com/doc/NNTraindataXML.pdf" width="100%" height="600"><br />
</object></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=174</wfw:commentRss>
		</item>
		<item>
		<title>Neural Network - Load Train Data from XML - Java</title>
		<link>http://ken-soft.com/?p=168</link>
		<comments>http://ken-soft.com/?p=168#comments</comments>
		<pubDate>Fri, 26 Dec 2008 04:52:59 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Artificial Intelligence]]></category>

		<category><![CDATA[General Development]]></category>

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

		<category><![CDATA[Neural Networks]]></category>

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

		<category><![CDATA[Software Development]]></category>

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

		<category><![CDATA[Back-Error Propagation]]></category>

		<category><![CDATA[Neural Network]]></category>

		<category><![CDATA[ニューラルネット]]></category>

		<category><![CDATA[神経回路]]></category>

		<category><![CDATA[誤差逆伝播法]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=168</guid>
		<description><![CDATA[This Neural Network is a command line implementation that uses the Back-Error Propagation learning algorithm. The main difference with this model is that all train data is loaded from an external XML file.
The Train data specification can be found Here.
The Zip file containing the Jar file and traindata directory can be downloaded here: NN.jar
Below is [...]]]></description>
			<content:encoded><![CDATA[<p>This Neural Network is a command line implementation that uses the Back-Error Propagation learning algorithm. The main difference with this model is that all train data is loaded from an external XML file.<br />
The Train data specification can be found <a href="http://ken-soft.com/?p=174" target="_blank">Here</a>.</p>
<p>The Zip file containing the Jar file and traindata directory can be downloaded here: <a href="http://www.ken-soft.com/code/java/nn01/NN02.zip">NN.jar</a><br />
Below is the Syntax for running NN02.jar in a command line:<br />
<code>java -jar NN02.jar [num center layers] [num center layer neurons] [learning rate]</code><br />
An example includes:<br />
<code>java -jar NN02.jar 1 50 1.5</code><br />
Which specifies a neural network with 1 center layers, 50 neurons per center layer, and a learning rate of 1.5. If now parameters are supplied it runs with default parameters.<br />
Once executed, it should give a display similar to the image below.<br />
<a href="http://www.ken-soft.com/code/java/nn01/NN02.png" target="_blank" ><img src="http://www.ken-soft.com/code/java/nn01/NN02.png" width="250" /></a></p>
<p>The neural network Source is almost unchanged from a previous example found <a href="http://ken-soft.com/?p=162" target="_blank" >Here</a><br />
Included in the zip file is my custom, and very very messy, XML Parser. If you plan on using any of this code for any real development, I recommend using a standard XML Parser.  <img src='http://ken-soft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=168</wfw:commentRss>
		</item>
		<item>
		<title>Neural Network - Back-Error Propagation - Java</title>
		<link>http://ken-soft.com/?p=162</link>
		<comments>http://ken-soft.com/?p=162#comments</comments>
		<pubDate>Fri, 26 Dec 2008 04:33:40 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Artificial Intelligence]]></category>

		<category><![CDATA[General Development]]></category>

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

		<category><![CDATA[Neural Networks]]></category>

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

		<category><![CDATA[Software Development]]></category>

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

		<category><![CDATA[Back-Error Propagation]]></category>

		<category><![CDATA[Neural Network]]></category>

		<category><![CDATA[ニューラルネット]]></category>

		<category><![CDATA[人工知能]]></category>

		<category><![CDATA[誤差逆伝播法]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=162</guid>
		<description><![CDATA[This Neural Network is a command line implementation that uses the Back-Error Propagation learning algorithm. As well, The number of center layers, neurons per center layer, and learning rate are all changeable. The provided Test file teach Logial AND, however other test files can easily be created.
The Jar file can be downloaded here: NN.jar
Below is [...]]]></description>
			<content:encoded><![CDATA[<p>This Neural Network is a command line implementation that uses the Back-Error Propagation learning algorithm. As well, The number of center layers, neurons per center layer, and learning rate are all changeable. The provided Test file teach Logial AND, however other test files can easily be created.</p>
<p>The Jar file can be downloaded here: <a href="http://www.ken-soft.com/code/java/nn01/NN.jar">NN.jar</a><br />
Below is the Syntax for running NN.jar in a command line:<br />
<code>java -jar NN.jar [num center layers] [num center layer neurons] [learning rate]</code><br />
An example includes:<br />
<code>java -jar NN.jar 2 10 1.5</code><br />
Which specifies a neural network with 2 center layers, 10 neurons per center layer, and a learning rate of 1.5. If now parameters are supplied it runs with default parameter; which are 1 center layers, 1 neurons per center layer, and a learning rate of 0.5.<br />
That should give a display similar to the image below.<br />
<a href="http://www.ken-soft.com/code/java/nn01/NN01.png" target="_blank" ><img src="http://www.ken-soft.com/code/java/nn01/NN01.png" width="250" alt="neural network back error propagation java"/></a></p>
<p>Below are some links to A couple articles that give a good brief overview about neural networks, including some concepts about developing learning algorithms. Hope they are useful.<br />
<a href="http://ken-soft.com/?p=70" target="_blank" >About Neural Networks (English)</a><br />
<a href="http://ken-soft.com/?p=65" target="_blank" >About Neural Networks (Japanese/日本語)</a></p>
<p><a href="http://ken-soft.com/code/java/nn01/NeuralNetwork.java" class="code">NeuralNetwork.java</a></p>
<p><a href="http://ken-soft.com/code/java/nn01/Layer.java" class="code">Layer.java</a></p>
<p>There are two test file for you to try out.</p>
<p><a href="http://ken-soft.com/code/java/nn01/NeuralNetworkTest.java" class="code">NeuralNetworkTest.java</a></p>
<p><a href="http://ken-soft.com/code/java/nn01/NeuralNetworkTest2.java" class="code">NeuralNetworkTest2.java</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=162</wfw:commentRss>
		</item>
		<item>
		<title>Multi-linked List - Java</title>
		<link>http://ken-soft.com/?p=159</link>
		<comments>http://ken-soft.com/?p=159#comments</comments>
		<pubDate>Fri, 26 Dec 2008 03:57:40 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[General Development]]></category>

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

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

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[double-linked]]></category>

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

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

		<category><![CDATA[Mult-Linked List]]></category>

		<category><![CDATA[Multi-linked]]></category>

		<category><![CDATA[multiply-linked list]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=159</guid>
		<description><![CDATA[This program is a multi-linked list where each node is also doubly connected (so that you can backtrack a followed path). Note, this is not a simple doubly linked list. each node of this list can connect to any number of other nodes in the list, including itself. This should be very interesting to build [...]]]></description>
			<content:encoded><![CDATA[<p>This program is a multi-linked list where each node is also doubly connected (so that you can backtrack a followed path). <b>Note</b>, this is not a simple doubly linked list. each node of this list can connect to any number of other nodes in the list, including itself. This should be very interesting to build off of and tinker with.</p>
<p>The Jar file can be downloaded here: <a href="http://www.ken-soft.com/code/java/mll/MLLDoubleLinked.jar">MLLDoubleLinked.jar</a><br />
To run the Jar file open the command prompt, cd into the directory, then type:<br />
<code>java -jar MLLDoubleLinked.jar</code><br />
That should give a display similar to the image below. The out shows a series of tests being ran as well as a final output of the MLL.<br />
<a href="http://www.ken-soft.com/code/java/mll/MLL01.png" target="_blank" ><img src="http://www.ken-soft.com/code/java/mll/MLL01.png" width="250" alt="Multilinked list"/></a></p>
<p>The source is also bundled into the Jar file.</p>
<p>MLL.java - contains many of the main functions necessary in a multilinked list.</p>
<p><a href="http://ken-soft.com/code/java/mll/MLL.java" class="code">MLL.java</a></p>
<p><a href="http://ken-soft.com/code/java/mll/MLLNode.java" class="code">MLLNode.java</a></p>
<p><a href="http://ken-soft.com/code/java/mll/MLLTest.java" class="code">MLLTest.java</a></p>
<p>The Unit Test class is not executed in the Jar file. But it&#8217;s source is included.</p>
<p><a href="http://ken-soft.com/code/java/mll/MLLUnitTest.java" class="code">MLLUnitTest.java</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=159</wfw:commentRss>
		</item>
		<item>
		<title>3D Rotation Matrix - Graph 3D</title>
		<link>http://ken-soft.com/?p=147</link>
		<comments>http://ken-soft.com/?p=147#comments</comments>
		<pubDate>Fri, 26 Dec 2008 02:31:48 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[General Development]]></category>

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

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

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

		<category><![CDATA[2D]]></category>

		<category><![CDATA[3D]]></category>

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

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

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

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

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

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=147</guid>
		<description><![CDATA[This was a simple program I wrote that Displays 3D points. It does so by simply projecting a 3D (vector) into 2D.
The Jar file can be downloaded here: Graph3D.jar
The C/C++ version can be found here

Before looking at the source, let&#8217;s take a look at some of the fundamental mathematics behind the software.
rotations - Rotations in [...]]]></description>
			<content:encoded><![CDATA[<p>This was a simple program I wrote that Displays 3D points. It does so by simply projecting a 3D (vector) into 2D.<br />
The Jar file can be downloaded here: <a href="http://www.ken-soft.com/code/java/graph3D/Graph3D.jar">Graph3D.jar</a><br />
The C/C++ version can be found <a href="http://ken-soft.com/?p=458" target="_blank">here</a></p>
<p><a href="http://www.ken-soft.com/code/java/graph3D/graph3D.png" target="_blank" ><img src="http://www.ken-soft.com/code/java/graph3D/graph3D.png" width="150" alt="3D rotation matrix" /></a><br />
Before looking at the source, let&#8217;s take a look at some of the fundamental mathematics behind the software.<br />
<b>rotations</b> - Rotations in this software simple geometric transformations based around an unmoving center axis. Below are the three rotation matrices for each axis, X, Y, and Z, respectively. Every operation can be found in Transform.java below.</p>
<p><br/><b>Rotate Around X,Y, or Z Axis</b></p>
<table width="100%">
<td><img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_bc19288dce04b8ed2a6361e370fff4d3.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotX = delim{[}{matrix{3}{3}{1 0 0 0 {cos(theta)} {-sin(theta)} 0 {sin(theta)} {cos(theta)}}}{]}" title="rotX = delim{[}{matrix{3}{3}{1 0 0 0 {cos(theta)} {-sin(theta)} 0 {sin(theta)} {cos(theta)}}}{]}"/></td>
<td><img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_48f328ce40e3daa3b6b254993f00f539.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotY = delim{[}{matrix{3}{3}{{cos(theta)} 0 {sin(theta)} 0 1 0 {-sin(theta)} 0 {cos(theta)}}}{]}" title="rotY = delim{[}{matrix{3}{3}{{cos(theta)} 0 {sin(theta)} 0 1 0 {-sin(theta)} 0 {cos(theta)}}}{]}"/></td>
<td><img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_07348bdb67e7aa9dbaec5ba1f4444cf8.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotZ = delim{[}{matrix{3}{3}{{cos(theta)} {-sin(theta)} 0 {sin(theta)} {cos(theta)} 0 0 1 0}}{]}" title="rotZ = delim{[}{matrix{3}{3}{{cos(theta)} {-sin(theta)} 0 {sin(theta)} {cos(theta)} 0 0 1 0}}{]}"/></td>
</table>
<p> It is also important to know that every point in our world is defined by:<br />
<img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_971.5_b37f4b7621c7a8e878c47165d7a82672.png" style="vertical-align:-28.5px; display: inline-block ;" alt="vec{p } = delim{[}{matrix{3}{1}{x y z}}{ ]}" title="vec{p } = delim{[}{matrix{3}{1}{x y z}}{ ]}"/><br />
This can be seen in Point3D.java below. (Which is synonymous to a Vector in this application.) </p>
<p><br/><b>Rotate Around Arbitrary Axis</b><br />
The above rotations are all rotations about either the X,Y, or Z axises. But another common and more complicated rotation is to rotate Vector/Point A around Vector/Point B.<br />
Here are the Steps:<br />
1. the Vector that is being rotated around must be NORMALIZED.<br />
this can be done very easily</p>
<table width="100%">
<td>1a. <img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_986.5_8a326df1f1a94b48a2deff565f5e6e9d.png" style="vertical-align:-13.5px; display: inline-block ;" alt="d = sqrt(x^2 + y^2 + z^2)" title="d = sqrt(x^2 + y^2 + z^2)"/></td>
<td>
 1b. <img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_da220b5a11df89470afe59ad29b530c6.png" style="vertical-align:-58.5px; display: inline-block ;" alt="hat{p} = delim{[}{matrix{3}{1}{x/d y/d z/d}}{]}" title="hat{p} = delim{[}{matrix{3}{1}{x/d y/d z/d}}{]}"/></td>
</table>
<p>2. next, using quaternions, perform the rotation.<br />
Where:<br />
2a. <img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_994.5_3d5d7957084ecfb29cf311eeeb3b7a93.png" style="vertical-align:-5.5px; display: inline-block ;" alt="hat{p} = ai + bj + ck" title="hat{p} = ai + bj + ck"/><br />
<img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_971.5_1f7af62e73ff888f2f6c5047a0c7abd4.png" style="vertical-align:-28.5px; display: inline-block ;" alt="q0 = cos(theta/2),  q1 = sin(theta/2) a,  q2 = sin(theta/2) b,  q3 = sin(theta/2) c" title="q0 = cos(theta/2),  q1 = sin(theta/2) a,  q2 = sin(theta/2) b,  q3 = sin(theta/2) c"/>  (<img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_994.5_dfcdced295ae300b5c8b4b2f956174b0.png" style="vertical-align:-5.5px; display: inline-block ;" alt="theta" title="theta"/> is in radians)<br />
The rotation matrix evaluates to the following:<br />
2b. <img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_95d334d1cb8898933a43bf2429eb6902.png" style="vertical-align:-58.5px; display: inline-block ;" alt="rotAB = delim{[}{matrix{3}{3}{ (q0^2 + q1^2 - q2^2 - q3^2) {2(q1q2 - q0q3)} {2(q1q3 + q0q2)} {2(q2q1 + q0q3)} (q0^2 - q1^2 + q2^2 - q3^2)  {2(q2q3 - q0q1)}  {2(q3q1 - q0q2)} {2(q3q2 + q0q1)} {(q0^2 - q1^2 - q2^2 + q3^2)} }}{]}" title="rotAB = delim{[}{matrix{3}{3}{ (q0^2 + q1^2 - q2^2 - q3^2) {2(q1q2 - q0q3)} {2(q1q3 + q0q2)} {2(q2q1 + q0q3)} (q0^2 - q1^2 + q2^2 - q3^2)  {2(q2q3 - q0q1)}  {2(q3q1 - q0q2)} {2(q3q2 + q0q1)} {(q0^2 - q1^2 - q2^2 + q3^2)} }}{]}"/><br />
<br/><b>Example:</b> Suppose we have point <img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_971.5_6e5df3fbc73e5cdb4afc1f80e840b529.png" style="vertical-align:-28.5px; display: inline-block ;" alt="vec{p} = delim{[}{matrix{3}{1}{1 2 3}}{]}" title="vec{p} = delim{[}{matrix{3}{1}{1 2 3}}{]}"/><br />
and we would like to rotate <img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_994.5_1b5b0f1bfc276496f2ac21892aa12531.png" style="vertical-align:-5.5px; display: inline-block ;" alt="vec{p}" title="vec{p}"/> by 30° around the X axis.<br />
<img src="http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_29bf15549cfab5d584da786e22323e1b.png" style="vertical-align:-58.5px; display: inline-block ;" alt="vec{p}_{new} = (rotX)vec{p} = delim{[}{matrix{3}{3}{1 0 0 0 {cos(theta)} {-sin(theta)} 0 {sin(theta)} {cos(theta)}}}{]}.delim{[}{matrix{3}{1}{x y z}}{]} = delim{[}{matrix{3}{3}{1 0 0 0 {cos(30)} {-sin(30)} 0 {sin(30)} {cos(30)}}}{]}.delim{[}{matrix{3}{1}{1 2 3}}{]}" title="vec{p}_{new} = (rotX)vec{p} = delim{[}{matrix{3}{3}{1 0 0 0 {cos(theta)} {-sin(theta)} 0 {sin(theta)} {cos(theta)}}}{]}.delim{[}{matrix{3}{1}{x y z}}{]} = delim{[}{matrix{3}{3}{1 0 0 0 {cos(30)} {-sin(30)} 0 {sin(30)} {cos(30)}}}{]}.delim{[}{matrix{3}{1}{1 2 3}}{]}"/></p>
<p>And finally, to project the 3D points onto a 2D canvas after performing a rotation, a simple way is to simply ignore the Z coordinate and draw the point based on it&#8217;s X and Y coordinates. However this is assuming that you&#8217;re projecting it on to the screen as if you are looking straight at it.</p>
<p>The source code can be found below as well as being bundled into the Jar file.</p>
<p><a href="http://ken-soft.com/?p=368" >Cube 3D</a> - A simple 3D Cube engine that demonstrates the usage of ALL the above mentioned equations.</p>
<p>Transform3D.java - This is a simple version using a 3&#215;3 matrix. Using a 4&#215;4 matrix you can also store the translation information. This is useful when trying to program a skeleton represented by vectors.<br />
(Also, check out Graph/Rotate4D <a href="http://ken-soft.com/?p=296">here</a></p>
<p><a href="http://ken-soft.com/code/java/graph3D/Transform3D.java" class="code">Transform.java</a></p>
<p><a href="http://ken-soft.com/code/java/graph3D/Point3D.java" class="code">Point3D.java</a></p>
<p>Other included source:</p>
<p><a href="http://ken-soft.com/code/java/graph3D/Graph3D.java">Graph3D.java</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=147</wfw:commentRss>
		</item>
		<item>
		<title>Kana Tutor</title>
		<link>http://ken-soft.com/?p=115</link>
		<comments>http://ken-soft.com/?p=115#comments</comments>
		<pubDate>Thu, 25 Dec 2008 07:36:38 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Japan]]></category>

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

		<category><![CDATA[Language Software]]></category>

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

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

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

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

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

		<category><![CDATA[かたかな]]></category>

		<category><![CDATA[かな]]></category>

		<category><![CDATA[ひらがな]]></category>

		<category><![CDATA[日本語]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=115</guid>
		<description><![CDATA[This is some simple software a wrote a while back for studying Katakana(カタカナ) and Hiragana(ひらがな), Japanese two alphabets (not including Kanji(漢字)). Unfortunately I have only ported it to Windows.
This Software will eventually be replaced with an online PHP page, so check back time to time! 
Download Here






]]></description>
			<content:encoded><![CDATA[<p>This is some simple software a wrote a while back for studying Katakana(カタカナ) and Hiragana(ひらがな), Japanese two alphabets (not including Kanji(漢字)). Unfortunately I have only ported it to Windows.</p>
<p>This Software will eventually be replaced with an online PHP page, so check back time to time! </p>
<p><a href="http://www.ken-soft.com/dl/kanatutor.zip"><b>Download Here</b></a></p>
<table width="100%">
<tr>
<td><a href="http://www.ken-soft.com/code/pb/jTutor/jt_01"><img width="195" src="http://www.ken-soft.com/code/pb/jTutor/jt_01.JPG" alt="Japanese Kana Tutor Katakana hiragana"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/jTutor/jt_02.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/jTutor/jt_02.JPG" alt="Japanese Kana Tutor Katakana hiragana"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/jTutor/jt_04.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/jTutor/jt_04.JPG" alt="Japanese Kana Tutor Katakana hiragana"/></a></td  ></tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=115</wfw:commentRss>
		</item>
		<item>
		<title>Magus Map Maker - 2D Multilayer Map</title>
		<link>http://ken-soft.com/?p=110</link>
		<comments>http://ken-soft.com/?p=110#comments</comments>
		<pubDate>Thu, 25 Dec 2008 07:12:31 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Game Development]]></category>

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

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

		<category><![CDATA[Software Development]]></category>

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

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

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

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

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

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=110</guid>
		<description><![CDATA[Note: for a more fully featured map maker, I would reccomend using Mappy This is just something I made a few years back to ease personal game development.
Magus Map Maker is a 2D multilayer game map maker written in Purebasic. Magus Map Maker Features:
Multiple Layers - make maps up to 3 layers plus an additional [...]]]></description>
			<content:encoded><![CDATA[<p><b>Note: for a more fully featured map maker, I would reccomend using Mappy</b> This is just something I made a few years back to ease personal game development.<br />
Magus Map Maker is a 2D multilayer game map maker written in <a href="http://www.purebasic.com">Purebasic</a>. Magus Map Maker Features:<br />
<b>Multiple Layers</b> - make maps up to 3 layers plus an additional &#8220;attribute&#8221; layer used to store other information about the map tiles.<br />
<b>Load tilesets</b> - Supports BMP,JPEG,PNG,TIFF,and TGA.formats.<br />
<b>Save/Load</b> - After working hard on maps, easily save/load them. Also features a save to image feature, so that you can view your whole map in one image file.<br />
<b>Tilenator</b> - This feature can turn a tilesheet into a directory of invidual tiles, and vice versa<br />
<b>Help Files</b> - Online help documentation to ease use  </p>
<p><a href="http://www.ken-soft.com/dl/mmm.zip"><b>Download Here</b></a><br />
For more extensive documentation concerning Magus Map Maker refer to the online help files: <a href="http://www.ken-soft.com/doc/mmm/help/"><b>Online Help</b></a></p>
<table width="100%">
<tr>
<td><a href="http://www.ken-soft.com/code/pb/mmm/2nd_layer.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/mmm/2nd_layer.JPG" /></a></td>
<td><a href="http://www.ken-soft.com/images/mmm/all_layers.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/mmm/all_layers.JPG" alt="2D Tile Map Maker"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/mmm/up_to_3rd_layer.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/mmm/up_to_3rd_layer.JPG"alt="2D Tile Map Maker" /></a></td  ></tr>
<tr>
<td><a href="http://www.ken-soft.com/code/pb/mmm/show_image.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/mmm/show_image.JPG" alt="2D Tile Map Maker"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/mmm/map16x16.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/mmm/map16x16.JPG" alt="2D Tile Map Maker"/></a></td>
<td width="195"><a href="http://www.ken-soft.com/code/pb/mmm/sprite_sheet.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/mmm/sprite_sheet.JPG" alt="2D Tile Map Maker"/></a></td>
</tr>
</table>
<table width="100%">
<tr>
<td><a href="http://www.ken-soft.com/code/pb/mmm/cave.JPG"><img width="500" src="http://www.ken-soft.com/code/pb/mmm/cave.JPG" alt="2D Tile Map Maker"/></a></td>
</tr>
</table>
<p><b>Credits</b><br />
<b>Programmer</b><br />
- Kenny Cason<br />
<b>Beta Testers</b><br />
- University of Arkansas Game Development Club</p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=110</wfw:commentRss>
		</item>
		<item>
		<title>Blocks - Advanced Tetris Clone (Written in Purebasic)</title>
		<link>http://ken-soft.com/?p=97</link>
		<comments>http://ken-soft.com/?p=97#comments</comments>
		<pubDate>Thu, 25 Dec 2008 06:37:58 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Game Development]]></category>

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

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

		<category><![CDATA[Software Development]]></category>

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=97</guid>
		<description><![CDATA[Blocks is a tetris like game written in Purebasic. Blocks features 3 modes:
Baby Mode - simple pieces constructed from 3 bricks.
Normal Mode - standard tetris pieces.
Blocks Mode - pieces constructed from 1 - 6 bricks. 27 different pieces, including a randomly generated piece that can take on bizzare shapes. In this mode it is possible [...]]]></description>
			<content:encoded><![CDATA[<p>Blocks is a tetris like game written in <a href="http://www.purebasic.com">Purebasic</a>. Blocks features 3 modes:<br />
<b>Baby Mode</b> - simple pieces constructed from 3 bricks.<br />
<b>Normal Mode</b> - standard tetris pieces.<br />
<b>Blocks Mode</b> - pieces constructed from 1 - 6 bricks. 27 different pieces, including a randomly generated piece that can take on bizzare shapes. In this mode it is possible to clear 6 lines at once, earning yourself a &#8220;Block.&#8221; I recommend playing it in block mode and large size for the most fun. <img src='http://ken-soft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Enjoy!<br />
High Scores are saved for each of the modes.</p>
<p><a href="http://www.ken-soft.com/dl/blocks.zip"><b>Download Here</b></a><br />
<a href="http://www.ken-soft.com/code/pb/blocks/blocks.pb"><b>Download Source Here</b></a>It has been a few years since I compiled it. I believe it was compiled using Purebasic v3.94, However, It should be fairly easy to make changes to get it to recompile in the most recent version, or just to convert it into another language.</p>
<table width="100%">
<tr>
<td><a href="http://www.ken-soft.com/code/pb/blocks/screenshot.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/blocks/screenshot.JPG" alt="Blocks 2D Tetris clone"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/blocks/screenshot2.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/blocks/screenshot2.JPG" alt="Blocks 2D Tetris clone"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/blocks/screenshot3.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/blocks/screenshot3.JPG" alt="Blocks 2D Tetris clone"/></a></td  ></tr>
<tr>
<td><a href="http://www.ken-soft.com/code/pb/blocks/screenshot4.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/blocks/screenshot4.JPG" alt="Blocks 2D Tetris clone"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/blocks/screenshot5.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/blocks/screenshot5.JPG" alt="Blocks 2D Tetris clone"/></a></td>
<td width="195"></td>
</tr>
</table>
<p><b>About Blocks</b></p>
<p><b>Credits</b><br />
<b>Programmer</b><br />
- Kenny Cason<br />
<b>Graphics Design</b><br />
- Kenny Cason<br />
<b>Music</b><br />
 - Nintendo<br />
<b>Beta Testers</b><br />
- Kenny Cason<br />
- David Johnson</p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=97</wfw:commentRss>
		</item>
		<item>
		<title>Vulcan I - (Written in Purebasic)</title>
		<link>http://ken-soft.com/?p=73</link>
		<comments>http://ken-soft.com/?p=73#comments</comments>
		<pubDate>Thu, 25 Dec 2008 06:14:26 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Game Development]]></category>

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

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

		<category><![CDATA[Software Development]]></category>

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

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

		<category><![CDATA[Side Scroller]]></category>

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=73</guid>
		<description><![CDATA[Vulcan I is a sidescrolling space shooter written in Purebasic. This was my first major attempt at programming a game and is far from perfect. Vulcan I features 7 full length levels, each ending with a boss battle, many of which are redundant. Each level is unique and has its own array of enemies and [...]]]></description>
			<content:encoded><![CDATA[<p>Vulcan I is a sidescrolling space shooter written in <a target="_blank" href="www.purebasic.com">Purebasic</a>. This was my first major attempt at programming a game and is far from perfect. Vulcan I features 7 full length levels, each ending with a boss battle, many of which are redundant. Each level is unique and has its own array of enemies and terrains. Equip various powerups to prepare for the final showdown to save the universe.</p>
<p><a href="http://www.ken-soft.com/dl/vulcan.zip"><b>Download Here</b></a></p>
<table width="100%">
<tr>
<td><a href="http://www.ken-soft.com/code/pb/vulcan/screenshot01.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/vulcan/screenshot01.JPG" alt="Vulcan Side Scrolling Space Shooter"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/vulcan/screenshot02.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/vulcan/screenshot02.JPG" alt="Vulcan Side Scrolling Space Shooter"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/vulcan/screenshot03.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/vulcan/screenshot03.JPG" alt="Vulcan Side Scrolling Space Shooter"/></a></td>
</tr>
<tr>
<td><a href="http://www.ken-soft.com/code/pb/vulcan/screenshot04.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/vulcan/screenshot04.JPG" /></a></td>
<td><a href="http://www.ken-soft.com/code/pb/vulcan/screenshot05.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/vulcan/screenshot05.JPG" alt="Vulcan Side Scrolling Space Shooter"/></a></td>
<td><a href="http://www.ken-soft.com/code/pb/vulcan/screenshot06.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/vulcan/screenshot06.JPG" alt="Vulcan Side Scrolling Space Shooter"/></a></td>
</tr>
<tr>
<td><a href="http://www.ken-soft.com/code/pb/vulcan/screenshot07.JPG"><img width="195" src="http://www.ken-soft.com/code/pb/vulcan/screenshot07.JPG" alt="Vulcan Side Scrolling Space Shooter" /></a></td>
</tr>
</table>
<p><b>About Vulcan</b></p>
<ul><b>Keyboard:<br />
</b></p>
<li>Direction Keys - moves the ship in the designated direction
</li>
<li>Space - shoots the selected weapon
</li>
<li>Left Alt - Cycles through the weapon arsenal
</li>
<li>C - Pause/Unpause
</li>
<li>V - Speed down *as of now it speeds down very rapidly
</li>
<li>R - Resets the game
</li>
</ul>
<ul><b>Controller:</b></p>
<li>Dpad or analog - moves the ship in the designated direction
</li>
<li>button 3 - shoots the selected weapon
</li>
<li>button 1 - speed down
</li>
<li>button 7 &#038; 8 - Cycle through weapon arsenal
</li>
<li>start - pause *** push any other button to unpause
</li>
<li>select - reset game
</li>
</ul>
<ul><b>Beam Weapons<br />
</b></p>
<li>Phazor - The basic weapon at your disposal. however this weapon
 </li>
<li>can become quite devastating.
</li>
<li>Homing - A ball of energy launches at all the enemies on the screen</li>
<li>Plasma - A powerful bolt of plasma
</li>
<li>Charge - slow to charge but the power is worth it
</li>
<li>Vulcan - The most lethal weapon and has the most deadly upgrades. enemies will think twice about attacking you. <img src='http://ken-soft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<ul><b>Upgrades<br />
</b></p>
<li>Speedup - The ships speed increases
</li>
<li>Beams - Upon aquiring these powerups a new weapon will be available
</li>
<li>Armorup - Not only does the ships armor increase but so does its appearance
<li>Special - Each weapon has its own unique upgrade.
</li>
</ul>
<ul><b>Misc</b>  	</p>
<li>Points	- scores an extra 500 points
</li>
<li>Difficulty - easy, medium
</li>
<li>Unlockable Difficulty - hard, super ultra mega hard
</li>
<li>Unlockable mode - bonus mode - beat the game in super ultra mega hard
</li>
<li>saves hiScore and 6 character name</li>
</ul>
<p>The music for Vulcan is a tune made by Anthony Lofton, and it alone should make you want to keep playing the game.</p>
<p><b>Credits</b><br />
<b>Programmer</b><br />
- Kenny Cason<br />
<b>Graphics Design</b><br />
- Kenny Cason<br />
- David Johnson<br />
- Josh Daughtery<br />
- Nintendo<br />
<b>Music</b><br />
 - Anthony Lofton<br />
<b>Beta Testers</b><br />
- John Deforest<br />
- Kenny Cason<br />
- David Johnson<br />
- Connie Jiang<br />
- Gladson-Ripley Dorm</p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=73</wfw:commentRss>
		</item>
		<item>
		<title>Neural Networks - Simple Models (PDF)</title>
		<link>http://ken-soft.com/?p=70</link>
		<comments>http://ken-soft.com/?p=70#comments</comments>
		<pubDate>Thu, 25 Dec 2008 03:02:07 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Artificial Intelligence]]></category>

		<category><![CDATA[Neural Networks]]></category>

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

		<category><![CDATA[Back-Error Propagation]]></category>

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

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

		<category><![CDATA[Neural Network]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=70</guid>
		<description><![CDATA[  
]]></description>
			<content:encoded><![CDATA[<p><embed wmode="transparent" src="http://www.ken-soft.com/doc/neuralnetwork-en.pdf" width="100%" height="600">  </p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=70</wfw:commentRss>
		</item>
		<item>
		<title>ニューラルネット（神経回路網・誤差逆伝播法）PDF</title>
		<link>http://ken-soft.com/?p=65</link>
		<comments>http://ken-soft.com/?p=65#comments</comments>
		<pubDate>Thu, 25 Dec 2008 02:52:41 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Artificial Intelligence]]></category>

		<category><![CDATA[Neural Networks]]></category>

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

		<category><![CDATA[ニューラルネット]]></category>

		<category><![CDATA[人工知能]]></category>

		<category><![CDATA[学習方]]></category>

		<category><![CDATA[神経回路]]></category>

		<category><![CDATA[誤差逆伝播法]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=65</guid>
		<description><![CDATA[  
]]></description>
			<content:encoded><![CDATA[<p><embed wmode="transparent" src="http://www.ken-soft.com/doc/neuralnetwork-jp.pdf" width="100%" height="600">  </p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=65</wfw:commentRss>
		</item>
		<item>
		<title>Logical Method for Solving the 3&#215;3x3 Rubik&#8217;s Cube</title>
		<link>http://ken-soft.com/?p=49</link>
		<comments>http://ken-soft.com/?p=49#comments</comments>
		<pubDate>Thu, 25 Dec 2008 02:29:18 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Learning]]></category>

		<category><![CDATA[Rubik's Cube]]></category>

		<category><![CDATA[How to]]></category>

		<category><![CDATA[Layer-by-Layer]]></category>

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

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

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

		<guid isPermaLink="false">http://ken-soft.com/?p=49</guid>
		<description><![CDATA[How to Logically Solve a Rubik’s Cube
Kenneth Cason
	First, as with any problem, it is important to understand what your objective is. In the case of the Rubik’s Cube, the main goal is to arrange the pieces in such a way that each side is the same color. Next lets luck at the structure of a [...]]]></description>
			<content:encoded><![CDATA[<p><center>How to Logically Solve a Rubik’s Cube</center><br />
<center>Kenneth Cason</center><br />
	First, as with any problem, it is important to understand what your objective is. In the case of the Rubik’s Cube, the main goal is to arrange the pieces in such a way that each side is the same color. Next lets luck at the structure of a standard 3&#215;3 Rubik’s Cube. It is a cube composed of 6 sides, each side composed of 9 stickers (3&#215;3). There are 8 corner pieces, 12 edge pieces and 6 center pieces (one on each side). It is also important to note that on all “odd” Rubik’s Cube’s the center pieces can rotate clockwise or counter clockwise, but the positions are fixed. “odd” meaning that the cube is a 3&#215;3, 5&#215;5, NxN, where N is an odd number. Also, because the center pieces are fixed it becomes immediately obvious which side is which color.<br />
	Now that we know the basic structure of a Rubik’s Cube next lets think about strategies to solve it. First, lets examine what is probably the most common way to solve a Rubik’s Cube, the “Layer by Layer” method. For those not familiar with the Layer by Layer method, it involves solving the top, middle, and bottom layer in that order. However, despite this seeming to be the most logical way to approach the Rubik’s Cube, it is actually farm more difficult to solve in this manner. The problem is very simple. If you solve the first layer completely, in order to solve the second layer without messing up the solved first layer the moves grow in length and complexity. Then to solve the bottom layer without messing up the top and middle ayers, the moves again grow even more complex. To add a quantitative example, lets look at the case of trying to place a piece in the second row without messing up the first row it takes 7 permutations, and to switch the bottom layer edge pieces positions without messing up the top and middle layers, permutations can be as much as 15, in which you are more likely to give up before you ever derive on your own techniques. Not to say that it is impossible, but without any experience cubing can prove to be very difficult. However using the method In this paper, you can place all edge pieces in their correct positions in as  f approximately 3 permutations each. In a nutshell, this is where most people are mistaken, is thinking that the Layer by Layer method is the easiest way to solve a Rubik’s Cube when in fact mathematically it’s more complex to do so.<br />
	Also, until you are comfortable with the feel of a Rubik’s Cube, I highly recommend to avoid checking many websites for solutions as they primarily rely on rote memorization of techniques, though definitely useful after you’ve got a feel for the cube on your own. Plus it’s more rewarding when you do it on your own. Now, the next time you see someone solving a Rubik’s Cube using the Layer by Layer method, you can assume that about 99% of the time they learned how to solve it from either A) a friend or B) the internet. Also, contrary to popular belief, you cannot re-stick the stickers after peeling them off. As encouragement, you may also be happy to know that you need not know or understand any mathematics to solve the Rubik’s Cube. Good Luck!<br />
	Note, as I believe it spoils the reward of solving the Rubik’s Cube, I will NOT write any algorithms that will directly tell you how to move pieces as shown in the following diagrams. This guide is merely designed to guide and kindle your thoughts and let you know that there is a simpler method than the layer-by-layer method.</p>
<p>Explanation:<br />
1. First, scramble up the Rubik’s Cube, if it isn’t already. </p>
<p>2. All except on corner piece, solve the top layer. This may seem difficult at first, but will become simple as you practice.</p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc2.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>Just like in the diagram, solve the for edge pieces in the top layer, creating a cross. Ensure that the color orientation is correct all the way around by examining the center pieces color in the middle layer.
</td>
</table>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc3.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>Next, solve any three of the corner pieces in the top layer, leaving one unsolved corner piece. You may choose to the corner to not solve at your own discretion.</td>
</table>
<p>3. Except for one edge piece, place corresponding 3 edge pieces  into the middle layer.</p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc4.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>In order to do this, we are going to make use of the unsolved corner piece in the top layer. In general you first place the unsolved corner of the top layer directly over the place in the second layer where you want to place the correct piece (which must be in the bottom layer). Then in only 3 moves each you can solve 3 of the 4 edge pieces in the middle layer. The resulting pattern should be similar to whats in the diagram to the left.</td>
</table>
<p>4. Next, turn the cube upside down exposing the bottom layer.</p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc5.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>The unsolved 2 pieces from the top and middle layer in previous steps can now be used to place the edge pieces correctly in the bottom row.</td>
</table>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc6.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>If done correctly the resulting pattern will be as described in the diagram to the left.</td>
</table>
<p>5. Next, place the remaining corner pieces into their correct place, without regarding orientation. Typical algorithms involve the rotation of 3 corner pieces either clockwise or counterclockwise. To do so takes and algorithm of only 8 moves. Depending on probability you may even be lucky enough to solve the cube at this point by simple rotating the corners.</p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc7.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>An example of a sample 3 corner rotation clockwise.</td>
</table>
<p>6. Finally, what may seem to be the most difficult part of the cube, rotating two corner pieces orientation. However, this is deceptively easy. As you can see in the diagram if one corners orientation is rotated clockwise, one other corner piece is rotated oppositely. This is because during the process of rotating one corner piece, the cube gets messed up. Then by performing the operations in reverse to another corner piece, it causes the cube to fix itself and rotate one other piece in the opposite direction. It can be viewed in a simpler case such as if you rotate the top face clockwise, naturally by doing the opposite and rotating the top face counterclockwise, you will fix the cube. This principle is in my opinion a key concept in understanding the Rubik’s Cube. </p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc8.jpg" alt="Rubik's Cube Tutorial"/></center></td>
<td>To perform the rotations shown in the diagram requires and algorithm of 14 moves. However, Don’t be alarmed, half of it is simply undoing what you did in the first half. So it’s really more like 6 moves to rotate a single corner piece in one direction, 1 move to put the next corner to rotate into position, 6 moves to undo the first 6 moves you did which causes the corner piece to rotate in the opposite direction. 1 move to readjust the top layer</td>
</table>
<p>The secret to the Rubik’s Cube is practice. The more you work at it the more you will understand it.<br />
Good Luck!</p>
<p>PDF Download available <a href="http://www.ken-soft.com/doc/rubikscube-en.pdf">here</a><br />
Japanese Version available here <a href="http://www.ken-soft.com/doc/rubikscube-jp.pdf">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=49</wfw:commentRss>
		</item>
		<item>
		<title>ルービックキューブの論理的なやり方（３x３x３）</title>
		<link>http://ken-soft.com/?p=37</link>
		<comments>http://ken-soft.com/?p=37#comments</comments>
		<pubDate>Thu, 25 Dec 2008 01:17:19 +0000</pubDate>
		<dc:creator>Kenny</dc:creator>
		
		<category><![CDATA[Learning]]></category>

		<category><![CDATA[Rubik's Cube]]></category>

		<category><![CDATA[3x3]]></category>

		<category><![CDATA[やり方]]></category>

		<category><![CDATA[パズル]]></category>

		<category><![CDATA[ルービックキューブ]]></category>

		<category><![CDATA[仕方]]></category>

		<category><![CDATA[揃え方]]></category>

		<category><![CDATA[方法]]></category>

		<category><![CDATA[考え方]]></category>

		<guid isPermaLink="false">http://ken-soft.com/?p=37</guid>
		<description><![CDATA[ルービックキューブの論理的なやり方
Kenny Cason(ケン・ケーソン)
　まず、ルービックキューブの目的は同じ色を集めていくことである。それで、普通のルービックキューブの構成を教えてみよう。ルービックキューブは立方体で、各面は9個(3&#215;3)の色の付いたシールがある。コーナキューブが8個で、エッジキューブが12個で各面の中心にあるセンターキューブが6個で構成されている。奇数のルービックキューブの中心のピースは回転するが移動しない。それゆえ、各面の正解の色が簡単に判る。次は解き方を考えてみよう。一番目、二面目、三面目をそれぞれ揃ていくという方法が一番よく使われている方法だろうが、意外にそうやって揃おうとすと、問題が出る。例えば、一面目を完全に揃えたら、二面目を揃う為に既に揃えた場所を崩さずに他の場所を揃えると、動作が非常に多くなるから、解くのももっと難しくなって、揃える前に諦める可能性がある。これは殆どの人の間違えの一つだと思う。インターネットでルービックキューブのやり方を検索すると、沢山のウェブサイトが出てくるが、殆どのウェブサイトは動作の暗記だけで、解き方はとても回りくどいだから、あまり役に立たないと思う。あと、自分で考えた方が価値があると思う。では、もっと分かりやすいやり方を教えてみよう。ルービックキューブのやり方は比較的に簡単だから、頑張って!
説明:
1。まず、ルービックキューブを回して色をバラバラに崩す。
2。一つのコーナキューブ以外、一面目を揃えていく。これを自力で出来なければ、もっと練習しなければならない。



こんなふうに一面目の間のピースを揃えていく。




それで、一面目のコーナキューブを三つ揃えていく。どれでもいい。


3。二段目のエッジキューブを三つ揃えていく。



まずは、一面目のまだ揃ってないコナーキューブを二面目のまだ揃ってないエッジキューブの上に回す。

4。一番下の段のエッジキューブを揃えていく。これらのキューブをそれぞれ三つの動作
で揃えていく。



まだ揃えてないエッジキューブを簡単に正しい場所に入れる為、一、二面目の二つの揃えてないキューブのスペースを使うコツがある。




ステップ4が終わったら、すべてのエッジキューブが揃えている。

5。次は、コナーキューブを揃えていく。残っているまだ揃っていないコナーキューブを正しい場所に入れていく。八回の動作で三個のコナーキューブが右・左回りに回転することができる。確率によると、一個から三個のキューブを同時に揃えることが出来る。



コナーキューブが揃うまで、回す。

6。最後は一番難しそうかもしれないが、意外にコナーキューブの回転のやり方は分かりやすい。一個のコナーキューブを回したら、ルービックキューブを直す為に、他のスタートポイントを前のコナーキューブと同じ場所から逆に回さなければならない。



十四回の動作で二個のコナーキューブを逆に回す

ルービックキューブをするにはコツは練習です。
頑張ってください！
PDFは下のリンクからダウンロードできます。
日本語：ダウンロード
英語ダウンロード 
]]></description>
			<content:encoded><![CDATA[<p><center>ルービックキューブの論理的なやり方</center><br />
<center>Kenny Cason(ケン・ケーソン)</center><br />
　まず、ルービックキューブの目的は同じ色を集めていくことである。それで、普通のルービックキューブの構成を教えてみよう。ルービックキューブは立方体で、各面は9個(3&#215;3)の色の付いたシールがある。コーナキューブが8個で、エッジキューブが12個で各面の中心にあるセンターキューブが6個で構成されている。奇数のルービックキューブの中心のピースは回転するが移動しない。それゆえ、各面の正解の色が簡単に判る。次は解き方を考えてみよう。一番目、二面目、三面目をそれぞれ揃ていくという方法が一番よく使われている方法だろうが、意外にそうやって揃おうとすと、問題が出る。例えば、一面目を完全に揃えたら、二面目を揃う為に既に揃えた場所を崩さずに他の場所を揃えると、動作が非常に多くなるから、解くのももっと難しくなって、揃える前に諦める可能性がある。これは殆どの人の間違えの一つだと思う。インターネットでルービックキューブのやり方を検索すると、沢山のウェブサイトが出てくるが、殆どのウェブサイトは動作の暗記だけで、解き方はとても回りくどいだから、あまり役に立たないと思う。あと、自分で考えた方が価値があると思う。では、もっと分かりやすいやり方を教えてみよう。ルービックキューブのやり方は比較的に簡単だから、頑張って!</p>
<p>説明:<br />
1。まず、ルービックキューブを回して色をバラバラに崩す。<br />
2。一つのコーナキューブ以外、一面目を揃えていく。これを自力で出来なければ、もっと練習しなければならない。</p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc2.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>こんなふうに一面目の間のピースを揃えていく。</td>
</table>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc3.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>それで、一面目のコーナキューブを三つ揃えていく。どれでもいい。
</td>
</table>
<p>3。二段目のエッジキューブを三つ揃えていく。</p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc4.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>まずは、一面目のまだ揃ってないコナーキューブを二面目のまだ揃ってないエッジキューブの上に回す。</td>
</table>
<p>4。一番下の段のエッジキューブを揃えていく。これらのキューブをそれぞれ三つの動作<br />
で揃えていく。</p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc5.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>まだ揃えてないエッジキューブを簡単に正しい場所に入れる為、一、二面目の二つの揃えてないキューブのスペースを使うコツがある。</td>
</table>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc6.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>ステップ4が終わったら、すべてのエッジキューブが揃えている。</td>
</table>
<p>5。次は、コナーキューブを揃えていく。残っているまだ揃っていないコナーキューブを正しい場所に入れていく。八回の動作で三個のコナーキューブが右・左回りに回転することができる。確率によると、一個から三個のキューブを同時に揃えることが出来る。</p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc7.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>コナーキューブが揃うまで、回す。</td>
</table>
<p>6。最後は一番難しそうかもしれないが、意外にコナーキューブの回転のやり方は分かりやすい。一個のコナーキューブを回したら、ルービックキューブを直す為に、他のスタートポイントを前のコナーキューブと同じ場所から逆に回さなければならない。</p>
<table width="100%">
<tr>
<td><center><img padding="0" width="150" src="http://www.ken-soft.com/images/rc/rc8.jpg" alt="Rubik's Cube Tutorial" /></center></td>
<td>十四回の動作で二個のコナーキューブを逆に回す</td>
</table>
<p>ルービックキューブをするにはコツは練習です。<br />
頑張ってください！</p>
<p>PDFは下のリンクからダウンロードできます。<br />
日本語：<a href="http://www.ken-soft.com/doc/rubikscube-jp.pdf">ダウンロード</a><br />
英語<a href="http://www.ken-soft.com/doc/rubikscube-en.pdf">ダウンロード</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://ken-soft.com/?feed=rss2&amp;p=37</wfw:commentRss>
		</item>
	</channel>
</rss>
