如何修复加载栏在结束前停止

我正在尝试制作一个加载栏,但这就是出现的问题 HELP MEE

from time import sleep

def fill_rect():

    global fill_r

    global fill_v

    global rect_x

    global speed_fill

    fill(fill_r,fill_v,0)

    rect(width/2 - 100, height/2 - 12.5,rect_x,25)

    if rect_x <= 200 - speed_fill :

        rect_x = rect_x + speed_fill

        fill_r = fill_r + 5

        fill_v = fill_v -2

        speed_fill = speed_fill + 1



def setup():

    global fill_r

    global fill_v

    global rect_x

    global speed_fill

    background(0,100,255)

    size(500,500)

    speed_fill = 1

    fill(0)

    rect(width/2 - 100, height/2 - 12.5,200,25)

    rect_x = 1

    fill_r = 25

    fill_v = 100


def draw():

    global fill_r

    global fill_v

    global rect_x

    fill_rect()

加载条要么没有走到底,睡眠导入在这段代码中没有用,如果我在 fill_rect() 函数中更改 if 语句的参数加载条超出限制


皈依舞
浏览 120回答 2
2回答

牧羊人nacy

用于min限制rect_x到小节的末尾:rect_x&nbsp;=&nbsp;min(200,&nbsp;rect_x&nbsp;+&nbsp;speed_fill)酒吧迅速填满。问题是,加速度太强了:speed_fill&nbsp;=&nbsp;speed_fill&nbsp;+&nbsp;1降低加速度(例如 0.1):def fill_rect():&nbsp; &nbsp; global fill_r, fill_v, rect_x, speed_fill&nbsp; &nbsp; fill(fill_r, fill_v, 0)&nbsp; &nbsp; rect(width/2 - 100, height/2 - 12.5, rect_x, 25)&nbsp; &nbsp; if rect_x <= 200:&nbsp; &nbsp; &nbsp; &nbsp; rect_x = min(200, rect_x + speed_fill)&nbsp; &nbsp; &nbsp; &nbsp; speed_fill += 0.1&nbsp; &nbsp; &nbsp; &nbsp; fill_r += 5&nbsp; &nbsp; &nbsp; &nbsp; fill_v -= 2https://i.stack.imgur.com/9CgFR.gif

慕少森

我找到了一种方法让它以任何加速度停在矩形的末端def fill_rect():&nbsp; &nbsp; global fill_r&nbsp; &nbsp; global fill_v&nbsp; &nbsp; global rect_x&nbsp; &nbsp; global speed_fill&nbsp; &nbsp; fill(fill_r,fill_v,0)&nbsp; &nbsp; rect(width/2 - 100, height/2 - 12.5,rect_x,25)&nbsp; &nbsp; if rect_x <= 200&nbsp; &nbsp;:&nbsp; &nbsp; &nbsp; &nbsp; if rect_x > 200 - speed_fill:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rect_x = 200 - speed_fill&nbsp; &nbsp; &nbsp; &nbsp; rect_x = rect_x + speed_fill&nbsp; &nbsp; &nbsp; &nbsp; fill_r = fill_r + 5&nbsp; &nbsp; &nbsp; &nbsp; fill_v = fill_v - 2&nbsp; &nbsp; &nbsp; &nbsp; speed_fill = speed_fill + 1
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python