The electron beam moves in horizontal lines backwards and forwards across the sample. Each line is a series of steps.
Depending on the height, and the shape, of the sample at each step we get black, grey or white dots that create the image on the screen.
Black happens when no electrons hit the detector. White is when all the electrons hit the detector. Grey is in between.