How to draw thick lines in Brandy BASIC?

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

How to draw thick lines in Brandy BASIC?

Post by Richard Russell »

I know that Brandy BASIC doesn't support VDU 23,23... to set the thickness of lines, but presumably there must be some way of drawing lines that are more than one pixel thick.

For example one could in principle draw two or more parallel lines so close together that they merge into one thick line, or one might draw a thick line in the form of a long thin rectangle (probably as two triangles).

But neither approach seems particularly straightforward, especially if one wants the line thickness to be substantially independent of its angle. So has somebody already done this and created a general-purpose thick-line drawing routine for Brandy BASIC (or Matrix Brandy BASIC)?
Ric
Posts: 221
Joined: Tue 17 Apr 2018, 21:03

Re: How to draw thick lines in Brandy BASIC?

Post by Ric »

I think multiple lines is the only method that works efficiently, if one uses two triangles a circle needs to be plotted at either end as well if the thick line has that property. Although I guess if the line was thicker than say 10 pixels it may be quicker to plot triangles and circles.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
jgharston
Posts: 50
Joined: Thu 05 Apr 2018, 14:08

Re: How to draw thick lines in Brandy BASIC?

Post by jgharston »

I've usually used code along these lines:

Code: Select all

      DEFPROCdraw(x1,y1,x2,y2,thick):LOCAL n
      IF ABS(x2-x1)<ABS(y2-y1):FOR n=1 TO thick:MOVE x1+n,y1:DRAW x2+n,y2:NEXT:ENDPROC
      FOR n=1 TO thick:MOVE x1,y1+n:DRAW x2,y2+n:NEXT:ENDPROC
with appropriate scaling for the pixel sizes.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: How to draw thick lines in Brandy BASIC?

Post by Richard Russell »

Ric wrote: Thu 11 Sep 2025, 09:47if one uses two triangles a circle needs to be plotted at either end as well if the thick line has that property.
It's only in BB4W that thick lines have 'round' ends (presumably because that's what GDI32 does, by default). In BBCSDL they don't, they have 'flat' ends (similarly because that's what the underlying library, SDL2_gfxPrimitives, does).

So I'm not too concerned about the ends, especially as the 'thick' lines I'm typically wanting to draw are perhaps only 6-8 pixels thick, and the shape of the ends probably won't be apparent unless you look very closely (especially when you consider the effects of aliasing).

Any solution which works in Brandy, and results in the thickness of the line being substantially independent of its angle, is OK by me. But it doesn't look trivial, and I was hoping not to have to write it from scratch (especially as in BB4W and BBCDSL it's done for me).
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: How to draw thick lines in Brandy BASIC?

Post by Richard Russell »

jgharston wrote: Thu 11 Sep 2025, 10:34 I've usually used code along these lines:
OK, thanks, but the results are pretty rough! If you look at the output from this program (admittedly rendered in BBCSDL, not Brandy) the line thickness is uneven, so is the spacing, and the ends are all over the place. In the NE and SW directions something seems to go seriously wrong. I was hoping for something better. :(

Code: Select all

      ORIGIN 640,512
      FOR a = 0 TO 2*PI STEP PI/20
        PROCdraw(0, 0, 400*COS(a), 400*SIN(a), 20)
      NEXT
      END

      DEFPROCdraw(x1,y1,x2,y2,thick):LOCAL n
      IF ABS(x2-x1)<ABS(y2-y1):FOR n=1 TO thick:MOVE x1+n,y1:DRAW x2+n,y2:NEXT:ENDPROC
      FOR n=1 TO thick:MOVE x1,y1+n:DRAW x2,y2+n:NEXT:ENDPROC
thick.png
You do not have the required permissions to view the files attached to this post.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: How to draw thick lines in Brandy BASIC?

Post by Richard Russell »

Richard Russell wrote: Thu 11 Sep 2025, 10:37 I was hoping not to have to write it from scratch (especially as in BB4W and BBCDSL it's done for me).
Once I put my mind to it, the triangle method actually isn't so hard, and works quite well:

Code: Select all

      ORIGIN 640,512
      FOR a = 0 TO 2*PI STEP PI/20
        PROCthick(0, 0, 400*COS(a), 400*SIN(a), 20)
      NEXT
      END

      DEFPROCthick(x1,y1,x2,y2,t) : LOCAL dx,dy,d
      dx = x2-x1 : dy = y2-y1 : d = t*0.5 / SQR(dx*dx+dy*dy) : dx = dx*d : dy = dy*d
      MOVE x1+dy,y1-dx : MOVE x1-dy,y1+dx : PLOT 85,x2+dy,y2-dx : PLOT 85,x2-dy,y2+dx
      ENDPROC
thick.png
You do not have the required permissions to view the files attached to this post.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: How to draw thick lines in Brandy BASIC?

Post by Richard Russell »

Richard Russell wrote: Thu 11 Sep 2025, 11:15 Once I put my mind to it, the triangle method actually isn't so hard, and works quite well:
And in Matrix Brandy BASIC:

brandy.png
You do not have the required permissions to view the files attached to this post.
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: How to draw thick lines in Brandy BASIC?

Post by Richard Russell »

Just to clarify, the thickness is in BASIC graphics units (as it was in Jonathan's code), to change it to pixels - e.g. for compatibility with VDU 23,23... - remove the *0.5 from the calculation:

Code: Select all

      REM Line thickness t in pixels
      DEF PROCthickline(x1,y1,x2,y2,t) : LOCAL dx,dy
      dx = x2-x1 : dy = y2-y1 : t = t / SQR(dx*dx + dy*dy) : dx = dx*t : dy = dy*t
      MOVE x1+dy,y1-dx : MOVE x1-dy,y1+dx : PLOT 85,x2+dy,y2-dx : PLOT 85,x2-dy,y2+dx
      ENDPROC
Richard Russell
Posts: 457
Joined: Tue 18 Jun 2024, 09:32

Re: How to draw thick lines in Brandy BASIC?

Post by Richard Russell »

Even works quite nicely on the BBC Micro (MODE 0, changing ORIGIN 640,512 to VDU 29,640;512;):

beeb.png
You do not have the required permissions to view the files attached to this post.