Hello.
I have 2 sketches, the first of which grabs some text from a website. At present I just have a printIn command to check that it's grabbing the right bit (which it is). I want to take the text that this sketch grabs and get it to go into a rolling headline.
I have a second sketch taken from a rolling headline tutorial, and am trying to work out how to get the text from the printIn command to go into the rolling headline text (and from there for it to check and replace every once in a while if the text from the website changes).
Can someone point me in the right direction as to how to do this? Thanks
LP.
The http request code is pasted first:
import http.requests.*;
public void setup()
{
size(400,400);
smooth();
GetRequest get = new GetRequest("https://www.mi5.gov.uk/UKThreatLevel/UKThreatLevel.xml");
get.send();
//println("Reponse Content: " + get.getContent());
//println("Reponse Content-Length Header: " + get.getHeader("Content-Length"));
///return the contents of the HTTP request
String content = get.getContent();
//turn itinto HTML
XML rss = parseXML(content);
///get the main chunk of xml inside the parent rss
XML channel = rss.getChild("channel");
//inside this is a child element called 'title'
XML item = channel.getChild("item/title");
//you need what's inside this element i.e. ignore the tags, get the stuff inside
String itemContent = item.getContent();
//how do I get the text printed out into the second sketch?
println("", itemContent);
}
This is the rolling headline sketch code:
int blinkTime;
boolean blinkOn;
PImage bgImg; // Declare variable PImage bgImg related to the field
PGraphics img;
//For now some news headlines, it's here where I want to place the text retrieved from the first sketch
String[] headlines = {
"fact plus importance equals news",
"speed plus repetition equals fear",
"percentage minus context equals terror",
"it's here where I want to place the text retrieved from the first sketch",
};
PFont f; // Global font variable
float x; // Horizontal location
int index = 0;
PFont l; // STEP 1 Declare PFont variable
void setup() {
size(600, 399); // make the size same as photo
bgImg = loadImage("fieldnpole.jpg"); // load the image inside setup
f = createFont( "HelveticaNeue-Bold", 20);
// Initialize headline offscreen
x = width;
}
{
blinkTime = millis();
blinkOn = true;
}
void draw() {
background(bgImg);
fill(#FF0303);
noStroke();
if (blinkOn)
ellipse(550,30,20,20);
fill(#FF0303);
noStroke();
if (millis() - 500 > blinkTime) {
blinkTime = millis();
blinkOn = !blinkOn;
}
fill(255,0,0.50);
rect(0,340,600,80);
// Display headline at x location
textFont(f, 20);
textAlign (LEFT);
fill(255);
// A specific String from the array is displayed according to the value of the "index" variable.
text(headlines[index], x, height-20);
// Decrement x
x = x - 3;
// If x is less than the negative width, then it is off the screen
// textWidth() is used to calculate the width of the current String.
float w = textWidth(headlines[index]);
if (x < -w) {
x = width;
// index is incremented when the current String has left the screen in order to display a new String.
index = (index + 1) % headlines.length;
}
{
l = createFont("HelveticaNeue-Bold",10,true); // STEP 2 Create Font
textFont(l,10); // STEP 3 Specify font to be used
fill(0); // STEP 4 Specify font color
text("LIVE",510,35); // STEP 5 Display Text
}
}