Showing posts with label retroComputing. Show all posts
Showing posts with label retroComputing. Show all posts

17 December 2022

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.

06 March 2022

Pentagram - as an 8-bit scalable vector

When you want to summon a demon, but he demon is fussy about the precision of your pentagram! 😉  Drawing an inverted pentagram on a ZX Sprectrum as a scalable vector 'graphic' using the PLOT and DRAW commands. The idea is to denote the centre of the pentagram / circle as x, y co-ordinates (in pixels) represented with the variables x and y, and the radius (also in pixels) and represented with the variable r. 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.

If x and y are the centre of the cricle, the 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 for a further four times for each side / point of the pentagram. 

Left: The starting point (bottom of pentagram) and fixe x, y co-ordinates for each subsequent line / point of the pentagram. 
Right: The same implemented in BASIC on the ZX Spectrum 128k (Fuse Emulator) 


The additional circle, 1105 CIRCLE x,y,r+(r/6) draws an additional (scalable) circle outside the pentagram with a diameter one sixth longer than the inner circle. The above code, when run will display the pentagram (right) along with the inner and outer circles. The calculations are certainly NOT super accurate, it was worked out with graph paper, a protractor, compass and ruler but it's close enough for the low resolution graphics of an 8-bit computer. Note: negating all the numbers above (with the exception of the starting x co-ordinate) will result in a graphic of a non-inverted pentagram. The basic graphic can be used in other functions, loops etc. to create different effects.




01 March 2022

Dissonance and Resonance

A wave function in nested loops written in BASIC on a Sinclair ZX Spectrum 48k (Fuse Emulator) showing dissonant and resonant sine waves.  


     100 REM listing
     304 LET a=25: LET h=128 : REM harmonic
     400 FOR i = 0 TO 6
     410 GO SUB 510: LET h=h-10
     420 NEXT i: GO TO 1000
     510 FOR x = 0 TO 255
     515 LET y=88+a*SIN(x/h*PI)
     520 PLOT x,y+47
     530 NEXT x: RETURN
    1000 STOP

ASCII

 ASCII on a DOS Command Line 😉😎