9-10XIST
Roller Text
// An array of news headlines
String[] headlines = {
"COVID-19",
"wash your hands,",
"sanitise,",
"practice social distancing,",
"and stay safe :)",
};
PFont f; // Global font variable -
float x; // horizontal location of headline
PGraphics pg;
int index = 0;
void setup() {
size(400,400);
f = createFont("Georgia",26,true);
x = width; // Initialize headline offscreen to the right
}
void draw() {
background(#F36153);
fill(212, 197, 199);
// Display headline at x location
textFont(f,25);
textAlign(LEFT);
text(headlines[index],x,180);
x = x - 5; // speed of scrolling text
// If x is less than the negative width,
// then it is off the screen
float w = textWidth(headlines[index]);
if (x < -w) {
x = width;
index = (index + 1) % headlines.length; // % it returns the remainder of a division into index
}
}
Code
Video Demonstration
This code is supposed to act as an array of news headlines. The text moves from the right offscreen to the left in a loop. It mirrors the headlines that are shown on the news. Because this code was supposed to mirror news headlines, I decided on texts that are similar to those shown on the news right now. News about COVID-19. I changed the text so it would say, “COVID-19, wash your hands, sanitise, practice social distancing and stay safe :)” But the text I chose felt more like a message rather than a news headline. So instead of having the texts move at the bottom of the screen, I moved it to the middle. From there I changed the speed that the text was scrolling at so it would be slower and therefore easier to read. I changed the background to a reddish-pink colour to show the urgency of following these rules. The colour of the background is declared with Hexadecimals while the colour of the text is in RGB. This shows that both Hexidecimals and RGB can be used in Processing. I changed the font so that the message would come across as more formal by using the font “Georgia”. This exercise uses functions such as string, textAlign() and textFont().
(click the functions underlined to learn more about them)