Archive for May, 2008

Code: Mesh library + demo

Saturday, May 31st, 2008
Demo of Lee Byron\'s Mesh library

MeshLibDemo.pde – Demo of Lee Byron’s Mesh library

Lee Byron has written a neat little Processing library called Mesh which allows for easy calculation and display of Voronoi, Delaunay and Convex Hull diagrams.

Given a set of points, these diagrams calculate the minimal regions around the points (Voronoi), an optimal triangulation of the points (Delaunay) or the polygon shape that contains all the points (Convex Hull). So far the library only supports the 2D versions of the diagrams, but it is in part based on the QuickHull3D java library which also handles 3D hulls.

Byron didn’t include any code examples in the current release, so I hacked up a quick demo.

Code: MeshLibDemo.pde

To run this example, download MeshLibDemo.zip and unzip it inside your Processing sketches folder. The Mesh library is included in a “libraries” subfolder, but you’ll have to restart Processing for the library to be recognized.

I’m posting the full code below for easy reference.

// MeshLibDemo.pde - Demo of Lee Byron's Mesh library for
// calculating and drawing Voronoi, Delaunay and Convex Hull
// diagrams. 

// Uses a set of random points to calculate all
// three diagrams, with one point responding to the mouse
// position. Press space to reset points, press '1', '2' and
// '3' to toggle display of the different diagrams.
//
// The library is included in this sketch, see the "libraries"
// subfolder See http://leebyron.com/else/mesh/ for more
// information about the library.
//
// Marius Watz - http://workshop.evolutionzone.com/

import megamu.mesh.*;

Voronoi myVoronoi;
Delaunay myDelaunay;
Hull myHull;

float[][] points;
float[][] myEdges;
MPolygon myRegions[],myHullRegion;
int col[];

float startX,startY,endX,endY;
float[][] regionCoordinates;

boolean showVoronoi=true;
boolean showDelaunay=false;
boolean showHull=false;

void setup() {
  size(500,250);

  // initialize points and calculate diagrams
  initMesh();
  smooth();
}

void draw() {
  background(200);
  if(myRegions==null) return;

  // draw Voronoi
  if(showVoronoi) {
    strokeWeight(1);
    stroke(0);
    for(int i=0; i< myRegions.length; i++) {
      fill(col[i]); // use random color for each region
      regionCoordinates = myRegions[i].getCoords();
      myRegions[i].draw(this); // draw this shape
    }
  }

  // draw Voronoi as lines
  if(showDelaunay) {
    strokeWeight(2);
    stroke(255,0,0);
    for(int i=0; i< myEdges.length; i++) {
      startX = myEdges[i][0];
      startY = myEdges[i][1];
      endX = myEdges[i][2];
      endY = myEdges[i][3];
      line(startX, startY, endX, endY);
    }
  }

  // draw Hull in semi-transparent yellow
  if(showHull) {
    strokeWeight(1);
    stroke(0);
    fill(255,255,0, 150);
    myHullRegion.draw(this);
  }
}

void initMesh() {
  // is points array is null then initialize it
  if(points==null) initPoints();

  // save the current number of regions, so that
  // we can check if it's the same after the Voronoi
  // has been recalculated.
  int oldlength=0;
  if(myRegions!=null) oldlength=myRegions.length;

  myVoronoi = new Voronoi( points );
  myHull = new Hull( points );
  myDelaunay = new Delaunay( points );

  myRegions = myVoronoi.getRegions();
  myHullRegion = myHull.getRegion();
  myEdges = myDelaunay.getEdges();

  // if the number of regions is different than
  // before then recalculate the random colors
  if(oldlength!=myRegions.length) {
    col=new int[myRegions.length];
    for(int i=0; i< myRegions.length; i++) {
      float prob=random(100);
      if(prob>60) col[i]=color(random(30,100));
      else col[i]=color(random(200,255));
    }
    col[0]=color(255,0,0);
  }
}

