27 lines
516 B
Plaintext
27 lines
516 B
Plaintext
String txt = "Hello, world! ";
|
|
boolean dir = true;
|
|
|
|
void draw(){
|
|
background(128);
|
|
text(txt, 10, height/2);
|
|
if(frameCount%10==0){
|
|
if(dir) {
|
|
txt = rotate(txt, 1);
|
|
} else {
|
|
txt = rotate(txt, txt.length()-1);
|
|
}
|
|
}
|
|
}
|
|
|
|
void mouseReleased(){
|
|
dir = !dir;
|
|
}
|
|
|
|
String rotate(String text, int startIdx) {
|
|
char[] rotated = new char[text.length()];
|
|
for (int i = 0; i < text.length(); i++) {
|
|
rotated[i] = text.charAt((i + startIdx) % text.length());
|
|
}
|
|
return String.valueOf(rotated);
|
|
}
|