l = []
for r in range(256):
for g in range(256):
for b in range(256):
if x < w:
pix[x, y] = (r, g, b)
x += 1
else:
#Don't use this color yet. Creates the diagonal.
l.append((r, g, b))
x = 0
y += 1
#this is the last row of pixels
for i in l:
pix[x, y] = i
x += 1