Week 3 (Ending 15/2/08)

Finally Processing works on Ubuntu. The problem earlier turned out to be rather stupid. Ubuntu had jikes installed previously which was actually incompatible with Processing. So I just uninstalled the machine's jikes version and worked it out. (Thanks to Janaka for pointing out this error.)

Also I have connected Processing with MySQL

Here is the sample code..

import de.bezier.sql.*;
import de.bezier.mysql.*;
 
MySQL msql;
 
void setup()
{
    size( 100, 100 );
 
    // this example assumes that you are running the 
    // mysql server locally (on "localhost").
    //
 
    String user     = "root";
    String pass     = "password";
 
    String database = "Test";
 
    String table    = "Words";
 
    msql = new MySQL( "localhost", database, user, pass, this );
 
    if ( msql.connect() )
    {   
        // create a table with an id and a word
        //
        msql.execute( "CREATE TABLE IF NOT EXISTS " + table + " ("+
                          "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"+
                          "word VARCHAR( 255 )"+
                      ")"
                    );
 
        // fill the table with some data
        //
        msql.execute( "INSERT INTO " + table + " (word) VALUES (\"Lorem\")" );
        msql.execute( "INSERT INTO " + table + " (word) VALUES (\"ipsum\")" );
        msql.execute( "INSERT INTO " + table + " (word) VALUES (\"dolor\")" );
 
        // now read it back out
        //
        msql.query( "SELECT * FROM " + table );
 
        while (msql.next())
        {
            String s = msql.getString("word");
            int n = msql.getInt("id");
            println(s + "   " + n);
        }
 
        // need to find out how many rows there are in table?
        //
        msql.query( "SELECT COUNT(*) FROM " + table );
        msql.next();
        println( "number of rows: " + msql.getInt(1) );
    }
    else
    {
        // connection failed !
    }
}
 
void draw()
{
    // i know this is not really a visual sketch ...
}

The output is as follows.. Every time 3 records are added. Look at the black console part at the bottom of the image.

sqlrun.gif

Thoughts on the background for the whole system

I am thinking of using the current time to make the background change according to the time.. I did a simple analog clock with Processing just now. This could be a start for even more realistic things. Watch the clock video below..

New Goals

I talked to Prof Adrian on Tuesday just after he returned from Japan. After a pretty good discussion & Prof Adrian's talk Prof Tosa, some immediate short term goals were worked out..

1. Connect the PHP Chat to Processing.
2. Creating new type of text input/visualization using the processing software.

Thoughts on why we need Processing to interact with PHP although it can directly talk to the MySQL database

I believe that it might not be advisable to let Processing communicate directly with a MySQL server because the applet is running on the clients machine, which is not a 'trusted host' for communicating with the MySQL server. We could maybe sign the applet which will make it seem ok for it to access the database directly but still it will ask some annoying questions like "Do you trust content from this user.. blah blah.." when we do this.

So I thought a better way to do this should be to interact with a PHP page which will interact with the database. I believe it's actually more secure to handle the database stuff in a PHP script than in processing because a java applet can potentially be decompiled and then your MySQL login/password/server is available to be borrowed/stolen.

Hence we need to connect with PHP which in turn will do the main work by interacting with the database.

Connecting PHP chat to processing

My initial idea was to connect the current Taito source code for the Zen Master to Processing thinking that Japanese font was supported by Processing. But I was wrong. When I copy and paste Japanese characters into Processing they become garbage. And even when I supply the Japanese fonts to it they dont render in the applet. Check it out below.

ProcessingNoJapanese.png

I copied the Japanese characters in the title part of the index.html and pasted in the processing window and garbage shows up. When I try to render it doesn't shoe up also.

This is supported by the documentation in Processing Website..

Check it out at this page. I have highlighted the part in the page. So just scroll down and you should be able to see it.

So I thought of just doing a test case where the PHP script interacts with database and outputs in the Processing frame.

I completed the test case and here is the sample of the crude program. The user can type in his response here. But the computer response is totally unintelligent. So if I have a real PHP file which can intelligently choose responses then this will look really good.

testFYP.png

Looking Ahead

I am probably going to help with Confucius Computer and do some background research on my FYP project for the next few days.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License