export function render(index) {
v = pixels[index]
v = v*v*v
if (abs(index - leader) < 3) h = 0.66 // blue up front
else if (abs(index - leader) < 10) h = 0.1 // yellow next
else h = 0 // red for the rest
hsv(h, 1, v)
}
This works because abs(index - leader) is how far the current pixel is from the pixel that’s the leader. Notice leader is a decimal and index is whole number. Since the leader can move in either direction, technically the pixels right in front of the leader (the ones who are about to become bright) are also given these special colors, but they probably have faded their v intensity to 0 by that time, so you won’t see those colors unless you also set the fade speed so slow that it starts to “eat it’s own tail”.
If you play with this, just be careful of the ordering of your ifs and else ifs to think through making sure every value of index will set h to something.
To make it white, use my example but set s to 0 instead of changing h to other hues.