Generating a gradient image
Generate an image of width W and height H where every pixel's intensity depends only on its column x, ramping linearly from 0 at the left edge to 255 at the right edge, identically across all three channels so the gradient reads as grayscale first:
function generate_gradient(width, height):
image = allocate width * height * 3 bytes
for y from 0 to height - 1:
for x from 0 to width - 1:
value = round(x * 255 / (width - 1))
offset = (y * width + x) * 3
image[offset + 0] = value # R
image[offset + 1] = value # G
image[offset + 2] = value # B
return image