如何防止Python中的文本重叠?

问题描述 投票:0回答:1

我希望将文本大小从 250 缩小到 150,而没有任何其他文本重叠,这是我的代码(不介意其余功能):

text_size = 250

    
global sound_clip

def setup():
    size (1000, 700)
    Menu_screen()
    
def title():
    global text_size
    if text_size > 150:
        text_size = max(text_size - 0.5, 150)
        font = createFont("Impostograph-Regular.otf", text_size)
        print(text_size)
        textAlign(CENTER, CENTER)
        textFont(font)
        text("Rings of the Sun", width/2, height/2)

def Menu_screen():
    img = loadImage("outer_space.png")
    image(img, 0, 0)
    
def draw():
    title()
    return

尝试使用 while 循环,但仍然相同,我不知道如何为文本设置动画

python text processing
1个回答
0
投票

以下源代码将在没有“重叠”的情况下对 python 文本进行动画处理。如果将背景(209)添加到draw()中,它将在绘制新文本之前“擦除”旧文本。我使用了我的系统上可用的不同字体。由于图像不可用,该演示也不使用菜单屏幕。

text_size = 250 
    
def title():
    global text_size
    if text_size > 90:
        text_size = max(text_size - 0.5, 90)
        #font = createFont("Inconsolata-Regular.otf", text_size)
        font = createFont("Arial", text_size)
        print(text_size)
        textAlign(CENTER, CENTER)
        textFont(font)
        text("Rings of the Sun", width/2, height/2)
        
def setup():
    size (1000, 700)
  
def draw():
    background(209)
    title() 
    return

© www.soinside.com 2019 - 2024. All rights reserved.