I think the readability of the code can be improved through the proper use of const and let. Especially const will make it clear which variables are immutable.
In case you didn't know (it's a bit hard to find), you can manually set the preview image for your notebook. In the notebook overview you have to find the context menu (the three dots below the preview image on the right, next to notebook title), then it should be one of the options. Might be nicer to show one of the later images in your notebook instead of this random noise
This function does not correctly average the pixel data. Higher sample values passed to the function make things dark.
The calculatePixel function should be passed [0,0,0] in place of accum and
putPixel should be moved after the "for s" block and use accum instead of res.