I took a break today to play with Microsoft Excel. I have been learning graphics programming (very rudimentary stuff here because I have never done anything in this area). I wanted learn the mathematics behind it all instead of focusing on a graphics technology or platform....you know, like what does a circle-drawing algorithm look like in the raw?
I decided to try something kind of silly but fun. A spreadsheet can be thought of as a Cartesian plane so why not configure an Excel worksheet to act as a very rudimentary pixel display?
The image below is of a worksheet with 256 columns and rows, with most of the other UI stripped away.
Now with a simple LOGO-like (or should I say turtle graphics) syntax, I can specify some operations and data:
The Action maps to an Enum with Draw, Erase, Pause, Resume, Goto, and End as its members. Type is for drawing shapes and is mapped to another Enum called Shape with Pixel, Line, Rectangle, Circle, and Brush as its members. Depending on the Actions and the Type, the Data column contains directions to the graphics engine about the shape to render.
The data above says something like this
- Draw a black circle at 65 and 120 with radius 10
- Pause for 50 ms
- Erase #1
- Draw a black circle at 70 and 125 with radius 10
- Pause for 50 ms
- Erase #4
- Draw and erase at various spots to animate the circle until Row # 35
- Goto #1 and repeat three times
- Draw a red rectangle at 6 and 64 with height and width = 128
Okay, so at 256x256 resolution, it is a grainy and jumpy but I wanted to look at the math behind all of this. Remember, this is in Excel so I am using VBA for all of this. Here is the code to draw a single pixel in our display:
Here is the code to draw our circle (two functions):
Unfortunately, my first implementation didn't work at all because Excel wouldn't update the display while this was happening, even with using Good Old DoEvents and setting ScreenUpdating = true. So, I found this:
Fun! Back to work...