From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/106814 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Gerben Wierda Newsgroups: gmane.comp.tex.context Subject: Re: METAPOST/MetaFun withtransparency doesn't accept my pair primary argument, what am I doing wrong? Date: Fri, 10 Apr 2020 10:07:28 +0200 Message-ID: <541E8D96-3966-483D-B4A6-0D9B86B487F2@rna.nl> References: <7CC08AA6-0447-4EF3-A04C-62BC8248A309@rna.nl> <87aecefb-6b82-40ed-3f17-21b9d152c4aa@xs4all.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.14\)) Content-Type: multipart/mixed; boundary="===============8356666018784143591==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="111161"; mail-complaints-to="usenet@ciao.gmane.io" Cc: mailing list for ConTeXt users To: Hans Hagen Original-X-From: ntg-context-bounces@ntg.nl Fri Apr 10 10:08:01 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jMohl-000Soz-7F for gctc-ntg-context-518@m.gmane-mx.org; Fri, 10 Apr 2020 10:08:01 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 56671183217; Fri, 10 Apr 2020 10:07:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cJTVs0kDnWTK; Fri, 10 Apr 2020 10:07:33 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 6AEB2183203; Fri, 10 Apr 2020 10:07:33 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 6378B183200 for ; Fri, 10 Apr 2020 10:07:32 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nl0f-_AZD8oR for ; Fri, 10 Apr 2020 10:07:31 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=213.125.118.53; helo=mail.rna.nl; envelope-from=gerben.wierda@rna.nl; receiver= Original-Received: from mail.rna.nl (mail.rna.nl [213.125.118.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 6ECC6182C24 for ; Fri, 10 Apr 2020 10:07:31 +0200 (CEST) Original-Received: from hermione.rna.nl (hermione.rna.nl [192.168.2.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.rna.nl (Postfix) with ESMTPSA id 844883D13688; Fri, 10 Apr 2020 10:07:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rna.nl; s=dkim_rsa2048; t=1586506048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AZ68/VQvVbzEEpOf1ZHC9CDrAyG8s9aNjAePlo/YR6c=; b=hdbDJtimg16S6lt2zJFlbmMRAQHuPXzLRSLgEkiVpErHZLrgHVvfZ0RaBo2kItY5zZLmg0 HYReVxDtGQXae5RX6hWLdg6S4niPJUaZp34DCNP0yvDbSprRlhdgq0TmHqhhNnAKyklvyX 1AyCklkYTL6ZRKCL1VN1yGhgy4wj+8TMLH+H+060i4MF6K9kkACsBhfpaIeXQElus279qE HLzYdSUc9iyIqGXULJqNDJySh3xcv4FqVpmbXlw71dUPb0CzBA1pgwyIWYyGoYHVJBGb7t EJiTd/a9078Xv8XnUKnjNHGXfgminKsNfvHpvjIrYQb+SMz0JCaXSFPJuIlHxQ== In-Reply-To: <87aecefb-6b82-40ed-3f17-21b9d152c4aa@xs4all.nl> X-Mailer: Apple Mail (2.3445.104.14) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:106814 Archived-At: --===============8356666018784143591== Content-Type: multipart/alternative; boundary="Apple-Mail=_95654EB8-4DD1-4EB5-B36E-D8CE262ED56D" --Apple-Mail=_95654EB8-4DD1-4EB5-B36E-D8CE262ED56D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 As I only use one transparency method anyway I could also fix this by = passing a numeric instead of a pair and use the standard = withtransparency (I don=E2=80=99t like overriding a standard MetaFun = method, one never knows what might break in future updates). vardef Foo( expr w, h, fillColor, fillTransparency) =3D show "FOO:", w, h, fillColor, fillTransparency; save pic; picture pic; save circ; path circ; circ :=3D (fullcircle xyscaled (h,h)); pic :=3D image ( fill (circ shifted (w-h/2,-h/2)) withcolor fillColor = withtransparency (1,fillTransparency); ); pic enddef; picture pic; pic :=3D Foo( 150, 50, (0.686,1.000,1.000), 0.5); draw pic; \stopMPpage \stoptext > On 9 Apr 2020, at 18:06, Hans Hagen wrote: >=20 > On 4/9/2020 4:58 PM, Gerben Wierda wrote: >> \starttext >> \startMPpage[instance=3Ddoublefun] >> vardef Foo( expr w, h, fillColor, fillTransparency) =3D >> show "FOO:", w, h, fillColor, fillTransparency; >> save pic; picture pic; >> save circ; path circ; >> circ :=3D (fullcircle xyscaled (h,h)); >> pic :=3D image ( >> fill (circ shifted (w-h/2,-h/2)) withcolor fillColor = withtransparency fillTransparency; >> ); >> pic >> enddef; >> pic :=3D Foo( 150, 50, (0.686,1.000,1.000), (1,1.000)); >> draw pic; >> \stopMPpage >> \stoptext >=20 > Maybe this definition is better then but I need to test it more >=20 > \starttext > \startMPpage[instance=3Ddoublefun] >=20 > def withtransparency expr t =3D > if pair t : > withprescript "tr_alternative=3D" & decimal = transparency_alternative_to_number(xpart t) > withprescript "tr_transparency=3D" & decimal ypart t > else : > mfun_with_transparency (transparency_alternative_to_number(t)) > fi > enddef ; >=20 > def mfun_with_transparency (expr a) expr t =3D > withprescript "tr_alternative=3D" & decimal a > withprescript "tr_transparency=3D" & decimal t > enddef ; >=20 > vardef Foo ( expr w, h, fillColor, fillTransparency) =3D > image ( > fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2) > withcolor fillColor > withtransparency fillTransparency > ; > ) > enddef; >=20 > vardef FooX ( expr w, h, fillColor) =3D > image ( > fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2) > withcolor fillColor > withtransparency (normaltransparent, .5) > ; > ) > enddef; >=20 > vardef FooY ( expr w, h, fillColor) =3D > image ( > fill fullcircle xyscaled (h,h) shifted (w-h/2,-h/2) > withcolor fillColor > withtransparency normaltransparent .5 > ; > ) > enddef; >=20 > 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)); >=20 > \stopMPpage > \stoptext >=20 >=20 > --=20 >=20 > ----------------------------------------------------------------- > Hans Hagen | PRAGMA ADE > Ridderstraat 27 | 8061 GH Hasselt | The Netherlands > tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl > ----------------------------------------------------------------- --Apple-Mail=_95654EB8-4DD1-4EB5-B36E-D8CE262ED56D Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 As = I only use one transparency method anyway I could also fix this by = passing a numeric instead of a pair and use the standard = withtransparency (I don=E2=80=99t like overriding a standard MetaFun = method, one never knows what might break in future updates).

