First you need to create some buffer that represents your screen and then some functions to draw what you want on that buffer. Then you make all your calculations and draw on buffer. After that write your buffer to file in the .bmp format. Repeat the calculate - draw - write-bmp sequence as needed.
See some information on bmp format
here.