10 August 2022

Pentagram - as an 8-bit scalable vector (again)

Just recently revisited my previous attempt at creating a scalable vector graphic of an inverted pentagram on a ZX Spectrum (Fuse Emulator) as I  since made a QB64 HD version - you know, one that runs on regular computers :) Porting the original code to QB64 wasn't too straightforward as the way lines are drawn in each language is fundamentally different. Anyway, I still like the original code and learned a lot from it. See the original post here

x and y represent the centre of the cricle, the first starting point, i.e., the bottom point of the pentagram can be stated as x, y-r, this is the first point to be PLOTted. Each subsequent move along the x axis (minus for left, plus for right) and y axis (minus for down, plus for up) can be measured and then shown by its relationship to the length of the radius (i.e., the number it is either multiplied or divided by to be the same as the radius). This will result in scaling the lateral and vertical DRAW x,y points along with the radius.

If we take the radius to be 50px, then the first movement is 29px left and 90px up. Therefore;

-29/r => -29/50 = -0.58 => -0.58r
90/r => 90/50 = 0.555' => r/0.555'

So the first DRAWn x, y co-ordinates are;  -0.58r, r/0.555' ... The same method is then repeated a further four times to draw the line for each side of the pentagram. 



This results in the following set of vectors and can be implemented in BASIC with the code below (written for ZX Spectrum 128k on Fuse emulator);

x, y-r
-0.58r, r/0.555'
1.53r, -1.08/r
-1.88r, 0
1.53r, 1.08r
-0.58r, -(r/0.555')

Changing the x, y starting position and/or the radius (r) will redraw the pentagram according to the new values. To do this, each point on the pentagram, and hence each line can be represented as vectors.