Context style macros for metapost
Hi, There are certain things that I do not like about metapost (it is not possible to specify drawoptions and filloptions separately, it lacks some of the features of tikz, etc.) and I was playing around trying to implement them. Being used to the ConTeXt way of things, I wanted to write macros in metapost the same way (define.... setup.... etc.) This is my first attempt --- a replacement for dashpattern macro. delimiters [[ ]] ; def definedash suffix @# = dodefinedash.@# enddef ; vardef dodefinedash@#[[text t]] = save on, off, w ; let on = _on_ ; let off = _off_ ; w = 0 ; picture @# ; @# := nullpicture t enddef ; definedash [[myeven]] [[on 3 off 3]] ; beginfig(1) draw (0,0)--(100,100) dashed myeven ; endfig ; end; Is there a better way to do this in metapost? Aditya
Aditya Mahajan wrote:
definedash [[myeven]] [[on 3 off 3]] ;
beginfig(1) draw (0,0)--(100,100) dashed myeven ; endfig ; end;
Is there a better way to do this in metapost?
Not really, I think. A dash pattern like definedash [[stutter]] [[on 3 off 3 on 1 off 3]] ; is allowed, making a true key-value solution almost impossible. (and I expect similar situations with just about everything) Taco
On Thu, 21 Dec 2006, Taco Hoekwater wrote:
Aditya Mahajan wrote:
definedash [[myeven]] [[on 3 off 3]] ;
beginfig(1) draw (0,0)--(100,100) dashed myeven ; endfig ; end;
Is there a better way to do this in metapost?
Not really, I think. A dash pattern like
definedash [[stutter]] [[on 3 off 3 on 1 off 3]] ;
is allowed, making a true key-value solution almost impossible. (and I expect similar situations with just about everything)
I am not too much worried about key-value assignment, but want a more familar (Contextish) interface. For example, I want to be able to do definelines [[verythin =.25bp, thin=.5bp, thick =1bp, verythick=1.5bp]] transale internally into different pen shapes and then say setupdraw[[lines=thick]] which will store the pen "thick" in an internal variable (say _draw!pen_). The macro draw will start with pickup pen _pen_ ; So that I can say setupdraw[[thick]] draw (0,0)--(10,10) ; .... setupdraw[[thin]] draw (10,0)--(0,10) ; ..... etc. Basically, provide a layer of emulation around metapost, so that it appears to be more "intuitive". One thing that I am struggling with right now is to implement something equivalent to \dosingleempty, so that both draw (0,0)--(10,10) ; and draw [[thick]] (0,0)--(10,10) ; work. A lot of times, I find myself wanting to use different settings for draw and fill. Right now drawoptions specifies the options for both draw and fill. That is why, I want something like setupdraw[[lines=...,color=...,options=....]] and setupfill[[lines=...,color=...,options=....]] etc. Right now, I am just experimenting on how difficult it is to have a consistent layer to do all this. Aditya
participants (2)
-
Aditya Mahajan
-
Taco Hoekwater