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

main.py
import random
import graphics as gr

# define the window
win = gr.GraphWin("Japanese Characters Falling", 500, 500)

# define the list of random characters and positions
chars = ["あ", "い", "う", "え", "お", "か", "き", "く", "け", "こ", "さ", "し", "す", "せ", "そ", "た", "ち", "つ", "て", "と", "な", "に", "ぬ", "ね", "の", "は", "ひ", "ふ", "へ", "ほ", "ま", "み", "む", "め", "も", "や", "ゆ", "よ", "ら", "り", "る", "れ", "ろ", "わ", "を", "ん"]
pos_x = [random.randint(0, 500) for _ in range(50)]
pos_y = [random.randint(-500, 0) for _ in range(50)]

# loop through characters and positions
while True:
    # clear the window
    win.delete("all")
    
    # move characters down the screen
    for i in range(50):
        pos_y[i] += 3
        
        # if the character goes off the screen, reset its position
        if pos_y[i] > 500:
            pos_y[i] = random.randint(-500, 0)
            pos_x[i] = random.randint(0, 500)
            
        # draw the character in green
        char = gr.Text(gr.Point(pos_x[i], pos_y[i]), chars[random.randint(0, len(chars)-1)])
        char.setTextColor("green")
        char.draw(win)
        
    # update the window
    win.update()
1149 chars
33 lines

This code uses the graphics library to create a window and randomly generate and display Japanese characters in green. The position of the characters are updated within a loop to make them fall from the top of the window to the bottom. The loop runs continuously to create an animation effect.

gistlibby LogSnag