void initPoints() {
    points = new float[(int)random(5,30)][2];

  for(int i=0; i< points.length; i++) {
    points[i][0] = random(width); // first point, x
    points[i][1] = random(height); // first point, y
  }

}

void keyPressed() {
  // reset points and mesh when spacebar is pressed
  if(key==' ') {
    initPoints();
    initMesh();
  }

  // use keys '1'-'3' to toggle display
  if(key=='1') showVoronoi=!showVoronoi;
  if(key=='2') showDelaunay=!showDelaunay;
  if(key=='3') showHull=!showHull;
}

void mouseMoved() {
  // if myRegions is null then mesh is not ready
  if(myRegions==null) return;

  // set first point to mouse position and recalculate
  points[0][0]=mouseX;
  points[0][1]=mouseY;
  initMesh();
}

Retrieving SMS messages from Processing on Mac

Saturday, May 31st, 2008


Here is a sketch written in Processing that allows you to retrieve in real-time SMS messages from a phone. It uses a MySQL-driven database to store the messages, you’ll need to have one at your disposal (remote or local).

A convenient way to install such a database on your computer is to download and install MAMP, then it’ll be just a matter of drag’n’dropping a folder in your Applications folder, the easy and usual way on Mac.
The package comes also with phpMyAdmin, a popular web-based tool to manage MySQL databases from within your browser.

Softwares/hardwares needed to run this program (assuming you have Processing installed):

  • Mac computer with bluetooth enabled.
  • A mobile phone with bluetooth capabilities (and enabled).
  • Access to a MySQL server. Download and install MAMP if you want to run one on your computer.
  • Cocoa UltraSMS. This software uses bluetooth communication to connect to your phone, and SQL database to save the retrieved messages.
  • MySQL library for Processing by Florian Jenett. The page comes with description to install a MySQL server too.

Here are the few steps to make the program run :

1. Install MySQL and create a database called processingsms.
If you installed MAMP, use phpMyAdmin to perform this operation. This step can be skipped if you have already access to a server.

UltraSMS with MAMP

2. Download and install Cocoa UltraSMS.
Run it and click on the Setup button to modify some parameters. Also, choose your bluetooth-enabled mobile phone in the list.

UltraSMS setup

Note that the screenshot parameters are important and may differ from your MySQL configuration. This paramaters will be used in the Processing sketch to connect to the database :

  • hostname + port. On a default MAMP installation, these are set to 127.0.0.1 and 8889.
  • database. The name of the database that was created in the previous step.
  • username + password. On a default MAMP installation these are both set to root.

3. Click on the Test button to check if UltraSMS can connect to the database. It will also ask you to create two tables (smsins and smsparts), click Ok. The Empty button will remove all the messages already saved.

4. Open Processing IDE, load the ProcessingSMS.pde sketch. In the config tab, change the values of the variables accordingly to your UltraSMS setup.

UltraSMS with Processing Config

5. Click on the Start button of the UltraSMS application. If everything goes well, the status should switch to Connected.
6. Run the program, it should display in the console your sms messages that were inside your phone.
7. Tell a friend to send a message on the connected phone, it should be grabbed and saved in the database !

I recently used this configuration in two installations, one of them being the particles cloud that was shown during the Web Flash Festival.
One of the main drawback I had to face is that the UltraSMS application deconnected when messages were sent massively to the receiving phone. You have then to reconnect manually , which may not be a good thing if this system is to be used in standalone installation. UltraSMS source code is available and there may be a hack to force an automatic reconnection in such situations.
The mobile phone I used for the tests was a Sony Ericsson K600i.

The .zip file containing the Processing sketch also contains a php script to simulate the sending of a SMS into database, which is quite handy when you’re in debugging mode. MAMP is then the tool of choice as it also installs Apache which runs a localhost webserver and lets you execute php scripts.

Any feedback would be very much appreciated. If you have tips, mobile phones that worked / not worked with this configuration, projects using this stuff (or other type of configuration), that would be lovely to share. Thanks!

