Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 prefered).

(Read the definition of PPM file on Wikipedia.)




-- demo\rosetta\Bitmap_write_ppm.exw
constant dimx = 512, dimy = 512
constant fn = open("first.ppm","wb") -- b - binary mode
sequence color
printf(fn, "P6\n%d %d\n255\n", {dimx,dimy})
for y=0 to dimy-1 do
    for x=0 to dimx-1 do
        color = {remainder(x,256),   -- red
                 remainder(y,256),   -- green
                 remainder(x*y,256)} -- blue
        puts(fn,color)
    end for
end for
close(fn)