Welsh flag

Discussions related to graphics (2D and 3D), animation and games programming
Richard Russell
Posts: 538
Joined: Tue 18 Jun 2024, 09:32

Welsh flag

Post by Richard Russell »

Code: Select all

      REM Welsh Flag by Richard Russell for BBC BASIC (version 5 or later), 26-Dec-2025
      MODE 9 : ORIGIN 240,240 : VDU 23,23,3|
      GCOL 2 : RECTANGLE FILL -100,-60,1000,320
      GCOL 7 : RECTANGLE FILL -100,260,1000,320
      GCOL 0 : MOVE 480,472
      FOR I% = 0 TO 7 : READ a$
        FOR J% = 0 TO 15
          d$ = LEFT$(a$,5) : a$ = MID$(a$,6) : A% = 0
          FOR K% = 0 TO 4
            A% += (ASCMID$(d$,K%+1) - &40) * 60^K%
          NEXT
          DRAW 4*(A% MOD 192), 4*(A% DIV 192 MOD 128) :  A% = A% DIV 24576
          DRAW 4*(A% MOD 192), 4*(A% DIV 192 MOD 128)
        NEXT
      NEXT
      ELLIPSE 180,460,15,12 : ELLIPSE FILL 180,460,10,6
      GCOL 129 : PLOT 143,400,320
      END

      DATA zLbWbY]oa\H^P{YULjzYas[J\I]sT^`O^k^sFceanRBlbYdPPeOA\[gx]@VjNuyfmKhMDkCDhnk[ERxi
      DATA Xp@KihVpVgb@tAgFsgBgWbNye_UVbeCIoOf]FlSgJtqzbhbkVcJFK\`{rsQbidInc@pGMaxSdF\Bs_qX
      DATA {ZMqTeTyORa[^dViRSzZ]KzI]weCO^Zslz^L`dC`xx{R_MsDn\uLlRWCp`ATXnRLRiihsUNpP_Ms^bII
      DATA mKvDLVb^@K_MLqHPrzuEmCPCDvMQ]EjJaRCdZQbB^OS]ACykB@y^j_AlP`[@vTmaAdQeUCPWLBKeBVsH
      DATA tMPiJNADpKqglvL^EUwHlM{\GCdsOEIJgiFFrEJDF^`nC{i{yAZtht@TvV@BDDOb@DYeRAWcflB`GkNH
      DATA ^PfOHLZjeHXMVZJHBPIKmRIoNr^XENSfilMADVBMO`AcGqUhmEyhd@E_QoDFhtKfDQ^oICEoDqBYzRkA
      DATA PnwO@jA_WASxOCAxjf^B{E`HFMmMoI{IITLVdbYMLMijLGJeiP\ksXQ{lydSyj^lX\aZF]FGqx^opYMb
      DATA ol`BdcMU^iNqFl`XYDQ_GiHI^V{SoYzUD[YoZfyWfia@YlPRc[NotBa\{c_fdFUfkDA^IjOjZGjqs^Kk
welshflag.png
You do not have the required permissions to view the files attached to this post.
DDRM
Posts: 25
Joined: Mon 17 Jun 2024, 08:02

Re: Welsh flag

Post by DDRM »

Interesting way of encoding the coordinates - must have taken some working out...

:-)

D
Richard Russell
Posts: 538
Joined: Tue 18 Jun 2024, 09:32

Re: Welsh flag

Post by Richard Russell »

DDRM wrote: Mon 12 Jan 2026, 09:04 Interesting way of encoding the coordinates - must have taken some working out...
Not really, it's simply Base60-encoded - like the more familiar Base64-encoding but using 60 consecutive ASCII characters for ease of decoding.

I started off using a more compact encoding scheme (something like Base90) but decoding it in a simple fashion required 64-bit integers, which was fine for BB4W, BBCSDL and Matrix Brandy but of course wouldn't work on Acorn BASICs. And as the original request for a Welsh flag came from the 'BASIC Programming Language' Facebook Group I didn't want it to be dependent on features not commonly found in other BASICs.

What I sacrificed was the overall size of the flag, which at 500 x 320 pixels (with the dragon being 384 x 256 pixels) doesn't make good use of the window.
Richard Russell
Posts: 538
Joined: Tue 18 Jun 2024, 09:32

Re: Welsh flag

Post by Richard Russell »

I also wrote an anti-aliased version of the Welsh flag program (using the aagfxlib library) but, frankly, there was no significant benefit: the end result was virtually indistinguishable from the native-graphics version listed above. However there were a couple of interesting takeaways:
  • The native graphics version relies on a flood-fill to colour the dragon red, because there is no built-in mechanism for plotting a solid-coloured polygon with an irregular outline. However aagfxlib does have such a function - PROC_aapolygon() - and although there is a limit to the complexity of polygon it can plot, I was pleasantly surprised to find that it did manage to plot the dragon despite its many concave and convex faces:

    Code: Select all

          PROC_aapolygon(256, x(), y(), &FF0000FF)
    
  • The same cannot be said for plotting the black outline, because it proved to be too complex for the PROC_aapolyline() function. However the array slicing feature, added to BBC BASIC last year, proved invaluable for plotting the outline in three segments. Without array slicing this code would have been very messy:

    Code: Select all

          PROC_aapolyline(86, x(  0 TO  85), y(  0 TO  85), 3, &FF000000, 0)
          PROC_aapolyline(86, x( 85 TO 170), y( 85 TO 170), 3, &FF000000, 0)
          PROC_aapolyline(87, x(170 TO 256), y(170 TO 256), 3, &FF000000, 0)
    
DDRM
Posts: 25
Joined: Mon 17 Jun 2024, 08:02

Re: Welsh flag

Post by DDRM »

Richard Russell wrote: Mon 12 Jan 2026, 09:45 What I sacrificed was the overall size of the flag
Can't you simply scale the whole thing up with x and y scale factors (which would probably be the same)? The offsets etc would need recalculating, of course, and you couldn't increase the RESOLUTION of your dragon, but at least you could fill your window.

Best wishes,

D
Richard Russell
Posts: 538
Joined: Tue 18 Jun 2024, 09:32

Re: Welsh flag

Post by Richard Russell »

DDRM wrote: Tue 13 Jan 2026, 13:28 Can't you simply scale the whole thing up with x and y scale factors (which would probably be the same)?
One could, but whenever non-integer scaling factors are involved it risks the introduction of additional aliasing. With my anti-aliased version (using aagfxlib) one could certainly scale the coordinates and fill the window width, sacrificing only resolution as you say. But I wouldn't want to do that with the non-anti-aliased ('pixellated') version that I listed above.
Richard Russell
Posts: 538
Joined: Tue 18 Jun 2024, 09:32

Re: Welsh flag

Post by Richard Russell »

Richard Russell wrote: Tue 13 Jan 2026, 16:38 With my anti-aliased version (using aagfxlib) one could certainly scale the coordinates
Here's a scaled, anti-aliased, version:

Code: Select all

      REM Welsh Flag by Richard Russell for BB4W or BBCSDL (antialiased)
      INSTALL @lib$ + "aagfxlib"
      MODE 9  : ORIGIN 148,184
      GCOL 2  : RECTANGLE FILL -148,-82,1278,410
      GCOL 15 : RECTANGLE FILL -148,328,1278,410
      MOVE 480,472 : DIM x(256), y(256) : P% = 0
      FOR I% = 0 TO 7 : READ a$
        FOR J% = 0 TO 15
          d$ = LEFT$(a$,5) : a$ = MID$(a$,6) : A% = 0
          FOR K% = 0 TO 4
            A% += (ASCMID$(d$,K%+1) - &40) * 60^K%
          NEXT
          x(P%) = 5.12*(A% MOD 192)
          y(P%) = 5.12*(A% DIV 192 MOD 128) : P% += 1 : A% = A% DIV 24576
          x(P%) = 5.12*(A% MOD 192)
          y(P%) = 5.12*(A% DIV 192 MOD 128) : P% += 1
        NEXT
      NEXT : x(P%) = x(0) : y(P%) = y(0)
      PROC_aapolygon(256, x(), y(), &FF0000FF)
      PROC_aapolyline(86, x(  0 TO  85), y(  0 TO  85), 3, &FF000000, 0)
      PROC_aapolyline(86, x( 85 TO 170), y( 85 TO 170), 3, &FF000000, 0)
      PROC_aapolyline(87, x(170 TO 256), y(170 TO 256), 3, &FF000000, 0)
      PROC_aaellipsefill(236, 586, 20, 16, 0, &FF000000)
      PROC_aaellipsefill(236, 586, 18, 14, 0, &FFFFFFFF)
      PROC_aaellipsefill(236, 586, 13,  8, 0, &FF000000)
      END

      DATA zLbWbY]oa\H^P{YULjzYas[J\I]sT^`O^k^sFceanRBlbYdPPeOA\[gx]@VjNuyfmKhMDkCDhnk[ERxi
      DATA Xp@KihVpVgb@tAgFsgBgWbNye_UVbeCIoOf]FlSgJtqzbhbkVcJFK\`{rsQbidInc@pGMaxSdF\Bs_qX
      DATA {ZMqTeTyORa[^dViRSzZ]KzI]weCO^Zslz^L`dC`xx{R_MsDn\uLlRWCp`ATXnRLRiihsUNpP_Ms^bII
      DATA mKvDLVb^@K_MLqHPrzuEmCPCDvMQ]EjJaRCdZQbB^OS]ACykB@y^j_AlP`[@vTmaAdQeUCPWLBKeBVsH
      DATA tMPiJNADpKqglvL^EUwHlM{\GCdsOEIJgiFFrEJDF^`nC{i{yAZtht@TvV@BDDOb@DYeRAWcflB`GkNH
      DATA ^PfOHLZjeHXMVZJHBPIKmRIoNr^XENSfilMADVBMO`AcGqUhmEyhd@E_QoDFhtKfDQ^oICEoDqBYzRkA
      DATA PnwO@jA_WASxOCAxjf^B{E`HFMmMoI{IITLVdbYMLMijLGJeiP\ksXQ{lydSyj^lX\aZF]FGqx^opYMb
      DATA ol`BdcMU^iNqFl`XYDQ_GiHI^V{SoYzUD[YoZfyWfia@YlPRc[NotBa\{c_fdFUfkDA^IjOjZGjqs^Kk
welshflag_antialiased.png
You do not have the required permissions to view the files attached to this post.