vardef Foo( expr w, h, fillColor, fillTransparency) = =3D
  show = "FOO:", w, h, fillColor, fillTransparency;
  save pic; picture = pic;
  save = circ; path circ;
  circ = :=3D (fullcircle xyscaled (h,h));
  pic :=3D image (
    fill (circ shifted (w-h/2,-h/2)) = withcolor fillColor withtransparency = (1,fillTransparency);
  );
  pic
enddef;

picture pic;
pic :=3D Foo( 150, 50, (0.686,1.000,1.000), = 0.5);
draw = pic;
\stopMPpage
\stoptext


On 9 Apr 2020, at 18:06, Hans Hagen <j.hagen@xs4all.nl> = wrote:

On 4/9/2020 4:58 PM, Gerben Wierda wrote:
\starttext
\startMPpage[instance=3Ddoublefun]
vardef Foo( = expr w, h, fillColor, fillTransparency) =3D
  show = "FOO:", w, h, fillColor, fillTransparency;
  save = pic; picture pic;
  save circ; path circ;
  circ :=3D (fullcircle xyscaled (h,h));
=   pic :=3D image (
    fill (circ shifted = (w-h/2,-h/2)) withcolor fillColor withtransparency fillTransparency;
  );
  pic
enddef;
pic :=3D 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=3Ddoublefun]

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

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

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

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

vardef FooY ( = expr w, h, fillColor) =3D
 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


--

---------------------------------------------------------------= --
=             &n= bsp;           &nbs= p;            =     Hans Hagen | PRAGMA ADE
=             &n= bsp;Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
=       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
---------------------------------------------------------------= --

= --Apple-Mail=_95654EB8-4DD1-4EB5-B36E-D8CE262ED56D-- --===============8356666018784143591== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============8356666018784143591==--