Director[11] = #@§!

Saturday, May 31st, 2008

Ok, so now I’m really pissed. So I’ve bought the damn upgrade, simply because I have so many old projects languishing on this dying platform. I’ve also been getting email from people because some of these projects are online, and no longer work; and instead of saying, “Macromedia, er Adobe, couldn’t move its sorry ass for over two years to get this software working on your platform,” the alert instead says, “please contact the author,” which in its tone suggests that somehow I’m the one who can’t manage my own projects. Okay, okay, so that’s the way software works, fine. So I get the upgrade, figuring I’ll finally fix these problems.

Five minutes later, this brand-spanking new software has crashed. Hmmm. That sucks. Okay, try again. The damn thing crashes again. Hmmm. Well, apparently, it has something to do with font support; okay, avoid that, try again. “Your application has unexpectedly quit,” and so on for days. Try simple stuff, complicated stuff = crash. Cannot open any significant project from pre-Director 11. I give up. Report bugs. Move on to something else.

So I gave it a few weeks, figuring Adobe would solve the problems that are always hanging around as software goes out the door. I even try copying individual media and scripts by hand, avoiding their “updater” which has now just crashed for the gazillionth time. No luck. Or the thing appears to work for a few seconds, then crashes at some random moment. Try another machine, try a clean install, rinse, lather, repeat…

Finally, I go back to their website. Try the forums, no help there. Try another bug report, probably won’t answer just like a few weeks ago. Try technical support…what!? I have to f@#&§! pay forty dollars just to get help making a supported feature actually work!?

The notion that professional software is somehow more efficient, or (gasp) simply professional, is in the end just a hoax. The illusion that actually having paid for the software will somehow give you some service when it breaks? Yeah, right. To compare real-world experiences: last week I had a bug in OpenFrameworks; I just opened up the code, fixed it, and moved on. I lost maybe a few minutes. Where do I turn when I have a bug in Director? Their website is like a fortress. Oh, sorry, I meant so say a crypt…

Speech representation in Processing II

Saturday, May 31st, 2008
Speech representation in Processing II from Jori de Goede on Vimeo.

Speech representation in Processing. Work in progress for an interactive installation based on para-linguistic elements in a conversation.

Cast: Jori de Goede

KineLib Code Package – Work(bug) in progress

Saturday, May 31st, 2008

Some days ago I decided to start cleaning the codes I’m using the most and to put them inside a library package. I have to say that I’m completly new to public release, and I forgot about using the default java version so everybody could use the library!

For now the package contain two almost working librairies. I will try to debug them and to add more codes soon but for now you should only use SpectrumAnalyzer and EasyControl.

public class NextStep extends Processing{

Saturday, May 31st, 2008
public NextStep (Processing contents) throws OutOfMemoryError {
	Skill skill = contents;translate(skill);
	getMore(skill);
}
public void translate (Skill _skill){
	while(_skill.hasNext()){
		skill += getJava(_skill);
}}
public void getMore(Skill _skill){
	while(getjava.hasNext()){
		skill += getJava(getjava.next());
}}
Skill getjava(Skill research){
return(knowledge)}}

Ogre

Saturday, May 31st, 2008
Well I finally got Ogre to compile. Bugger knows how I’m going to graft Openframeworks libraries into it. I only really need sound and the VideoGrabber, but those are still tall orders.

If you want to play with Ogre on a PC you’ll need the following:

Visual Studio 9. Trying to get it to work with Code Blocks is more trouble than it’s worth, especially as it breaks Openframeworks when you get the bare minimum working. Plus VS9 is pretty damn good. I’m amazed that Microsoft made it.
The Ogre SDK
DirectX Runtime

Then you’ll want to read the following:

