Processing: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 215: Line 215:


Unsurprisingly, the performance on the XO-1.5 is way better. Complex examples, such as the OpenCV blob example, are running, not exactly fluently, but in an acceptable way. Table 1 shows the frame rates that a simple test script provided on different setups. The script attempts to draw 500 rectangles, 10 by 10 pixels of random color at a random position within the constraints of the window.
Unsurprisingly, the performance on the XO-1.5 is way better. Complex examples, such as the OpenCV blob example, are running, not exactly fluently, but in an acceptable way. Table 1 shows the frame rates that a simple test script provided on different setups. The script attempts to draw 500 rectangles, 10 by 10 pixels of random color at a random position within the constraints of the window.









[[File:Test_run.jpg|left|thumb|200px|Running test sketch (on Mac OS X)]]
[[File:Test_run.jpg|left|thumb|200px|Running test sketch (on Mac OS X)]]

Revision as of 19:44, 17 September 2010

Processing

Processing IDE

Processing is a tool consisting of a Java framework and a mini IDE. The framework allows the fast development of visual, animated, interactive sketches. An empty window for example is created without requiring the user to write a single line of code. The commands to create graphical elements, such as rectangles or ellipses, are short and easy to use. It is easy to color and animate these elements. Furthermore, methods to catch a variety of interaction events are provided.

Processing exporting an applet

The framework is well documented, but the documentation is currently available in English only. The User Interface is simple and similar to Pippy’s. One of its biggest advantages though, is the huge user and contributor base that provides many plugins for the simplification of a wide variety of tasks. For further information see <ref group="nb">www.processing.org</ref>. As Processing is based on Java it requires the existence of a Java Runtime. It is not necessary to install this Runtime separately though, as Processing for Linux brings its JRE along. This makes Processing a rather large install, about 160 MB<ref group="nb">Including the OpenCV plugin and examples</ref> , which causes problems with the XOs' limited resources. Having installed Processing on release 10.1.2 build os852 leaves about 140 MB of free disk<ref group="nb">The term disk will be used as a convenient way to address any form of mass storage</ref> space. This is on an otherwise clean install with an almost empty Journal on the XO-1. The situation on the XO-1.5 is far less dramatic as a lot more disk space is available. Processing’s performance on the XO-1 running build 767 and XFCE was poor but it worked. On the XO-1 running build os852 and Gnome it was intolerable. On the XO-1.5 it is not great but comparatively good. See #Performance for more details. Processing interacts with the XO’s hardware features without additional efforts. The game, arrow, and screen direction buttons are recognized and can be addressed as key events. Connecting to the camera via OpenCV works right away. Accessing the microphone and the speakers, using the Minim library, which is included in Processing, worked out of the box as well.



Accessing the camera via Processing and OpenCV


Mobile Processing

Mobile Processing is a derivate of Processing that allows to create sketches for mobile phones. It is currently available for Windows and Mac OS only. According to its website<ref group="nb">mobile.processing.org</ref> the project is no longer significantly active.



Alternatives to Processing

Regarding Processing’s problematic size and performance, some alternatives have been examined as well.

Processing derivates

Apart from currently being not more than a proof of concept, Python Processing appeared to be promising. Python is installed on the XOs anyway as Sugar is based on it. Having a closer look, it shows that it worsens the problem as it just wraps around Processing using Jython and thus requires Java plus Jython. Similar scenario for Ruby Processing and Scala Processing. <ref>i.document » Blog Archive » python processing proof of concept, http://goo.gl/opyT, Retrieved: 07/18/2010</ref> <ref>Neat Graphics with Scala Processing | The Scala Programming Language, http://goo.gl/jUKI, Retrieved: 07/18/2010</ref> <ref>jashkenas's ruby-processing at master - GitHub, http://goo.gl/BwPm, Retrieved: 07/18/2010</ref>


OpenFrameworks

OpenFrameworks is the C++ equivalent to Processing. Unlike Processing it does not provide its own simplified IDE, but requires an installation of either XCode on Mac OS, Visual Studio or Code::Blocks on Windows, or Code::Blocks on Linux.

Installation

XO-1

The following steps describe the necessary steps to install Processing on build 767. It is advised to read #Performance before following these steps. To install Processing on build os852/Gnome follow the steps as described for the XO-1.5. This is not recommended though, due to its poor #Performance.

XFCE

