ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Passing colors to Metafun and TeX's bitmapimage macros
@ 2021-09-01 11:08 Jairo A. del Rio via ntg-context
  2021-09-01 12:42 ` Hans Hagen via ntg-context
  0 siblings, 1 reply; 2+ messages in thread
From: Jairo A. del Rio via ntg-context @ 2021-09-01 11:08 UTC (permalink / raw)
  To: mailing list for ConTeXt users; +Cc: Jairo A. del Rio


[-- Attachment #1.1: Type: text/plain, Size: 536 bytes --]

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.

Cordially,

Jairo

[-- Attachment #1.2: Type: text/html, Size: 1109 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Passing colors to Metafun and TeX's bitmapimage macros
  2021-09-01 11:08 Passing colors to Metafun and TeX's bitmapimage macros Jairo A. del Rio via ntg-context
@ 2021-09-01 12:42 ` Hans Hagen via ntg-context
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen via ntg-context @ 2021-09-01 12:42 UTC (permalink / raw)
  To: Jairo A. del Rio via ntg-context; +Cc: Hans Hagen

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-01 12:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01 11:08 Passing colors to Metafun and TeX's bitmapimage macros Jairo A. del Rio via ntg-context
2021-09-01 12:42 ` Hans Hagen via ntg-context

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).