#### Output to svg file

D.W. Burger

Hi, All,

I'm trying to use some published programs written in B.B.C. that create curve-stitch images like this one:

A book entitled "Curve Stitching" by Jon Millington, written in 1989, contains several B.B.C. programs that will draw these kinds of images on the screen.  Here's the program that drew the image above:

0 REM Parabolas - Polygon
10 INPUT'"How many sides? "V
20 INPUT'"And setps per side? "N
30 MODE 1
40 FOR B=0 TO 6.28 STEP 2*PI/V
50   G=B+2*PI/V
60   T=B+4*PI/V
70   FOR H=500/N TO 501 STEP 500/N
80     P=(500-H)*SIN B+H*SIN G+640
90     Q=(500-H)*COS B+H*COS G+500
100     X=(500-H)*SIN G+H*SIN T+640
110     Y=(500-H)*COS G+H*COS T+500
120     MOVE P,Q
130     DRAW X,Y
140   NEXT H,B

I've downloaded the trial version of BB4W and I can run the program so this image is displayed on the screen.  However, what I need is that image saved in SVG (or some other vector) format.  Will I be able to get this done with BB4W?  If so, can anyone point me in the right direction?  Thanks!

Dave Burger
dwburger@...

Richard Russell

On Sun, Jan 20, 2019 at 09:54 AM, D.W. Burger wrote:
However, what I need is that image saved in SVG (or some other vector) format.
Using BBC BASIC for Windows (trial or full versions) there are two "vector graphics formats" that you can relatively easily generate, but neither of them is SVG.  The first is the native 'VDU stream' that all versions of BBC BASIC use as the means of communicating with the 'VDU drivers', for example the statement MOVE 400,500 is converted into the byte stream 25,4,144,1,244,1.  The second is Windows Enhanced Metafile Format (EMF) which is a proprietary vector graphics format used by Windows.

To create a VDU stream file from your program it is simply a matter of 'spooling' its output by adding a couple of lines:

35 *spool polygon.vdu
145 *spool

You can then 'play' that file back in BBC BASIC, or in principle convert it to another format (if you have a suitable converter).  To create a Windows metafile is somewhat messier since it involves Windows API functions.  So it all hinges on whether either of those file formats is suitable.

Richard Russell

I should add that there are online EMF to SVG file converters (Google will find several) so if you don't mind the overhead of using one of those sites then generating an EMF file from your BASIC program and then converting it to SVG is one possible solution.  This adaptation to your program will create an EMF file in your Documents folder:

REM Parabolas - Polygon
10 INPUT'"How many sides? "V
20 INPUT'"And setps per side? "N
30 MODE 1
DIM rc{l%,t%,r%,b%}
rc.r% = 17000 : REM units are 0.01 mm
rc.b% = 13500
oldHDC% = @memhdc%
SYS "CreateEnhMetaFile", 0, @usr\$+"polygon.emf", rc{}, 0 TO @memhdc%
40 FOR B=0 TO 6.28 STEP 2*PI/V
50   G=B+2*PI/V
60   T=B+4*PI/V
70   FOR H=500/N TO 501 STEP 500/N
80     P=(500-H)*SIN B+H*SIN G+640
90     Q=(500-H)*COS B+H*COS G+500
100     X=(500-H)*SIN G+H*SIN T+640
110     Y=(500-H)*COS G+H*COS T+500
120     MOVE P,Q
130     DRAW X,Y
140   NEXT H : NEXT B
SYS "CloseEnhMetaFile", @memhdc% TO hEMF%
@memhdc% = oldHDC%
SYS "DeleteEnhMetaFile", hEMF%

In practice you would be wise to add some error handling, ideally using SEH, since otherwise any error reported whilst the output is redirected to the metafile will be invisible!

D.W. Burger

Well, Richard...that's just incredible!  Thanks so much for providing the bb4w code for getting this done.  I gave it a try and got exactly the kind of output I wanted.  That is, I took the EMF file the program generated and converted it to SVG online.  I then opened the SVG file in Inkscape and generated the Gcode that I ultimately use to create a drawing on a 1m x 1.5m wall-hung, X-Y plotter I recently built.
Sometimes I marvel at what one can learn/do with online help.  My story is that I recently got inspired to figure out how to make "curve-stitch" art like the image I shared in my original post.  I've only had the "Curve Stitching" book by Jon Millington for a few days and was really lost in how to make use of the B.B.C. programs contained inside.  My google searches had failed to find anything on B.B.C. and only stumbled onto a reference to B.B.C. in a post on stackoverflow.com.  That find led me to bb4w and this usergroup.  So, in the span of a few days I went from completely lost to a working solution.  I can't thank you enough for taking the time to help me with this.  Best wishes!

Dave Burger
dwburger@...

------ Original Message ------
From: "Richard Russell" <news@...>
Sent: 1/20/2019 6:14:05 AM
Subject: Re: [bb4w] Output to svg file

I should add that there are online EMF to SVG file converters (Google will find several) so if you don't mind the overhead of using one of those sites then generating an EMF file from your BASIC program and then converting it to SVG is one possible solution.  This adaptation to your program will create an EMF file in your Documents folder:

REM Parabolas - Polygon
10 INPUT'"How many sides? "V
20 INPUT'"And setps per side? "N
30 MODE 1
DIM rc{l%,t%,r%,b%}
rc.r% = 17000 : REM units are 0.01 mm
rc.b% = 13500
oldHDC% = @memhdc%
SYS "CreateEnhMetaFile", 0, @usr\$+"polygon.emf", rc{}, 0 TO @memhdc%
40 FOR B=0 TO 6.28 STEP 2*PI/V
50   G=B+2*PI/V
60   T=B+4*PI/V
70   FOR H=500/N TO 501 STEP 500/N
80     P=(500-H)*SIN B+H*SIN G+640
90     Q=(500-H)*COS B+H*COS G+500
100     X=(500-H)*SIN G+H*SIN T+640
110     Y=(500-H)*COS G+H*COS T+500
120     MOVE P,Q
130     DRAW X,Y
140   NEXT H : NEXT B
SYS "CloseEnhMetaFile", @memhdc% TO hEMF%
@memhdc% = oldHDC%
SYS "DeleteEnhMetaFile", hEMF%

In practice you would be wise to add some error handling, ideally using SEH, since otherwise any error reported whilst the output is redirected to the metafile will be invisible!