As Processing is not sugarized, an additional Desktop system needs to be installed. Available lightweight desktops are XFCE <ref group="nb">www.xfce.org</ref> and LXDE <ref group="nb">lxde.org</ref>. Installing XFCE on the XO was straight forward. To add a convenient way of switching back and forth between XFCE and Sugar, some additional tweaks are necessary. Compared to e.g. Gnome, XFCE is rather ugly. It is more lightweight though and thus better suitable for an installation on the XO-1. Installing LXDE has not been examined.

  • Open the Terminal
  • Get root user privileges
$ su
#

Using sudo instead of su is considered more secure and thus recommended if it is available. In contrary to su, sudo enables the root user for the current command only and thus needs to be repeated in front of most of the following commands. If you are following these steps using su you are advised to leave the superuser level by calling exit before you switch to other tasks.

  • Install XFCE using yum
# yum install xfdesktop xfce-utils xfce-mcs-plugins xfce4-session xfce4-icon-theme
  • Set XFCE as the default desktop

Switch to the /home/olpc/ directory and copy the file .xsession-example to .xsession

# cd /home/olpc/
# cp .xsession-example .xsession
  • Open the new file with your favorite text editor
# nano .xsession

Find the line that says: #exec xterm and add the following code below: exec startxfce4 Save and exit nano (Ctrl-x) and restart X (CTRL+ALT+BACKSPACE), starting XFCE. If the system stops during the boot process, just type startxfce into the prompt.

  • Prevent getting stuck in the boot animation

Switch to /etc/init.d and open the file 0-boot-anim-start in your favorite text editor.

# cd /etc/init.d/
# nano 0-boot-anim-start

Search for the line that reads "# i'm the child". Replace if os.fork() == 0: with if os.fork() == 'debug':

  • Install a desktop switcher control panel in Sugar to switch between Sugar and XFCE and integrate a Sugar control panel to switch the other way round

Install the necessary files using yum and rpm.

# yum install gnome-icon-theme
# rpm -ivh http://dev.laptop.org/~cscott/xfce/sugar-xfce-control-0.2-1.noarch.rpm  
# rpm -ivh http://dev.laptop.org/~cscott/xfce/sugar-mcs-plugin-1.1.0-1.fc9.i386.rpm

Open the file /usr/share/icons/sugar/index.theme in a text editor

# nano /usr/share/icons/sugar/index.theme

Add Inherits=gnome after the line [Icon Theme]

Open /usr/bin/olpc-session in a text editor

# nano /usr/bin/olpc-session

and add

[ -f "$HOME/.xsession-xfce" ] && . "$HOME/.xsession-xfce"

before the line

exec /usr/bin/ck-xinit-session

Watch out for the spaces.

<ref>XFCE</ref> <ref>XFCE and Sugar</ref>

Switching from Sugar to XFCE and back

Firefox / Opera

Having installed the desktop system, the next step is to install a browser. This is an important step as Processing’s documentation is available in HTML format, online and offline. Installing Firefox failed with: Missing Dependency: gecko-libs 1.9.0.11. Several proposed solutions have been tried. None of them worked. Therefore it was decided to install Opera instead, which worked fine. After the installation Opera will ask you to upgrade to a newer version. Don't do it.

# rpm -ivh ftp://ftp.opera.com/pub/opera/linux/964/final/en/i386/static/opera-9.64.gcc4-static-qt3.i386.rpm

<ref name="opera">Opera</ref>

Java

Installing Java actually is not necessary to run Processing. Processing for Linux comes with its own version of Java. So the following steps can be omitted. Considered the available disk space on the XO, it is recommended not to install the additional JRE. The price that has to be paid for this is that you cannot run the exported applications or applets. You can run the sketches from within Processing though.

To install the JRE follow these instructions: Only JRE 1.5 is working in this setting. <ref>Restricted formats</ref> Get jre-1_5_0_13-linux-i586-rpm.bin at java.sun.com/products/archive/j2se/5.0_13/ Click on the link Download JRE, select Linux as platform, agree to the license, and click continue. Download the RPM. Switch to the terminal. If you do not have root privileges still, get root privileges. Change to the directory where you downloaded the JRE installer. Run the installer.

# cd /path/to/the/downloaded/java/rpm/
# ./jre-1_5_0_13-linux-i586-rpm.bin
Enabling Java in Opera
  • Enable Java in Opera

Start Opera, open the Opera menu, go to Tools->Preferences. Click the advanced Tab and select the content section. Check the Enable Java checkbox. Click the Java Options button, and enter /usr/java/jre1.5.0_13/lib/i386/ in the text field.

<ref name="opera">Opera</ref>

  • Setting the paths

Open .bashrc in a text editor.

# nano /home/olpc/.bashrc

Add the lines:

export JAVA_HOME=/usr/java/jre1.5.0_13/

