* How to get randomly coloured text in metapost?
@ 2010-05-11 15:48 Marco
2010-05-11 16:14 ` Alan BRASLAU
0 siblings, 1 reply; 8+ messages in thread
From: Marco @ 2010-05-11 15:48 UTC (permalink / raw)
To: ntg-context
Hi,
how to get random colours for text inside textext? Take a look at the
following example (MKIV).
\definecolor [static] [r=.9, g=.7, b=.8]
\starttext
\startuseMPgraphic {1}
def col=
(uniformdeviate(1),uniformdeviate(1),uniformdeviate(1))
enddef;
% These dots have a random color
for i=0 upto 5:
fill fullcircle scaled 5mm xshifted i*1cm withcolor col;
endfor;
% withcolor does not work, »Test« is black
for i=0 upto 5:
label(textext("Test"), (i*1cm,-1cm)) withcolor col;
endfor;
% To get a static color I use the following construct
for i=0 upto 5:
label(textext("\color[static]Test"), (i*1cm,-2cm));
endfor;
\stopuseMPgraphic
\useMPgraphic {1}
\stoptext
Is it possible to get the metapost construct »withcolor« to work with
text or do I have to take a different approach?
Thanks for any help.
Marco
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to get randomly coloured text in metapost?
2010-05-11 15:48 How to get randomly coloured text in metapost? Marco
@ 2010-05-11 16:14 ` Alan BRASLAU
2010-05-11 17:38 ` Marco
0 siblings, 1 reply; 8+ messages in thread
From: Alan BRASLAU @ 2010-05-11 16:14 UTC (permalink / raw)
To: Marco; +Cc: ntg-context
On Tuesday 11 May 2010 17:48:09 Marco wrote:
> Hi,
>
> how to get random colours for text inside textext? Take a look at the
> following example (MKIV).
>
> \definecolor [static] [r=.9, g=.7, b=.8]
> \starttext
> \startuseMPgraphic {1}
>
> def col=
> (uniformdeviate(1),uniformdeviate(1),uniformdeviate(1))
> enddef;
>
> % These dots have a random color
> for i=0 upto 5:
> fill fullcircle scaled 5mm xshifted i*1cm withcolor col;
> endfor;
>
> % withcolor does not work, »Test« is black
> for i=0 upto 5:
> label(textext("Test"), (i*1cm,-1cm)) withcolor col;
> endfor;
>
> % To get a static color I use the following construct
> for i=0 upto 5:
> label(textext("\color[static]Test"), (i*1cm,-2cm));
> endfor;
>
> \stopuseMPgraphic
> \useMPgraphic {1}
> \stoptext
>
> Is it possible to get the metapost construct »withcolor« to work with
> text or do I have to take a different approach?
>
> Thanks for any help.
> Marco
I understood from a much earlier discussion with Hans that "withcolor"
will not be made to work with text, whose color therefore has to be
set with ConTeXt constructs.
Alan
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to get randomly coloured text in metapost?
2010-05-11 16:14 ` Alan BRASLAU
@ 2010-05-11 17:38 ` Marco
2010-05-11 18:06 ` Hans Hagen
0 siblings, 1 reply; 8+ messages in thread
From: Marco @ 2010-05-11 17:38 UTC (permalink / raw)
To: ntg-context
> > Is it possible to get the metapost construct »withcolor« to work
> > with text or do I have to take a different approach?
>
> I understood from a much earlier discussion with Hans that "withcolor"
> will not be made to work with text, whose color therefore has to be
> set with ConTeXt constructs.
Thanks for the information. But how to do this? How can I set up the
randomness in ConTeXt? I browsed a bit through the sources and found a
lua snipped producing random integers. So here's my first attempt.
% only Integers, so not much variation in color :-(
\def\r{\ctxlua{commands.getrandomcounta(0,1)}}
% Defining the colour at this point makes it kind of static again
\definecolor[my][r=\r,g=\r,b=\r]
\starttext
\startuseMPgraphic {1}
% The colour is all the same, but different in each run
for i=0 upto 5:
label(textext("\color[my]{Test}"), (i*1cm,-2cm));
endfor;
% Does not work, results in compile error
% for i=0 upto 5:
% label(textext("\definecolor[my][r=\r,g=\r,b=\r]\color[my]{Test}"),
% (i*1cm,-3cm));
% endfor;
\stopuseMPgraphic
\useMPgraphic {1}
\stoptext
Maybe this code is an improvable step in the right direction, maybe it's
rubbish. Necessary improvements need to be:
i) need of floating point random numbers
ii) random colours per call and not per ConTeXt run
iii) the use is quite verbose, so need to put it in a macro
Any hints appreciated.
Marco
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to get randomly coloured text in metapost?
2010-05-11 17:38 ` Marco
@ 2010-05-11 18:06 ` Hans Hagen
2010-05-11 19:03 ` Marco
0 siblings, 1 reply; 8+ messages in thread
From: Hans Hagen @ 2010-05-11 18:06 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Marco
On 11-5-2010 7:38, Marco wrote:
> label(textext("\definecolor[my][r=\r,g=\r,b=\r]\color[my]{Test}"),
> % (i*1cm,-3cm));
numeric r, g, b ;
r := uniformdeviate 1 ;
g := uniformdeviate 1 ;
b := uniformdeviate 1 ;
textext("\colored[r=" & r & ",g=" & g & ",b=" & b & "]{Test}")
etc
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
| 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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to get randomly coloured text in metapost?
2010-05-11 18:06 ` Hans Hagen
@ 2010-05-11 19:03 ` Marco
2010-05-11 19:27 ` Mojca Miklavec
0 siblings, 1 reply; 8+ messages in thread
From: Marco @ 2010-05-11 19:03 UTC (permalink / raw)
To: ntg-context
> numeric r, g, b ;
>
> r := uniformdeviate 1 ;
> g := uniformdeviate 1 ;
> b := uniformdeviate 1 ;
>
> textext("\colored[r=" & r & ",g=" & g & ",b=" & b & "]{Test}")
Thanks for this snipped, Hans. It looks promising, but I get the
following compile error:
!mplib : mp terminal: >> "\colored [r="
>> 0.74464
! Not implemented: (string)&(known numeric).
<to be read again>
I used the following code:
\starttext
\startuseMPgraphic {1}
numeric r, g, b ;
r := uniformdeviate 1 ;
g := uniformdeviate 1 ;
b := uniformdeviate 1 ;
label(textext("\colored[r=" & r & ",g=" & g & ",b=" & b & "]{Test}"),
origin);
\stopuseMPgraphic
\useMPgraphic {1}
\stoptext
Marco
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to get randomly coloured text in metapost?
2010-05-11 19:03 ` Marco
@ 2010-05-11 19:27 ` Mojca Miklavec
2010-05-11 19:34 ` Marco
2010-05-11 19:40 ` luigi scarso
0 siblings, 2 replies; 8+ messages in thread
From: Mojca Miklavec @ 2010-05-11 19:27 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Tue, May 11, 2010 at 21:03, Marco wrote:
>> numeric r, g, b ;
>>
>> r := uniformdeviate 1 ;
>> g := uniformdeviate 1 ;
>> b := uniformdeviate 1 ;
>>
>> textext("\colored[r=" & r & ",g=" & g & ",b=" & b & "]{Test}")
> Thanks for this snipped, Hans. It looks promising, but I get the
> following compile error:
>
> !mplib : mp terminal: >> "\colored [r="
> >> 0.74464
> ! Not implemented: (string)&(known numeric).
> <to be read again>
You need to convert number to string first. Use "decimal(r)" instead
of "r". (But I didn't test.)
Mojca
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to get randomly coloured text in metapost?
2010-05-11 19:27 ` Mojca Miklavec
@ 2010-05-11 19:34 ` Marco
2010-05-11 19:40 ` luigi scarso
1 sibling, 0 replies; 8+ messages in thread
From: Marco @ 2010-05-11 19:34 UTC (permalink / raw)
To: ntg-context
> You need to convert number to string first. Use "decimal(r)" instead
> of "r". (But I didn't test.)
>
> Mojca
Thanks, Mojca. Works like a charm now.
Marco
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to get randomly coloured text in metapost?
2010-05-11 19:27 ` Mojca Miklavec
2010-05-11 19:34 ` Marco
@ 2010-05-11 19:40 ` luigi scarso
1 sibling, 0 replies; 8+ messages in thread
From: luigi scarso @ 2010-05-11 19:40 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Tue, May 11, 2010 at 9:27 PM, Mojca Miklavec
<mojca.miklavec.lists@gmail.com> wrote:
> On Tue, May 11, 2010 at 21:03, Marco wrote:
>>> numeric r, g, b ;
>>>
>>> r := uniformdeviate 1 ;
>>> g := uniformdeviate 1 ;
>>> b := uniformdeviate 1 ;
>>>
>>> textext("\colored[r=" & r & ",g=" & g & ",b=" & b & "]{Test}")
>> Thanks for this snipped, Hans. It looks promising, but I get the
>> following compile error:
>>
>> !mplib : mp terminal: >> "\colored [r="
>> >> 0.74464
>> ! Not implemented: (string)&(known numeric).
>> <to be read again>
>
> You need to convert number to string first. Use "decimal(r)" instead
> of "r". (But I didn't test.)
>
> Mojca
> ___________________________________________________________________________________
> 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://tex.aanhet.net
> archive : http://foundry.supelec.fr/projects/contextrev/
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
>
\starttext
\startuseMPgraphic {1}
numeric r, g, b ;
r := uniformdeviate 1 ;
g := uniformdeviate 1 ;
b := uniformdeviate 1 ;
label(textext("\colored[r=" & decimal(r) & ",g=" & decimal(g) & ",b="
& decimal(b) & "]{Test}"),origin);
label(textext("r=" & decimal(r) & ",g=" & decimal(g) & ",b=" &
decimal(b) ),origin+(0,-100));
\stopuseMPgraphic
\useMPgraphic {1}
\stoptext
( tested :-) )
Warning: default is preserve seed (every runs will have the same random number)
if you don't purge temporary files *tuo, *tui etc.
I'm sure that there is a switch/macros to avoid this, but I don't
remember it now
--
luigi
___________________________________________________________________________________
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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-05-11 19:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-11 15:48 How to get randomly coloured text in metapost? Marco
2010-05-11 16:14 ` Alan BRASLAU
2010-05-11 17:38 ` Marco
2010-05-11 18:06 ` Hans Hagen
2010-05-11 19:03 ` Marco
2010-05-11 19:27 ` Mojca Miklavec
2010-05-11 19:34 ` Marco
2010-05-11 19:40 ` luigi scarso
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).