Demo Code #1 – Vector Graphics
I’m currently working on a vector graphics library; this will eventually include fast implementations of line, circle and triangle rendering. There will be options to render on the standard Spectrum screen (with it’s horrid layout) and to a more sensibly laid out offscreen bitmap. I’m also going to add filled circle and triangle with optional texture shading (an 8×8 graphic).
I’ve just reworked a version of Bresenhams Incremental Line Algorithm in Z80, working in one quadrant. Screenshot attached to wet your appetite.
I’m personally quite excited by this; this line routine is neater than the last version I wrote some years ago. I think experience is slowly paying off!
Update
Finally got around to fixing the vector library routine to draw a line in all quadrants. There is no error checking or clipping yet in the demo application so if you move the cursor off screen you’ll start to see some odd effects.
You can go straight to a demo in the online emulator by clicking here then selecting Vector Demo. Note that you will need to be running the Java plugin to view the demo. The demo starts when you press any key and you can move the second cursor using Q,A,O and P.
I think there are still some optimisations to be had but am happy with the code; you can get to the point where you optimise code for speed but lose clarity. As the point is to give code as examples I’ll leave it up to you to make it fast and obfuscated.