CLEAR
_TITLE "progbar"
SCREEN _NEWIMAGE(1200, 600, 32)
'_FULLSCREEN _STRETCH


LINE (0, 0)-(1600, 800), _RGB(6, 216, 216), BF



'options of bar type are default, cbar, gbar,lbar,ppie
'options to pass to sub, x,y,width, position, bar type

FOR pd = 0 TO 100
    _DELAY .1
    CALL pbar(20, 20, 100, pd, "default")
    CALL pbar(20, 50, 1000, pd, "cbar")
    CALL pbar(20, 80, 600, pd, "gbar")
    CALL pbar(1000, 110, 1190, pd, "lbar")
    CALL pbar(180, 300, 100, pd, "ppie")
NEXT

END







SUB pbar (h, v, x, c, i$)
    'h is horiz start, v is vertical start, x is horiz end, c is completion %, i is type of bar
    'figure out end of bar complete
    IF c > 100 THEN c = 100
    IF c < 0 THEN c = 0
    c = c / 100 ' so that when c=1 the bar is complete
    cp = (((x - 2) - (h + 3)) * c) + h + 3 'calculate bar fill from percentage
    tp = (((x - h) * .5) + h) - 18 ' find center of bar for percentage text remark
    c = c * 100 ' change c back to a percentage
    c$ = STR$(INT(c)) + "%"
    IF i$ = "default" THEN GOTO d1
    IF i$ = "cbar" THEN GOTO cbar
    IF i$ = "gbar" THEN GOTO gbar
    IF i$ = "lbar" THEN GOTO lbar
    IF i$ = "ppie" THEN GOTO ppie
    GOTO finito

    ' now all the program options to draw different progress bars


    d1:
    LINE (h, v)-(x, v + 15), _RGB(33, 72, 127), BF
    LINE (h + 2, v + 2)-(cp, v + 13), _RGB(222, 222, 94), BF
    _PRINTMODE _KEEPBACKGROUND
    COLOR _RGB(0, 0, 0)
    _PRINTSTRING (tp, v + 1), c$
    GOTO finito
    '--------------------------------------------------------------------------------
    cbar:
    'from green to red progress bar
    LINE (h, v)-(x, v + 15), _RGB(0, 0, 0), BF
    g = 255
    cy = (x - 2) - (h + 2)
    cy = 255 / cy
    FOR bw = (h + 2) TO cp
        r = r + cy
        g = g - cy
        b = 0
        LINE (bw, v + 2)-(bw, v + 13), _RGB(r, g, b)
    NEXT
    _PRINTMODE _KEEPBACKGROUND
    gs = 255
    COLOR _RGB(gs, gs, gs)
    _PRINTSTRING (tp, v + 1), c$
    GOTO finito

    gbar:
    ' indented box with plain blue progress bar
    LINE (h, v)-(x, v + 19), _RGB(128, 128, 128), BF
    LINE (h + 1, v + 1)-(x - 1, v + 1), _RGB(0, 0, 0)
    LINE (h + 1, v + 1)-(h + 1, v + 18), _RGB(0, 0, 0)
    LINE (h + 1, v + 18)-(x - 1, v + 18), _RGB(255, 255, 255)
    LINE (x - 1, v + 18)-(x - 1, v + 1), _RGB(255, 255, 255)
    LINE (h + 2, v + 2)-(cp, v + 17), _RGB(0, 0, 180), BF
    _PRINTMODE _KEEPBACKGROUND
    gs = 255
    COLOR _RGB(gs, gs, gs)
    _PRINTSTRING (tp, v + 3), c$
    GOTO finito

    lbar:
    'weird lazer green bar
    LINE (h, v)-(x, v + 15), _RGB(0, 0, 0), BF
    LINE (h + 1, v + 1)-(x - 1, v + 14), _RGB(83, 255, 0), B
    LINE (h + 2, v + 6)-(cp, v + 9), _RGB(83, 255, 0), BF
    _PRINTMODE _KEEPBACKGROUND
    COLOR _RGB(255, 255, 255)
    _PRINTSTRING (tp, v + 1), c$
    GOTO finito

    ppie:
    CIRCLE (h, v), (x / 2), _RGB(0, 0, 0)
    CIRCLE (h, v), (x / 2) - 1, _RGB(255, 255, 255)
    'pie of completion
    '6.283188 is full radius in radians
    pc = (c * 3.599) 'pc = position in degrees
    pc = 359.9 - pc
    IF pc > 270 THEN pc = pc - 270: ELSE pc = pc + 90
    rr = pc * 0.0174533 ' set position radians
    dp = 90 * 0.0174533 ' set default position degrees

    FOR q = 0 TO x - 4
        CIRCLE (h, v), (q / 2), _RGB(80, 80, 160), rr, dp ' completed pie
        CIRCLE (h, v), (q / 2), _RGB(120, 120, 120), dp, rr 'uncompleted pie

        _PRINTMODE _KEEPBACKGROUND
        _PRINTSTRING (h - 18, v - 7), c$
    NEXT

    finito:
END SUB
