[Therion] Setting scale on custom symbol

Bill Gee bgee at campercaver.net
Thu May 16 20:51:03 CEST 2019


Hi Bruce and Martin -

Thanks for the tips.  I have figured out how to make it work.  The new code looks like this:

# This code defines an artificial electric light.  Used in tourist sections of a cave.
    def p_u_electriclight (expr pos,theta,sc,al) =
      U:=(0.3u, 0.3u);
      % Reduce size of the symbol.  The default size is too big.
      interim defaultscale:=0.4sc;
      T:=identity aligned al rotated theta scaled defaultscale shifted pos;
      pickup PenC;
      
      thdraw fullcircle scaled 0.5u shifted (0.0u, 0.7u);
      thdraw (-0.5u, -0.6u) -- (-0.5u, 0.0u);
      thdraw (-0.5u, 0.0u) .. (-0.35u, 0.55u) .. (0.0u, 0.7u);
      thdraw (0.0u, 0.7u) .. (0.35u, 0.55u) .. (0.5u, 0.0u);
      thdraw (0.5u,0.0u) -- (0.5u, -0.6u);
      thdraw (-0.7u, -0.6u) -- (0.7u, -0.6u);
      
    enddef;


I fiddled with the constant 0.4 to find a value that produces symbols about the size I wanted.  A nice thing about this code is that it still respects the "-size xxx" parameters.  

What does the line "U:=(0.3u, 0.3u);" do?  As far as I can tell, it has no effect at all.

MetaPost is rather puzzling by having no explicit multiplication operator.  The expression "0.4sc" does multiplication, but without any visible operator.  The same happens for all the expressions involving "u".  Back when I was studying computer science, that would have produced much vituperation from the professors!

I think this code is now suitable for posting on the Wiki.  I have several other custom symbols that might be useful to others:

Pavement
Boardwalk
Tiled floor
  (all as area fills)

Display case
Boxwork
Bear bed
Pendant
Stromatolite
  (These are points)

Who should I send the code to for review and posting?

-- 
Bill Gee



On Wednesday, May 15, 2019 2:47:09 AM CDT Martin Sluka via Therion wrote:
> From: https://www.researchgate.net/publication/265062623_Tutorial_in_MetaPost
> 
> interim - Make a local change to an internal variable
> 
> Martin Sluka
> 
> 
> > 15. 5. 2019 v 9:23, Bruce Mutton <bruce at tomo.co.nz>:
> > 
> > Hi Bill
> > I think that merging what you have with an interim defaultscale:=0.6; variable as demonstrated by Thomas Holder here https://therion.speleo.sk/wiki/metapost#special_symbol_examples will do the trick.
> > You probably want to keep the sc in def p_u_electriclight (expr pos,theta,sc,al), and multiply it by defaultscale before calling T:=identity...
> > Probably some trial and error involved.
> > Bruce
> > 
> > -----Original Message-----
> > From: Therion <therion-bounces at speleo.sk> On Behalf Of Bill Gee
> > Sent: Monday, 13 May 2019 06:14
> > To: Therion Mail List <therion at speleo.sk>
> > Subject: [Therion] Setting scale on custom symbol
> > 
> > Hello everyone - 
> > 
> > I have defined a custom symbol for electric light fixtures.  The MetaPost code is below.  Now that I have used it, I find that it draws the symbol too large.  I tried using "-scale small" and "-scale tiny", and that helps.  Rather than go through and add that to every point, I would like to change the MetaPost so it draws the symbol a bit smaller.
> > 
> > And I am lazy!  I could replot all the points for each of the lines.  It seems to me there should be a simpler way.  I tried messing with the U:= parameters, but they seem to make no difference whatever.
> > 
> > Is there a way I can declare a multiplier in the MetaPost code?  Perhaps declaring u = 0.6u?
> > 
> > Thanks!
> 
> 







More information about the Therion mailing list