LOGOesque extension to Language::SIMPLE - Feature creep diverts attention.

In an attempt to standardise vector graphical operations in GUIDeFATE (the world's simplest GUI designer) across different back-ends and keep things simple, a little diversion was needed. For a standard vector drawing one might use the computationally cumbersome SVG format directly and draw that on the widget. The problem is that one needs to be able to manipulate the graphics easily and AFTER deployment. I needed to script the creation of the drawing. Now lots of applications use a script language of their own, e.g. gnuplot, matlab, Kalgebra, R etc, so clearly this is a useful functionality on its own. What would be also useful is a portable scripting platform. This platform could serve my purpose, but being modular, could be easily repurposed for other applications.

Enter Language::SIMPLE (not yet on CPAN), the Simple Integrated Modular Programming Language Experiment, extended it with a LOGO to SVG translator. Dubious, I know, and vastly more powerful SVG and DOM modules exist already. But the main strength of Perl has been its ability to parse and manipulate textual data...data such as an SVG file or a script that generates that file. And the goal of this utility would have been to generate complex graphics from simple scripts, the scripts themselves potentially being generated programmatically. These graphics could then be loaded into a widget for display. Sure, the goal is not to be Inkscape, but to provide a reasonably usable set of textual graphical commands that could be scripted to create fairly complex vector imagery in a portable format, and integrateable into a GUI.

The architecture maybe could look something like this:- Now I am not sure the best way to do this. The modules are application specific. The modularity currently comes from using a do statement:-

   # $file is the extension file and contains the *contents* of a hash
   #  this hash is then inserted into %extensions  
   my %extension=do $file or die "Failed to load extension in $file $!";
   foreach my $thingy (keys %extension){
       $extensions{$extName}{$thingy}=$extension{$thingy};
   }

This loads the module which is structured as the contents of a hash. The current version of logo.ext supports creating lines, poly-lines, polygons, paths, circles, rectangles, text, colours and fills using LOGO-esque commands. SIMPLE already offers variable definition, arithmetic and some trigonometric functions along with loops, conditional branching. So it is now relatively trivial to draw images on the screen, whether it is the graphical explanation diagram above, or some random flowers below, and either save an SVG file, or insert into a widget (e.g. in a GUIDeFATE application, with any of its back-ends: Tk, Qt, GTK, Wx, and who knows, possibly Win32 etc)

random-flowers.png

Certainly it was not the intention to keep adding features to the extension, rather than focusing on GUIDeFATE. But it has been relatively simple to add commands, and I do hope to add groups, patterns and transforms. Animation should be possible thoughI am certain the performance is not going to be great, (unlikely to be able to recreate Asteroids or Elite). Adding limited 3D graphics like OpenSCAD would be another interesting diversion.

One thing for certain, testing SIMPLE and the logo extension has been made much easier because of the ability to rustle up a quick and dirty GUI application using GUIDeFATE. Which reminds me, I do need to get back to fixing GUIDeFATE proper. But few more tweaks first...

Leave a comment

About Saif

user-pic An Orthopaedic Surgeon, A Tissue Engineering Scientist, Lecturer, (and Hobbyist Programmer, Electronics Engineer and Roboticist)