如何修复加载栏在结束前停止 [英] How to fix loading bar stopping before the end

查看:38
本文介绍了如何修复加载栏在结束前停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<小时>

注意,帧率可以通过frameRate()一>.

i'm trying to make a loading bar but this is what came up 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()

the loading bar either doesn't go all the way the sleep import is useless in this code if i change the parameters of the if statement in the fill_rect() function the loading bar goes beyond the limit

解决方案

Use min to limit rect_x to the end of the bar:

rect_x = min(200, rect_x + speed_fill)

The bar fills up rapidly. The issue is, that the acceleration is to strong:

speed_fill = speed_fill + 1

Decrease the acceleration (e.g. 0.1):

def fill_rect():
    global fill_r, fill_v, rect_x, speed_fill

    fill(fill_r, fill_v, 0)
    rect(width/2 - 100, height/2 - 12.5, rect_x, 25)

    if rect_x <= 200:
        rect_x = min(200, rect_x + speed_fill)
        speed_fill += 0.1
        fill_r += 5
        fill_v -= 2


Note, the frame rate can be controlled by frameRate().

这篇关于如何修复加载栏在结束前停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