Hello everyone, I’m a school-level beginner programmer and I’m trying to display text letter by letter. There is something that I don’t understand about my code, because it works perfectly on a console but just doesn’t update the display window until the function is finished. I was wondering if there is a way to force the update or if maybe there could be a better script for this (of those that I could understand).
Thank you very much!
Processing uses the
draw() function to draw to the display window. You should adapt your code to work with this structure.
# this code executes once at the start
# this code executes every frame
text('Hello, World', 65, 105)
Welcome to the Processing Community, @Polo!
textAnimated function contains this conditional block:
Therefore, the function calls itself. Are you intentionally writing the function as a recursion?
EDITED 2x on July 7, 2021 to add the following:
To follow @tabreturn’s advice, you can add this prior to your function definition:
toTypeR = ""
t = 0
textAnimated("This is the text!", 0, 20, True)
You may see the entire text appear all at once, which does not seem to be what you wanted.
Fitting the recursion into the code structure of a Processing sketch to implement an animation can be tricky. You may benefit from reading the following discussion thread for guidance:
Is my fractal optimized? Could it animate?
Though it focuses on Java Mode, it does include a Python Mode example.
Also see Tower Hanoi - Why recursive draw only first and last steps?.
Thank you very much, I’ll try that. I was simply wondering if it was possible to write such a function outside of draw.