Processing Forum
PImage jorden;
import simpleML.*;
int e = 0;
ArrayList kometer = new ArrayList();
int x = 0;
int y = 0;
int douche = 0;
XMLRequest xmlRequest;
int startTime; // for the timer to make request ever N seconds
String html = ""; // String to hold data from request
void setup() {
// Creating and starting the request
xmlRequest = new XMLRequest(this, "http://search.twitter.com/search.rss?q=end");
xmlRequest.makeRequest();
size(height = 1000, width = 500);
ellipse(503, 245, 125, 125);
}
void draw() {
background(0);
// Every 5 seconds, make a new request
int now = millis();
if (now - startTime > 2000) {
xmlRequest.makeRequest();
println("Making request!");
startTime = now;
}
jorden = loadImage("earth.jpg"); //Bilden
imageMode(CENTER);
image(jorden, 500, 250);
for (int i = 0; i < kometer.size(); i++) {
komet k = (komet)kometer.get(i);
k.smart();
}
}
// When the request is complete
void netEvent(XMLRequest ml) {
// Retrieving an array of all XML elements inside "<title*>" tags
String[] headlines = ml.getElementArray("title");
for (int i = 0; i < headlines.length; i++) {
// println(headlines[i]);
}
for (String html: headlines) {
if (html.toLowerCase().contains("2012")) {
douche++;
println(douche);
kometer.add( new komet(random(0, width), random(0, height)));
}
}
}
///////////////////////////////CLASS KOMET/////////////////////////////////////
class komet{
float x = 0;
float y = 0;
int komet1 = 10;
int komet2 = 1;
komet(float _x, float _y){
x = _x;
y = _y;
}
void movement(){
x +=komet1;
y +=komet2;
}
void kometer(){
ellipse(x,y,25,25);
}
void smart(){
movement();
kometer();
}
}
|