DrawGen part 3 – BASIC points.





Although not obvious from previous articles DrawGen was originally written by me *in* BASIC and for use *from* BASIC. That said, I ‘moved on’ to ‘C’ a few years ago, hence the emphasis in this series on that language. The main disadvantage when using DrawGen from BASIC is that I haven’t written a library of functions to make things easier. However, the ‘help’ file which comes with DrawGen contains quite a lot of info for using BASIC so here I’ll just give a couple of simple examples so you can see how to go about using that information.



The above program shows how to use DrawGen commands in a BASIC program. The process has four stages:

  1. Open a file to save the commands;
  2. Save the commands as a series of instruction strings followed by appropriate values (integers);
  3. Close the file;
  4. Issue a star command telling DrawGen which file you want converted from a set of commands into a real DrawFile.


In the above example I used immediate values, but you can also do something like


So, just as with the ‘C’ examples you can create graphics using variables. There are a couple of much more complex BASIC demo programs inside the !DrawGen application if you want to try them.



To be honest I suspect that’s probably all I need say about using DrawGen from BASIC as, once you’ve seen the examples I suspect you can do everything else from the help file. If not, please let me know and I’ll be happy to answer any questions. Before reverting to my familiar ‘C’ I should say something which probably gives my age away! It should be obvious from the above examples that, in principle, you can use DrawGen from *any* language as all you have to do is put the appropriate commands into a file and then tell the DrawGen module to convert it. So, for those of you who use FORTRAN: (there goes my age clue!) I have a set of subroutines which makes using DrawGen from FORTRAN a bit easier. If you would like these, or want to ask any questions about DrawGen, please contact me via Archive or directly via email <jcgl@st-and.demon.co.uk>.

Looking at the second example above, you can see that I have sneaked in another ‘new’ DrawGen command, “linestyle”. The ‘C’ command for this is



where style_number is an integer which sets the line style to be used until further notice. The default linestyle is 0 which gives the predictable continuous line. At present there are just 8 linestyles defined.

The final thing I want to cover is curved lines – specifically Bezier curved paths. You can include Bezier curved paths in a ‘path’ using the command



This works in a similar way the the ‘DG_draw’ command in that it draws a line from the present drawing location to another place, but now it draws a Bezier curve rather than a straight line. The easiest way to understand how it works is, as usual, by examples.

Bezier1 simply draws a single curved line





This shows how the curvature of the line is determined by the locations of two control points with respect to the two actual endpoints of the line. Applications like !Draw, !Vector, etc let you show these on screen when editing and you can drag then around and get a feel for how moving them alters the curved shape.

Bezier2 uses a series of Bezier curves to draw a wiggly line:





This wiggly line isn’t meant to represent anything, it just shows you can generate quite complicated curved shapes. Although I’ve not given an example here, you can mix straight lines (DG_draw), and curves and movements (DG_move) in a path to get almost any shape you can imagine. The path can be coloured and filled as you like with the DG_path command which starts it, and you can preceed the path with a DG_linestyle if you want some kind of broken line. Taken together, these commands should give you the ability to make any kind of line or shape that you need.




That’s all I plan to write in this series, but if you have any questions please let me know. Thanks for reading and have good fun with DrawGen! :-)

Jim Lesurf