Отображаемый экран обновляется в конце функции draw()
.Таким образом, ваш цикл while полностью выполнен и отображается завершенный текст.Вам нужно будет изменить код так, чтобы он постоянно обновлял / перерисовывал экран и обновлял отображаемый текст на основе временной петли.
Например, например:
int currentTime;
int waitTime = 500;
int characters_to_display = 0;
boolean stringComplete = false;
String textInput = "Hello";
void setup() {
size(500, 500);
currentTime = millis();
}
void draw() {
// Update text to be shown. increaseCharIndex() is called while the text is not yet fully displayed
if (stringComplete == false) {
increaseCharIndex();
}
//Draw screen:
// draw background to clear screen
background(0);
// display (a substring of) the text
text(textInput.substring(0, characters_to_display), 10, 100);
}
void increaseCharIndex() {
// if the waitperiod has passed, increase the number of characters to be displayed
if (millis() - currentTime>waitTime) {
currentTime = millis();
characters_to_display++;
}
// if the full text will be shown, end the call to increaseCharIndex()
if (characters_to_display >= textInput.length())
{
stringComplete = true;
}
}
![enter image description here](https://i.stack.imgur.com/uLVR2.gif)