random green japanese alphabet falling from top to bottom in a loop in python

Here's an example code that uses the Python graphics library turtle to create a loop of randomly falling Japanese alphabets:

main.py
import turtle
import random

# create a list of Japanese alphabets
japanese_alphabets = ["あ", "い", "う", "え", "お", "か", "き", "く", "け", "こ", "さ", "し", "す", "せ", "そ",
                      "た", "ち", "つ", "て", "と", "な", "に", "ぬ", "ね", "の", "は", "ひ", "ふ", "へ", "ほ",
                      "ま", "み", "む", "め", "も", "や", "ゆ", "よ", "ら", "り", "る", "れ", "ろ", "わ", "を", "ん"]

t = turtle.Turtle()
t.hideturtle()
t.penup()
t.speed(0)
turtle.bgcolor("black")  # change the background color to black

while True:
    x = random.randint(-turtle.window_width()//2, turtle.window_width()//2)
    y = turtle.window_height()//2
    alphabet = random.choice(japanese_alphabets)
    t.setpos(x, y)
    t.color("green")
    t.write(alphabet, align="center", font=("Arial", 16, "normal"))
    for i in range(random.randint(5, 30)):
        t.clear()
        y -= 20  # move the alphabet down
        t.setpos(x, y)
        t.color("green")
        t.write(alphabet, align="center", font=("Arial", 16, "normal"))
        turtle.delay(10)  # pause for a moment
1034 chars
29 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