Installing the Ogre SDK
Setting up an application. No the Ogre Application Wizard doesn’t work on VS9. This means we have to do some twiddling with project settings to get it to work. But despite this being a pain, it teaches you how to set up projects properly and will help you in the long run.
My thread in the Ogre Forum about trying to get VC9 to compile Ogre. I didn’t quite read the instructions in the previous link thoroughly, but those instructions also assumed some knowledge I didn’t have. Most of the difficulty of getting Ogre to compile is down to correct project settings and correct file placement. So you have to use your initiative a little to figure it out. Now I’m at the following stage:

Ogre Tutorials

I’m going to settle in to this stuff now to put off the nightmare that combining Ogre and Openframeworks will be.

Bruce Sterling on the future of interaction design
Magic Pen
Artificial Stupidity
Fruit Mystery game
Cat with Bow Golf game
Floating Head
The Control Master (a Run Wrake film)
Metal Gear Solid 4 game play demo

C++ optimisation strategies
Processing for Javascript

As a side note I got a new phone recently. So I downloaded the latest Mobile Processing and spent one Sunday writing a new and more clever game of Snake vs the Computer for it. It uses the new A* algorithm I built and shows the Snake’s thoughts about which path to take ahead of it.

Snake AI 2

Weekend Inspiration: Psychedelic Processing Fluids from Memo

Saturday, May 31st, 2008

CDMo reader and 3L winner Memo has posted this rather lovely video.

Interactive Processing version here. Memo says:

This demo was done in Processing 0135 BETA (using Java) but I think I’m going to redo it in C++ with OpenFrameworks for performance reasons. While processing is brilliant for knocking up quick demos and getting off the ground quite quickly, for this project I need as much performance as possible. I.e. the app needs to run across 4 projectors (3000-4000 pixels wide) with loads more features!

So in short I’m halting the development of the Processing / Java version now and thought I’d post where I got to with it…


© Jaymis for Create Digital Motion, 2008. |
Permalink |
3 comments

Add to del.icio.us

Want more on these topics ? Browse the archive of posts filed under News.

Dipole Spin System – Hexagonal Lattice

Saturday, May 31st, 2008
Dipole Spin System – Hexagonal Lattice from evsc on Vimeo.

A hexagonal lattice of magnetic dipoles produces aligned domains along the 3 hexagonal axes (0º, 120º, 240º). Depending on the range of neighboring magnetic fields, those hexagonal axes are separated by smaller or bigger areas of clusters of macro-vortex centers.

http://evsc.net/v6/htm/dipole.htm

Cast: evsc

Dipole Spin System – 25×25 color

Saturday, May 31st, 2008
Dipole Spin System – 25×25 color from evsc on Vimeo.

The video shows a square lattices of 25×25 magnetic dipoles, the coloring of the magnets represents their rotational angle.

http://evsc.net/v6/htm/dipole.htm

Cast: evsc

Dipole Spin System – 100×100

Saturday, May 31st, 2008
Dipole Spin System – 100×100 from evsc on Vimeo.

Larger magnetic dipole lattices contain more vortex centers when they settle down from a random start configuration into their equilibrium configurations. In the video you can see vortex centers colliding and erasing each other.

http://evsc.net/v6/htm/dipole.htm

Cast: evsc

Dipole Spin System – 25×25

Saturday, May 31st, 2008
Dipole Spin System – 25×25 from evsc on Vimeo.

The video shows a square lattice of magnetic dipoles that start from a random configuration and settle down into a micro-vortex pattern. The arrows display the magnetic field acting on the magnets.

http://evsc.net/v6/htm/dipole.htm

Cast: evsc

Dipole Spin System – 10×10

Saturday, May 31st, 2008
Dipole Spin System – 10×10 from evsc on Vimeo.

Square lattices of up to 15×15 magnetic dipoles ultimately end up in a micro-vortex pattern after starting from a random spin configuration.

http://evsc.net/v6/htm/dipole.htm

Cast: evsc

Processing version 138 is now available. Download here. It’s on the road to stability again.

Saturday, May 31st, 2008

Processing version 138 is now available. Download here. It’s on the road to stability again.