koogy wrote on Jan 28th, 2010, 8:02am:is obviously setup - it's using constant values so they won't change with every frame. make the xreg and reg global (outside setup()) and initialise them inside setup().
haven't run the rest of it (it's not all there!)
Ok, I've sorted out those requests into the setup, I had thought they should be there before, but I'd forgotten to initialise them so I was getting some very nasty errors!
I keep going round in circles here though I think, I want to keep the high framerate, as ideally the images will update/check for updates every 30 secs, but I want to draw the current images into their 3D stack frequently, so I can add some controls for spinning them around/zooming in etc.
This is the code with the requests, so it should work, loading 15 images into a stack, but it only actually redraws the stack once every 30secs. I cant seem to just pick out the 4 lines of 'tint(), image(), fill(), text().
Code:import simpleML.*;
PImage image1;
PImage image2;
ArrayList images;
PFont font;
int startTime;
int zoom;
int imagePositionCount;
int textPositionCount;
int linkPositionCount;
int videoPositionCount;
String authorString;
String pubDateString;
String workTitleString;
String linkString;
String[] authorArray = new String[15];
String[] dateArray = new String[15];
String[] titleArray = new String[15];
String[] imageLinkArray = new String[15];
PImage[] imagesArray = new PImage[15];
String[] typeArray = new String[15];
XMLRequest xreq;
HTMLRequest req;
void setup() {
size(800,400, P3D);
background(0);
xreq = new XMLRequest(this,"http://cagd.leedsmet.ac.uk/feeds/groupWork.php?gid=g3000002");
req = new HTMLRequest(this,"http://cagd.leedsmet.ac.uk/feeds/groupWork.php?gid=g3000002");
req.makeRequest();
xreq.makeRequest();
startTime = millis();
font = createFont("Arial", 15);
textFont(font);
}
void draw(){
int now = millis();//start counter for updates.
if (now - startTime > 30000) { // Every 30 seconds, make a new request
req.makeRequest();
xreq.makeRequest();
println("Updating..");
startTime = now;
println(authorArray[0]+" posted the "+typeArray[0]+" called "+titleArray[0]+" on "+dateArray[0]+", see it here: "+imageLinkArray[0]);
background(0);
pushMatrix();
for(int i=1; i<authorArray.length; i++){
if(typeArray[i] == "image"){
imagePositionCount = imagePositionCount+1;
println(imagePositionCount+"images in top 15");
translate(100, 0, -100);
}else if(typeArray[i] == "text"){
textPositionCount = textPositionCount+1;
translate(100, 0, -100);
}else if(typeArray[i] == "video"){
videoPositionCount = videoPositionCount+1;
translate(100, 0, -100);
}else if(typeArray[i] == "link"){
linkPositionCount = linkPositionCount+1;
translate(100, 0, -100);
}
translate(0, 0, zoom);
if(imageLinkArray[i] != null){
imagesArray[i] = loadImage(imageLinkArray[i], "jpg");
tint(255-(i*15));
image(imagesArray[i], 0, 0, 100, 100);
fill(255);
text(authorArray[i], 10, 0);
}
}
popMatrix();
}
imagePositionCount = 0;
if(mousePressed){
zoom = zoom-1;
println(zoom);
}
}//end of draw.
void netEvent(XMLRequest ml) {
for(int i=0; i<15;i++){
String[] mostRecentAuthorsAll = ml.getElementArray("author");
authorString = mostRecentAuthorsAll[i];
int startAuthor = authorString.indexOf("(");
int endAuthor = authorString.indexOf(")", startAuthor);
String author = authorString.substring(startAuthor+1, endAuthor);
authorArray[i] = author;
String[] mostRecentPostDateAll = ml.getElementArray("pubDate");
pubDateString = mostRecentPostDateAll[i];
int startPubDate = pubDateString.indexOf(",");
int endPubDate = pubDateString.indexOf(":", startPubDate);
String pubDate = pubDateString.substring(startPubDate+2, endPubDate-3);
dateArray[i] = pubDate;
String[] mostRecentPostTitle = ml.getElementArray("title");
titleArray[i] = mostRecentPostTitle[i+2];
}
}
void netEvent(HTMLRequest ml) {// this currently gets 2 results. Need to put this into a loop(?) to get it working for all the items in the feed.
String feedHtml = ml.readRawSource();//gets the html from the feed.
String[] CDATABLOCKS = split(feedHtml, "<item>");//splits the feed into item chunks. - the first chunk is the 'header'.
for(int i=1; i<CDATABLOCKS.length; i++){//I have set i=1 to make it skip past the 'header' in slot[0].
int startGetType = CDATABLOCKS[i].indexOf("posted");
int endGetType = CDATABLOCKS[i].indexOf("<", startGetType);
String typeAll = CDATABLOCKS[i].substring(startGetType+7, endGetType-1);
if((typeAll.length()) == 8){
println("it's an image!");
typeArray[i-1] = "image";
}else if((typeAll.length() == 6)){
println("it's a link!");
typeArray[i-1] = "link";
}else if((typeAll.length() == 14)){
println("it's a moving image");
typeArray[i-1] = "video";
}else if((typeAll.length() == 15) || (typeAll.length() == 14)){
println("it must be a bit of text?..");
typeArray[i-1] = "text";
}
int startGetCDATA = CDATABLOCKS[i].indexOf("CDATA[");
int endGetCDATA = CDATABLOCKS[i].indexOf("]]",startGetCDATA);
String CDATA = CDATABLOCKS[i].substring(startGetCDATA, endGetCDATA);
int startGetLink = CDATA.indexOf("=");
int endGetLink = CDATA.indexOf(">", startGetLink);
String gotLink = CDATA.substring(startGetLink+2, endGetLink-1);
if(gotLink.indexOf("h") == 0){
imageLinkArray[i-1] = gotLink;
}
else{
imageLinkArray[i-1] = null;
}
}
}