Here's an example code that uses the Python graphics library turtle
to create a loop of randomly falling Japanese alphabets:
main.py1034 chars29 lines
This code creates a turtle
object, sets up the screen, defines a list of Japanese alphabets, and enters an infinite while
loop. In each iteration of the loop, a random x-position, a random alphabet, and the starting y-position of the top of the screen are chosen. Then, a turtle
method write()
is called to write the chosen alphabet at the chosen position, using the color green.
After that, another loop is started (for i in range(random.randint(5, 30)):
), which moves the alphabet down the screen by 20 pixels in each iteration, clears the previous position of the alphabet (t.clear()
), and writes the alphabet at the new position using turtle.delay(10)
to pause the animation briefly between each iteration. This loop runs for a random number of iterations between 5 and 30, making each falling animation slightly different. The animation continues indefinitely, with new alphabets falling from the top of the screen each time.
gistlibby LogSnag