[NetBehaviour] Volcano watching

Pall Thayer pallthay at gmail.com
Wed Dec 16 12:44:58 CET 2009


Hi everyone, just wanted to share this with you. Recently a live
webcam was installed to monitor Mt. Hekla, one of Iceland's most
active volcanoes. So of course, I couldn't resist. With the attached
files you can watch a live painting of Mt. Hekla that regenerates
itself in real time. It consists of two files, a perl script and a
processing applet. You need the XML::XPath module for perl as well as
mplayer, Image Magick and autotrace. The sun is just beginning to rise
over the mountain now so it's getting more and more interesting.

Instructions: first run the perl file and then launch the processing applet.

perl script: hekla.pl

#!/usr/bin/perl
use XML::XPath;
use IO::Socket;

$img_count = 1;
$socket = new IO::Socket::INET	(Proto		=> "tcp",
				LocalPort	=> "6666",
				Listen		=> 10,
				Reuse		=> 1,
				) or die "Can't connect! $!";

my $new_sock = $socket->accept();

while(1){
	print "$img_count\n";
	$img_count++;
	`mplayer -nosound -cache 50 -frames 1 -vo png mms://213.167.158.211/hekla/`;
	`convert -resize 800x600 -contrast -contrast -contrast -posterize 8
-blur 5 /home/palli/perltests/00000001.png
/home/palli/perltests/temp.png`;
	`autotrace -color-count 5 -despeckle-level 5 -input-format PNG
-output-file /home/palli/perltests/temp.svg
/home/palli/perltests/temp.png`;

	my $xml = XML::XPath->new(filename => '/home/palli/perltests/temp.svg');

	foreach my $path ($xml->find('//path')->get_nodelist) {
		($color) = $path->find('@style')->string_value =~ /fill:#([a-z 0-9]+)/;
		$shape = $path->find('@d')->string_value;
		$shape =~ s/([MCL])/-$1/g;
		print $new_sock "$shape-$color\n";
		print "$shape-$color\n";
		select(undef, undef, undef, 0.5);
	}
}


processing file:

import processing.net.*;

Client myClient;
String dataIn;
byte interesting = 10;

void setup()
{
  size(800, 600);
  myClient = new Client(this, "127.0.0.1", 6666);
background(#ffffff);
  frameRate(10);

}
void draw()
{
  noStroke();
  try{
    dataIn = null;

    if (myClient.available() > 0) {
      dataIn = myClient.readStringUntil(interesting);
      String dataSplit[] = split(dataIn, '-');
      String myColor = dataSplit[dataSplit.length-1];
      int myR = unhex(myColor.substring(0, 2));
      int myG = unhex(myColor.substring(2, 4));
      int myB = unhex(myColor.substring(4, 6));

      fill(myR, myG, myB);

      smooth();
      beginShape(POLYGON);
      for(int i = 1; i < dataSplit.length-2; i++){
        if(dataSplit[i].charAt(0) == 'C'){
          int dataLength = dataSplit[i].length();
          String useCoords[] = split(dataSplit[i].substring(1,
dataLength), ' ');
          bezierVertex(float(useCoords[0]), float(useCoords[1]),
float(useCoords[2]), float(useCoords[3]), float(useCoords[4]),
float(useCoords[5]));

        }
        else if(dataSplit[i].charAt(0) == 'L'){
          int dataLength = dataSplit[i].length();
          String useCoords[] = split(dataSplit[i].substring(1,
dataLength), ' ');
          vertex(float(useCoords[0]), float(useCoords[1]));
        }
        else if(dataSplit[i].charAt(0) == 'M'){
          endShape();
          beginShape(POLYGON);
          int dataLength = dataSplit[i].length();
          String useCoords[] = split(dataSplit[i].substring(1,
dataLength), ' ');
          vertex(float(useCoords[0]), float(useCoords[1]));
        }
      }
      endShape();
    }
  }
  catch(Exception e){
    //println(e);
  }
}


-- 
*****************************
Pall Thayer
artist
http://www.this.is/pallit
*****************************



More information about the NetBehaviour mailing list