//attention to distinguish: active/static variable.acitive should put into the void draw(),static is outside.
int n = 0;
int n_1 = 0;
int c;
int c_1;
//PFont f; // Global font variable
PFont g;
int v; // Horizontal location
int v_1;
String firstText = "";
String nextText = "";
void setup()
{
size(1300,400);
//f = createFont( "Arial" ,100,true);
g = createFont( "SIMKAI.TTF" ,100,true);
textFont(g,100);
}
void draw() {
background(25,25,112);//blue
textAlign (LEFT,CENTER);//LEFT,RIGHT,CENTER,TOP,BOTTOM
String book[] = loadStrings("book_2.txt");
String book_up[] = loadStrings("book_1.txt");
firstText = book_up[n];
nextText = book[n_1];
//1st row
fill(200,200,0);//yellow
textFont(g,100);
text(firstText,0 - v,100);
//2nd row
fill(255,64,64);//red
textFont(g,100);
text(nextText,0 - v_1,300);
//
if(v == 0)
{
if(c == 250){c = 0;v = v + 3;} //stop for 3 seconds.
else{c = c + 1;};
}
else{v = v + 3;};
// textWidth() is used to calculate the width of the current String.
if(v_1 == 0)
{
if(c_1 == 250){c_1 = 0;v_1 = v_1 + 3;} //stop for 3 seconds.
else{c_1 = c_1 + 1;};
}
else{v_1 = v_1 + 3;};
float w = textWidth(firstText);
float w_1 = textWidth(nextText);
//repeat and paragraph control
if (v > w)
{
v = 0;
if(n == book_up.length-1){n = 0;}
else{n++;}
}
if (v_1 > w_1)
{
v_1 = 0;
if(n_1 == book.length-1){n_1 = 0;}
else{n_1++;}
}
}
int n = 0;
int n_1 = 0;
int c;
int c_1;
//PFont f; // Global font variable
PFont g;
int v; // Horizontal location
int v_1;
String firstText = "";
String nextText = "";
void setup()
{
size(1300,400);
//f = createFont( "Arial" ,100,true);
g = createFont( "SIMKAI.TTF" ,100,true);
textFont(g,100);
}
void draw() {
background(25,25,112);//blue
textAlign (LEFT,CENTER);//LEFT,RIGHT,CENTER,TOP,BOTTOM
String book[] = loadStrings("book_2.txt");
String book_up[] = loadStrings("book_1.txt");
firstText = book_up[n];
nextText = book[n_1];
//1st row
fill(200,200,0);//yellow
textFont(g,100);
text(firstText,0 - v,100);
//2nd row
fill(255,64,64);//red
textFont(g,100);
text(nextText,0 - v_1,300);
//
if(v == 0)
{
if(c == 250){c = 0;v = v + 3;} //stop for 3 seconds.
else{c = c + 1;};
}
else{v = v + 3;};
// textWidth() is used to calculate the width of the current String.
if(v_1 == 0)
{
if(c_1 == 250){c_1 = 0;v_1 = v_1 + 3;} //stop for 3 seconds.
else{c_1 = c_1 + 1;};
}
else{v_1 = v_1 + 3;};
float w = textWidth(firstText);
float w_1 = textWidth(nextText);
//repeat and paragraph control
if (v > w)
{
v = 0;
if(n == book_up.length-1){n = 0;}
else{n++;}
}
if (v_1 > w_1)
{
v_1 = 0;
if(n_1 == book.length-1){n_1 = 0;}
else{n_1++;}
}
}