I guess you made it to difficult...
Variable([
dict(name="progress", ui="Slider",
args=dict(
value=0,
minValue=0,
maxValue=1,
)),
], globals())
backgroundColors = [
(0.5, 1, 0.5),
(0.5, 1, 1),
(0.5, 0, 0),
(1, 1, 0),
(0.5, 0, 1),
(0.5, 0.5, 0.5),
(0, 1, 0)
]
# pageW, pageH = (500, 500)
pageW, pageH = width(), height()
advance = pageW * progress
itemCount = len(backgroundColors)
itemWidth = pageW / (itemCount)
moveIndex = int(advance * progress // itemWidth)
backgroundColors = backgroundColors[-moveIndex:] + backgroundColors
for i in range(0, itemCount + 1):
color = backgroundColors[i]
fill(*color)
rect(itemWidth * (i-moveIndex) - itemWidth + advance * progress, 0, itemWidth, pageH)
fill(None)
stroke(0)
strokeWidth(10)
rect(0, 0, pageW, pageH)