From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: from cgl.ntg.nl (Cgl.ntg.nl [5.39.185.202]) by inbox.vuxu.org (Postfix) with ESMTP id E862D21500 for ; Thu, 9 Jan 2025 22:46:00 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id 6C58648534F for ; Thu, 9 Jan 2025 22:45:26 +0100 (CET) Authentication-Results: cgl.ntg.nl (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=ntg.nl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntg.nl; h= content-type:content-type:list-unsubscribe:list-subscribe :list-post:list-owner:list-help:list-archive:archived-at:list-id :subject:subject:reply-to:precedence:message-id:date:date:from :from:mime-version:received:received:received:received:received :received; s=cgl; t=1736459125; x=1739051126; bh=z97AydCX1b0XZeD zO+vkg7jESX9OFH4Zlf2Ypy5sT6k=; b=fv6qMDn2AGUokOi8cp0XJNH1agpCCAn KDj2p5JpDGyx98N2vtmslgYmbNeHka0mINYyGbCo2nYz8e8RNiLNZICvpVH/xOKT 2DD88GfuWJ8XqjdHRp9j51JyyZRBu/SUiRSzYzRGnmEd51UcC5nhVYxtbbvMcqbc ntHhiZ9eUsfE= X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Authentication-Results: cgl.ntg.nl (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=gmail.com Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8BWkp7Y5JbeL for ; Thu, 9 Jan 2025 22:45:25 +0100 (CET) Received: from cgl.ntg.nl (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id A529148425F for ; Thu, 9 Jan 2025 22:44:47 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by cgl.ntg.nl (Postfix) with ESMTP id AF9104841E2 for ; Thu, 9 Jan 2025 22:44:33 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at cgl.ntg.nl Received: from cgl.ntg.nl ([127.0.0.1]) by localhost (cgl.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vrdzyNoWkU6I for ; Thu, 9 Jan 2025 22:44:33 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.216.50; helo=mail-pj1-f50.google.com; envelope-from=florent.m42@gmail.com; receiver= Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cgl.ntg.nl (Postfix) with ESMTPS id 38E874841BD for ; Thu, 9 Jan 2025 22:44:33 +0100 (CET) Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2ee76befe58so2344666a91.2 for ; Thu, 09 Jan 2025 13:44:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736459071; x=1737063871; darn=ntg.nl; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=px6br7GEtboQ0E5ZUVj9ha+aEXTCAX58chzDY4Li/jQ=; b=TqwstwwOBJLrCgrItob5XAVKfjXHKU62M12r2+1tPmYb6jl+NSJ5E3Qm6exFYcElQc Tn3drz4a7lSJQMzDGBlay8hslkmYOqk6Z71jbMpCMKC44NqJuWWLMx7SKJelT0NRpPsl 4A/hkl2BkfoWDU3MLMNDW0Q39DiszFn757zCVMPyRbmFnjnX9+EiC8mhm86XJKJp5+zJ aIrImIogGEClWJ+2QHFTMEkG4BlVkxdqelUHlECZx8h8KuvmA3/J9gYHpwRB0vmcmjm+ iXzxzcrTRKpYowrzYgixGhDe1t3a+gEwrUGw9dSgvDx69V4//wJ+hdf+0ARnAhs1ElfW 95rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736459071; x=1737063871; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=px6br7GEtboQ0E5ZUVj9ha+aEXTCAX58chzDY4Li/jQ=; b=jrhOKvjYCRf0HJx9RcjkofGiv3bPfi33PTZC5GejyxVqiL2CTlhKkrCXb0a3XpdDCU RFX1p5ALVnipyC73v7Gv6bPeaXamQdE4SD2Q0j4c83LdEFPqGIX35WN4HOmMlFHddA+Y 87Fqa1GbB9SrdYET/6vDoCT5oVOTK05DJusrkEt82Q4LBX+tiuHSuwSk8h5oP4TJNOp0 eqJxXxQs6DjV9BoYN2K5RFRV+QlfrxuJwJiMpRpYNXGViNC/oDkPhi5SLY87PlvAT7uP FJ+EUNgN0ATCYFeiohpzm2afQfkTLDumRo01r5apOyocYdClE7z20C5ApXqdeQDlNEAH aTWA== X-Gm-Message-State: AOJu0YxSB9xihdjG3GkXF3BZdFkF90qA3+AZ5salEVa/EF4kgFjM8oPi kjb+JUvMqpLlmmqxMLnYr0FAim/jdHCzXCrGQU8m7hlSk7aZcRA911+4St2NJoVfWIoP1dXoLRL nU3aIIORvS0R8alJGf1UKC8m4WxIzpUpq X-Gm-Gg: ASbGnctSy8lOkIx+eNikd9OnOX16E2iaabIbtbOIJyQi7v7Sza3DwDaFwNjFb8P1KKo GZkE4l4ppDRCzrA/CrGk7OAFFdDDCIAb4TcpvDQ== X-Google-Smtp-Source: AGHT+IFmCZIwdgmtAMi2Ny0uQ+qKt1QTEB5JnaxLnBIpHb13tqZMZ3y6TMUQdd0jNQ/eFp2MRSDRDy9vKTXs0PPts5s= X-Received: by 2002:a17:90b:37c5:b0:2ea:3f34:f18d with SMTP id 98e67ed59e1d1-2f548eae685mr12963120a91.10.1736459070403; Thu, 09 Jan 2025 13:44:30 -0800 (PST) MIME-Version: 1.0 From: Florent Michel Date: Thu, 9 Jan 2025 21:44:14 +0000 X-Gm-Features: AbW1kvazNKcIcPq71itKTPKq75dsEUdNzhTteLE3ZI9K3PwkL-U1Vb5-l6IEnzk Message-ID: To: mailing list for ConTeXt users Message-ID-Hash: ZM2ZQWQ3UK4TDQGFCT3JUWZ233MTI2OS X-Message-ID-Hash: ZM2ZQWQ3UK4TDQGFCT3JUWZ233MTI2OS X-MailFrom: florent.m42@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list Reply-To: mailing list for ConTeXt users Subject: [NTG-context] Functional shading with MetaPost / MetaFun List-Id: mailing list for ConTeXt users Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: multipart/mixed; boundary="===============7669635584516603398==" --===============7669635584516603398== Content-Type: multipart/alternative; boundary="0000000000000eff1e062b4ce23d" --0000000000000eff1e062b4ce23d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, I was trying to see if I could use MetaFun / MetaPost as my main tool for generating figures. I really like its close integration with ConTeXt, speed, and expressivity making it, even for a beginner like me, a pleasure to work with. One difficulty I encountered is for generating 2D functional shadings. For instance, I am not sure what is the best way to reproduce the following pgfplots picture in MetaPost: ____________________________________________________________ \usemodule[pgfplots] \pgfplotsset{width=3D10cm,compat=3D1.18} \usepgfplotslibrary{patchplots} \starttext \startTEXpage \starttikzpicture \startaxis[ hide axis=3Dtrue, axis lines=3Dnone,hide axis, enlargelimits=3Dfalse, scale only axis, clip bounding box=3Dupper bound, clip=3Dtrue, ] \addplot[ patch, shader=3Dinterp, mesh/color input=3Dexplicit, data cs=3Dpolar, ] coordinates { (90,4) [color=3Dred] (210,4) [color=3Dgreen] (-30,4) [color=3Dblue] }; \stopaxis \stoptikzpicture \stopTEXpage \stoptext ____________________________________________________________ One idea is to draw a sequence of triangles, each with a linear gradient: ____________________________________________________________ \startMPpage def LinearIntTriangle(expr pa, pb, pc, cola, colb, colc, n_iter) =3D for i =3D n_iter step -1 until 1 : path p; x :=3D i / n_iter; y :=3D (i - 0.5) / n_iter; p :=3D pa -- (pa + x * (pb - pa)) -- (pa + x * (pc - pa)) -- cycle; sh :=3D define_linear_shade(pa + y * (pb - pa), pa + y * (pc - pa), (1 - y) * cola + y * colb, (1 - y) * cola + y * colc); fill p withshade sh; endfor enddef; color cola, colb, colc; cola :=3D (0,1,0); colb :=3D (1,0,0); colc :=3D (0,0,1); LinearIntTriangle((0,0), (50,50*(3**0.5)), (100,0), cola, colb, colc, 30)= ; \stopMPpage ____________________________________________________________ or to use a slight variation (decomposing the triangle in three so that the color is =E2=80=98right=E2=80=99) along each edge: ____________________________________________________________ \startMPpage def LinearIntTriangleB(expr pa, pb, pc, cola, colb, colc, n_iter) =3D color centre_color; centre_color :=3D (cola + colb + colc) / 3; LinearIntTriangle((pa + pb + pc) / 3, pa, pb, centre_color, cola, colb, n_iter); LinearIntTriangle((pa + pb + pc) / 3, pb, pc, centre_color, colb, colc, n_iter); LinearIntTriangle((pa + pb + pc) / 3, pc, pa, centre_color, colc, cola, n_iter); enddef; color cola, colb, colc; cola :=3D (0,1,0); colb :=3D (1,0,0); colc :=3D (0,0,1); LinearIntTriangleB((0,0), (50,50*(3**0.5)), (100,0), cola, colb, colc, 10); \stopMPpage ____________________________________________________________ This approach gives =E2=80=98good enough=E2=80=99 results for large values = of n_iter. However, the size of the generated pdf is somewhat larger than the pgfplots version: for instance, the first version above generates a 5KiB pdf versus 3.8KiB for the pgfplots version, while being somewhat less accurate. Increasing n_iter to 100 gives a result which is (to my not-very-good eyes) very close to the pgfplots version but the pdf size increases to about 20KiB, and takes significantly longer to render using MuPDF. I'd be grateful if someone could point me to a better way to generate such shadings in MetaFun / MetaPost. Cheers, Florent --0000000000000eff1e062b4ce23d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,=C2=A0

I was trying to see if I= could use=C2=A0MetaFun / MetaPost as my main tool for generating figures. = I really like its close integration with ConTeXt, speed, and expressivity m= aking it,=C2=A0even for a beginner like me, a=C2=A0 pleasure to=C2=A0work w= ith.=C2=A0

One difficulty I encountered is for generating 2D functio= nal shadings. For instance, I am not sure what is the best way to reproduce= the following pgfplots picture in MetaPost:=C2=A0

_________________= ___________________________________________
\usemodule[pgfplots]
\pgf= plotsset{width=3D10cm,compat=3D1.18}
\usepgfplotslibrary{patchplots}
=
\starttext

\startTEXpage
\starttikzpicture
\startaxis[
= =C2=A0 =C2=A0 hide axis=3Dtrue,
=C2=A0 =C2=A0 axis lines=3Dnone,hide axi= s,
=C2=A0 =C2=A0 enlargelimits=3Dfalse,
=C2=A0 =C2=A0 scale only axis= ,
=C2=A0 =C2=A0 clip bounding box=3Dupper bound,
=C2=A0 =C2=A0 clip= =3Dtrue,
]
=C2=A0 =C2=A0 \addplot[
=C2=A0 =C2=A0 =C2=A0 =C2=A0 pat= ch,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 shader=3Dinterp,
=C2=A0 =C2=A0 =C2=A0= =C2=A0 mesh/color input=3Dexplicit,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 data cs= =3Dpolar,
=C2=A0 =C2=A0 ]
=C2=A0 =C2=A0 coordinates {
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 (90,4) [color=3Dred]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (210,= 4) [color=3Dgreen]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (-30,4) [color=3Dblue]=C2=A0 =C2=A0 };
\stopaxis
\stoptikzpicture
\stopTEXpage
= \stoptext
____________________________________________________________
One idea is to draw a=C2=A0sequence of triangles, each with a linear = gradient:=C2=A0
________________________________________________________= ____
\startMPpage
=C2=A0 def LinearIntTriangle(expr pa, pb, pc, cola,= colb, colc, n_iter) =3D
=C2=A0 =C2=A0 for i =3D n_iter step -1 until 1 = :
=C2=A0 =C2=A0 =C2=A0 path p;
=C2=A0 =C2=A0 =C2=A0 x :=3D i / n_iter= ;
=C2=A0 =C2=A0 =C2=A0 y :=3D (i - 0.5) / n_iter;
=C2=A0 =C2=A0 =C2= =A0 p :=3D pa -- (pa + x * (pb - pa)) -- (pa + x * (pc - pa)) -- cycle;
= =C2=A0 =C2=A0 =C2=A0 sh :=3D define_linear_shade(pa + y * (pb - pa), pa + y= * (pc - pa),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (1 - y) * cola + y = * colb, (1 - y) * cola + y * colc);
=C2=A0 =C2=A0 =C2=A0 fill p withshad= e sh;
=C2=A0 =C2=A0 endfor
=C2=A0 enddef;

=C2=A0 color cola, c= olb, colc;
=C2=A0 cola :=3D (0,1,0);
=C2=A0 colb :=3D (1,0,0);
=C2= =A0 colc :=3D (0,0,1);
=C2=A0
=C2=A0 LinearIntTriangle((0,0), (50,50= *(3**0.5)), (100,0), cola, colb, colc, 30);
\stopMPpage
_____________= _______________________________________________

or to use a slight v= ariation (decomposing the triangle in three so that the color is =E2=80=98r= ight=E2=80=99) along each edge:
________________________________________= ____________________
\startMPpage
=C2=A0 def LinearIntTriangleB(expr = pa, pb, pc, cola, colb, colc, n_iter) =3D
=C2=A0 =C2=A0 color centre_col= or;
=C2=A0 =C2=A0 centre_color :=3D (cola + colb + colc) / 3;
=C2=A0 = =C2=A0 LinearIntTriangle((pa + pb + pc) / 3, pa, pb, centre_color, cola, co= lb, n_iter);
=C2=A0 =C2=A0 LinearIntTriangle((pa + pb + pc) / 3, pb, pc,= centre_color, colb, colc, n_iter);
=C2=A0 =C2=A0 LinearIntTriangle((pa = + pb + pc) / 3, pc, pa, centre_color, colc, cola, n_iter);
=C2=A0 enddef= ;

=C2=A0 color cola, colb, colc;
=C2=A0 cola :=3D (0,1,0);
=C2= =A0 colb :=3D (1,0,0);
=C2=A0 colc :=3D (0,0,1);
=C2=A0
=C2=A0 Li= nearIntTriangleB((0,0), (50,50*(3**0.5)), (100,0), cola, colb, colc, 10);\stopMPpage
__________________________________________________________= __

This approach gives =E2=80=98good enough=E2=80=99 results for lar= ge values of n_iter. However, the size of the generated pdf is somewhat lar= ger than the pgfplots version: for instance, the first version above genera= tes a 5KiB pdf versus 3.8KiB for the pgfplots version, while being somewhat= less accurate. Increasing n_iter to 100 gives a result which is (to my not= -very-good eyes) very close to the pgfplots version but the pdf size increa= ses to about 20KiB, and takes significantly longer to render using MuPDF.= =C2=A0

I'd be grateful if someone could point me to=C2=A0a bette= r=C2=A0way to generate such shadings in MetaFun / MetaPost.

Cheers,<= br>Florent
--0000000000000eff1e062b4ce23d-- --===============7669635584516603398== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________ --===============7669635584516603398==--