[metapost] ANN: colordef package preview

Dan&Jan Luecking luecking at uark.edu
Fri Feb 6 08:48:52 CET 2009


At 04:40 PM 2/5/2009, you wrote:

>Unfortunately, I have no idea how to implement an operator ! that works
>like this:
>
>   red!80  = .2[red, white]
>   red!80!blue  = .2[red, blue]
>
>The former case is simple, roughly
>
>   primarydef col ! tint=
>     min(1,max(0,tint/100))[white, col]
>   enddef;

You could have ! examine its second operand. If it is a
number, save that number somewhere. If it is a color,
assume it is the second ! of a colA!tint!colB and make
use of the previously saved numeric to recover colA.
This assumes that only the two cases are needed.
For example:

newinternal colorfactor;
primarydef op_i ! op_ii =
   if numeric op_ii:
     colorfactor := min(1,max(0,op_ii/100));
     (colorfactor)[white,op_i]
   elseif color op_ii:
     % presume first operand was produced from
     % (colorfactor)[white,somecolor], and find that color
     if colorfactor = 1:
       op_i
     else:
       (colorfactor)[op_ii,(1/(1-colorfactor))[white,op_i]]
     fi
   else: % error case or other color models, etc.
   fi
enddef;

N.B. Not tested.

>In the second case, however, there is the problem that from a MetaPost
>point of view ! has two different meanings.
>
>   primarydef colA ! tint ! colB=
>
>doesn't seem to work.

It couldn't possibly, as MP doesn't have trinary operators,
or any means to define them.

Personally, I don't like the notation red!80!blue and prefer
a simple vardef with three arguments:
  vardef !(expr clrA, tint, clrB)=
   % etc.
  enddef


Dan

Dan Luecking
Fayetteville, Arkansas 



More information about the metapost mailing list