export PATH=$PATH:$JAVA_HOME/bin

<ref>OLPC runs Processing and Arduino, villamil.org/?p=106, Retrieved: 04/17/2010</ref>


Processing

Processing running on XO-1/XFCE

Now that all the preparations have been finished, Processing can finally be installed. Download the tarball, untar it and fix the directories permissions recursively.

# cd /home/olpc
# wget http://processing.googlecode.com/files/processing-1.2.1.tgz
# tar xvfz  processing-1.1.tgz
# chmod -R 0755 processing-1.1

Run Processing.

# cd Processing-1.1
# ./processing

Of course, Processing can be started from the GUI as well, double clicking its icon.

OpenCV

Install OpenCV to connect Processing to the camera.

#  yum install opencv

There are two more packages available, opencv-python and opencv-devel, both of them are not required. Finally download the Processing - OpenCV connector and put it into Processing’s library directory.

# cd  /home/olpc /Processing-1.2.1/libraries/
# wget http://ubaa.net/shared/processing/opencv/download/opencv_01.zip
# unzip opencv_01.zip
# rm opencv_01.zip

Additionally download the Processing OpenCV examples and move them to your sketchbook.

# cd  /home/olpc/sketchbook/
# wget http://ubaa.net/shared/processing/opencv/download/opencv_examples.zip
# unzip opencv_examples.zip
# rm opencv_examples.zip
# exit
$

Note that for most of these operations root user privileges are required. Do not forget to logout as root and switch back to your normal user level as soon as you have finished the installations.


XO-1.5

Installing Processing on the XO-1.5 as well as the newer releases for the XO-1 is much easier. Both come preinstalled with Gnome so there is no need to install another Desktop. Firefox is also preinstalled so there is no need to install another browser. The price that has to be paid on the XO-1 is an intolerably bad performance.

Java

Installing Java actually is not necessary to run Processing (see #Java). It has been tried to connect Firefox to the Java browser plugin that comes with Processing’s included JRE. This did not work so far. Firefox keeps asking to install a JRE.

Installing Java on the newer build is more straight forward. A regular installation using the current Java version can be performed. Download the JRE from here: http://java.sun.com/javase/downloads/index.jsp. Select the latest JRE click continue, select Linux as the operating system. Agree to the license and hit continue. On the next page select the rpm file.

  • Open the Terminal and go to the directory where the downloaded JRE is located
$ cd /path/to/the/downloaded/java/rpm/
$ sudo sh jre-xxx-linux-i586-rpm.bin

Replace xxx with the actual version number.

  • Activate the Firefox plugin
$ sudo /usr/sbin/alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so  libjavaplugin.so /usr/java/default/plugin/i386/ns7/libjavaplugin_oji.so 20000

<ref>Personal Fedora 11 Installation Guide, www.mjmwired.net, Retrieved: 07/06/2010</ref>

Processing

Installing Processing: Follow the instructions as given in #Processing.

OpenCV

Installing OpenCV: Follow the instructions as given in #OpenCV


Performance

The XO’s, especially the XO-1’s, specifications are causing two problems with Processing: Disk space and performance. Having installed XFCE, OpenCV, Opera, Processing, and a couple of examples the XO-1 soon ran out of disk space.

Upgrading to build os852/Gnome even worsens the situation.

Processing running on XO-1/Gnome. Messed up display

Processing’s performance on the XO-1 was less than satisfactory. It took several minutes to start the application and to build sketches. More complex Sketches, such as the OpenCV examples caused failures in the XO’s GUI. Frames of windows failed to be displayed, sometimes the contents of windows disappeared for minutes.

Gnome itself has some performance problems on the XO-1. It takes significant time to open and close windows or to switch between directories in the File Browser. The contents of some Processing sketches are displayed completely messed up. Opening the same sketch in a text editor proves that this is a display error.

Unsurprisingly, the performance on the XO-1.5 is way better. Complex examples, such as the OpenCV blob example, are running, not exactly fluently, but in an acceptable way. Table 1 shows the frame rates that a simple test script provided on different setups. The script attempts to draw 500 rectangles, 10 by 10 pixels of random color at a random position within the constraints of the window.





Running test sketch (on Mac OS X)

Simple performance test sketch

int t;
color c;
int wh;
void setup() {
  wh = 500;
  size(wh, wh);
  frameRate(200);
  t=500;
}
void draw() {
  for (int i = 0; i < t; i++) {
    c = color(random(255),random(255),random(255));
    fill(c);
    rect(random(wh), random(wh), 10,10);
  }
  println(frameRate);
}


Notes

<references group="nb" />

References

<references />