From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: "Jairo A. del Rio via ntg-context" <ntg-context@ntg.nl>
Cc: Hans Hagen <j.hagen@xs4all.nl>
Subject: Re: Passing colors to Metafun and TeX's bitmapimage macros
Date: Wed, 1 Sep 2021 14:42:30 +0200 [thread overview]
Message-ID: <ca2889b3-d687-e2aa-3e8b-5c4910936c1f@xs4all.nl> (raw)
In-Reply-To: <CAKyqqaYXOPo+xWPp3ZS0QGouPB39uvg=eKK+w_VkGJFJyCQJMQ@mail.gmail.com>
On 9/1/2021 1:08 PM, Jairo A. del Rio via ntg-context wrote:
> Hi, list!
> I want to know if there's a handy way to pass predefined colors, either
> RGB or CMYK, e.g. those in svg or crayola, to Metafun's bitmapimage.
> Say, something like:
>
> \startMPpage
>
> % svg's gold definition
>
> draw bitmapimage(2, 2, "ffd700 ffd700 ffd700 000000") scaled 3cm;
>
> \stopMPpage
>
> using "gold" instead of its definition so that I can set bitmap image
> colors by name rather than numbers. In a similar vein, I wonder if
> something analogous is possible for ConTeXt's \bitmapimage macro. Thank
> you in advance.
it's mostly about 'what interface to use' and 'how is that documented
and remembered at all'
\startluacode
function MP.replacecolors(str,c)
-- could be a helper, these two combined (never needed it):
local m, a = attributes.colors.namedcolorattributes(c)
local d = attributes.colors.values[a]
local r = string.format("%02x%02x%02x",
math.round(d[3]*255),
math.round(d[4]*255),
math.round(d[5]*255)
)
mp.quoted((string.gsub(str,"444444",r)))
end
\stopluacode
\definecolor[kindofgold][h=ffd700]
\startMPpage
draw bitmapimage(2, 2, "ffd700 ffd700 ffd700 000000") scaled 3cm;
vardef mybitmapimage(expr n, m, s, c) =
bitmapimage(2, 2, MP.replacecolors(s, c))
enddef ;
draw mybitmapimage(2, 2, "444444 444444 444444 000000", "kindofgold")
scaled 3cm shifted (0,-3cm);
\stopMPpage
-----------------------------------------------------------------
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
___________________________________________________________________________________
prev parent reply other threads:[~2021-09-01 12:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-01 11:08 Jairo A. del Rio via ntg-context
2021-09-01 12:42 ` Hans Hagen via ntg-context [this message]
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=ca2889b3-d687-e2aa-3e8b-5c4910936c1f@xs4all.nl \
--to=ntg-context@ntg.nl \
--cc=j.hagen@xs4all.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).