CODE 5
String[] headlines = {
"Hi, My name is Khoo Yan Xuan OwO"
};
PFont f ;
float x;
int index = 0;
void setup() {
size(800,800);
f = createFont("sentyWen",50,true);
x = width;
}
void draw() {
background(123,456,234);
fill(0);
textFont(f,50);
textAlign(CENTER,BOTTOM);
text(headlines[index],x,160);
x = x - 6;
float w = textWidth(headlines[index]);
if (x < -w) {
x = width;
index = (index + 8) % headlines.length;
}
}
CODE 5
Original Code
String[] headlines = {
"Hello World",
};
PFont f; // Global font variable -
float x; // horizontal location of headline
int index = 0;
void setup() {
size(400,200);
f = createFont("Arial",16,true); //load Arial font into f
// Initialize headline offscreen to the right
x = width;
}
void draw() {
background(255);
fill(0);
// Display headline at x location
textFont(f,16);
textAlign(LEFT);
text(headlines[index],x,180);
// Decrement x- this marks the speed of the scrolling text
x = x - 3;
// 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
}
}
Original Code
Modifications
1) Change of the phrase:
String[] headlines = {
"Hello World",
};
to
String[] headlines = { "Hi, My name is Khoo Yan Xuan OwO" };
2) Screen Size and Font:
size(400,200);
f = createFont("Arial",16,true);
to
size(800,800);
f = createFont("sentyWen",50,true);
3) Background Colour:
void draw() {
background(255);
fill(0);
to
void draw() { background(123,456,234); fill(0);
4) Text Alignment and Text Location:
textFont(f,16);
textAlign(LEFT);
text(headlines[index],x,180);
to
textFont(f,50);
textAlign(CENTER,BOTTOM); text(headlines[index],x,160);
EXPLANATION
This code shows a moving sentence that go across the screen over and over again. The first two lines of the code introduce the sentence that will be used later in the code. The whole sentence "Hi, My name is Khoo Yan Xuan OwO" will be introduced as 'headlines' later in the code.
textFont(f,50);
textAlign(CENTER, BOTTOM);
text(headlines[index],x,160);
This part states the font of the sentence and also determines the location of the sentence. The headlines of this code are positioned on top of the display screen and the font size is 50.
x = x - 6;
This part of the code decides the speed of the headlines and how fast the headlines it will move across the screen. The bigger the value x subtracts, the slower the headlines moves and vice versa.