[Therion] Main route through a cave
Tarquin Wilton-Jones
tarquin.wilton-jones at ntlworld.com
Mon Jun 14 21:35:52 CEST 2021
> So I am playing with a purple dashed line (thanks Axel!) and it looks
> almost great. Almost. I would like it more if I could make it
> translucent, but I think "withtransparentcolor" only works for fills.
> For lines, it seems to act like a regular withcolor. Is there a way to
> draw translucent lines with Therion's MetaPost? (Obviously I can
> recreate the line using a series of filled dots, or two parallel lines
> that get filled in between, but those are messy approaches.)
I will repeat my question of "can I draw a translucent line?" because it
would still be nicer, and hopefully someone here knows a way.
And it would still be very useful to be able to tint scraps somehow, eg.
make them half way between their depth colour, and the background
colour, without having to layer a different colour over the top (which
ruins opacity).
Anyway, I have done it with a dotted line. It sounded so simple; "dashed
evenly", but that puts the dots at regular spacing based on the line
width, without taking care of the line ends. Sometimes it ends half way
through a dot. And at the edges of a scrap, it gets cut off horribly,
and does not line up with the dot pattern of the next scrap's line.
Short lines across a scrap don't get any dots at all. You can use a
single line over multiple scraps and tell it not to clip, but then it
overlays all your other symbols. Urgh!
There is a solution, it is neat enough that some of you might want it
for your own projects;
The solution was to create a custom dashpattern, where each "dash" (a
dot) has half a gap width at each end of it. That means the line starts
with a gap, not a dot, and there is no overlap. To make sure it also
ends with a gap, it counts how many dots it can fit in the line length,
rounds it to the nearest integer (minimum of 1 dot), then works out how
much space should be devoted to each dot. It subtracts the width of a
dot's actual length (the minimum line length that can be drawn), and
then divides the remaining space by 2, and uses that as the "off" dash
length at either side of the dot's "on" width. I believe the built-in
adjust-step macro can offer something similar.
The end result looks good to me, and will always have half a gap at each
end - with gap lengths adjusted to fit perfectly - so lines that start
and end at the same coordinate as each other will always get a whole gap
between their dots.
(I would love to understand why arclength / width gives eg. 5, but it
will actually have enough space for 5 dots and 5 gaps, which should be
10 times the width, not 5. Is arclength half the actual length?)
Basic code:
def l_u_route (expr P)=
begingroup;
save scale, linewidth, len, steps, dotgap, dotwidth;
T:=identity;
linewidth:=u;
% If you make the dotwidth too small, MetaPost cannot perform the
% dashpattern calculations, and it gets the spacing wrong
% minimum limit is 0.0002
dotwidth:=0.001;
% the drawn length of the line is twice its arclength,
% so dot + gap makes exactly steps number of dots
len:=arclength P;
% short lines still need a dot
steps:=max(round(len / linewidth), 1);
dotgap:=len / steps;
pickup PenA scaled linewidth;
thdraw P dashed dashpattern(off (dotgap-dotwidth)/2 on dotwidth off
(dotgap-dotwidth)/2) withcolor (0.9,0,1);
endgroup;
enddef;
initsymbol("l_u_route");
More information about the Therion
mailing list