ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Gerben Wierda <gerben.wierda@rna.nl>
Subject: Re: METAPOST/MetaFun withtransparency doesn't accept my pair primary argument, what am I doing wrong?
Date: Thu, 9 Apr 2020 18:06:12 +0200	[thread overview]
Message-ID: <87aecefb-6b82-40ed-3f17-21b9d152c4aa@xs4all.nl> (raw)
In-Reply-To: <7CC08AA6-0447-4EF3-A04C-62BC8248A309@rna.nl>

On 4/9/2020 4:58 PM, Gerben Wierda wrote:
> \starttext
> \startMPpage[instance=doublefun]
> 
> vardef Foo( expr w, h, fillColor, fillTransparency) =
>    show "FOO:", w, h, fillColor, fillTransparency;
>    save pic; picture pic;
>    save circ; path circ;
>    circ := (fullcircle xyscaled (h,h));
>    pic := image (
>      fill (circ shifted (w-h/2,-h/2)) withcolor fillColor 
> withtransparency fillTransparency;
>    );
>    pic
> enddef;
> 
> pic := Foo( 150, 50, (0.686,1.000,1.000), (1,1.000));
> draw pic;
> \stopMPpage
> \stoptext

Maybe this definition is better then but I need to test it more

\starttext
\startMPpage[instance=doublefun]

def withtransparency expr t =
     if pair t :
         withprescript "tr_alternative="  & decimal 
transparency_alternative_to_number(xpart t)
         withprescript "tr_transparency=" & decimal ypart t
     else :
         mfun_with_transparency (transparency_alternative_to_number(t))
     fi
enddef ;

def mfun_with_transparency (expr a) expr t =
     withprescript "tr_alternative="  & decimal a
     withprescript "tr_transparency=" & decimal t
enddef ;

vardef Foo ( expr w, h, fillColor, fillTransparency) =
   image (
     fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2)
         withcolor fillColor
         withtransparency fillTransparency
     ;
   )
enddef;

vardef FooX ( expr w, h, fillColor) =
   image (
     fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2)
         withcolor fillColor
         withtransparency (normaltransparent, .5)
     ;
   )
enddef;

vardef FooY ( expr w, h, fillColor) =
   image (
     fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2)
         withcolor fillColor
         withtransparency normaltransparent .5
     ;
   )
enddef;

draw Foo  ( 350, 50, (0.5,1,0), (1,.5));
draw FooX ( 250, 50, (1,0.5,1));
draw FooY ( 150, 50, (1,1,0.5));

\stopMPpage
\stoptext


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2020-04-09 16:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 14:58 Gerben Wierda
2020-04-09 16:06 ` Hans Hagen [this message]
2020-04-10  8:07   ` Gerben Wierda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87aecefb-6b82-40ed-3f17-21b9d152c4aa@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=gerben.wierda@rna.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).