We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Concurrent Operations
Page Index Toggle Pages: 1
Concurrent Operations (Read 555 times)
Concurrent Operations
Feb 9th, 2007, 8:53pm
 
Heya, here's a simple app that first loads some profile pics from myspace, and then moves them across the screen, changing them every second.

I know, pointless now, used this to learn a little about the proHTML library for another project.  

My problem however is that it takes quite a while to laod the pics upfront before getting to the draw loop.  Any suggestions on how I could start drawing and grabbing the pics concurrently, to rid the long lead time?

Code:

import prohtml.*;

HtmlImageFinder htmlImageFinder;
PImage[] pics;
int i=0;
int frame=0;

void setup() {
String[] profiles;
size(600,600);
background(0);
frameRate(60);
pics = new PImage[6];
profiles = new String[5];
profiles[0] = "http://www.myspace.com/blahblah0";
profiles[1] = "http://www.myspace.com/blahblah1";
profiles[2] = "http://www.myspace.com/blahblah2";
profiles[3] = "http://www.myspace.com/blahblah3";
profiles[4] = "http://www.myspace.com/blahblah4";


//load pic array with profile pics
for (int c=0; c<5; c++) {
pics[c] = getProfilePic(profiles[c],c);
}
}

PImage getProfilePic(String url, int c) {
PImage pic;
htmlImageFinder = new HtmlImageFinder(url);
pic = loadImage(htmlImageFinder.getImageLink(1));
return pic;
}

void draw() {
background(0);

image(pics[i], frame*2, 10);
if(frameCount % 60 == 0) i++;
frame++;
}


Also, seeing as this is my first Processing app.. any glaring flaws or bad habits in the way I wrote this?

Many thanks!
Re: Concurrent Operations
Reply #1 - Feb 9th, 2007, 10:44pm
 
You could use a new thread. Take a look at this example which is loading images from flickr in an applet:http://www.eskimoblood.de/applets/applet25/applet25.pde
Re: Concurrent Operations
Reply #2 - Feb 9th, 2007, 10:52pm
 
Exactly what I was looking for, thanks!

The other option, for me at least, is to do do some screen scraping with ruby and store it off somewhere, but I really like the proHTML library, which makes me want to do it all in Processing.

Thanks again!
Page Index Toggle Pages: 1