* random background picture in metafun
@ 2012-03-13 14:45 Thomas A. Schmitz
2012-03-13 15:58 ` Aditya Mahajan
2012-03-13 16:33 ` Peter Rolf
0 siblings, 2 replies; 10+ messages in thread
From: Thomas A. Schmitz @ 2012-03-13 14:45 UTC (permalink / raw)
To: mailing list for ConTeXt users
Hi all,
scenario: for a presentation, I want the background to be a random
picture, taken from a directory "backgroundpics." The pictures are
numbered consecutively as 1.jpg through 22.jpg. For some complex
reasons, it would be easier for me to include these pictures via metafun
(I want to add other graphical elements on top). So my question is, how
can I pick a random picture? Given the code
StartPage ;
draw externalfigure "backgoundpics/1" xscaled PaperWidth yscaled
PaperHeight ;
StopPage ;
how can I obtain a random number and make metapost pick the
corresponding picture? Sorry, difficult to make a minimal example here...
Thomas
___________________________________________________________________________________
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] 10+ messages in thread
* Re: random background picture in metafun
2012-03-13 14:45 random background picture in metafun Thomas A. Schmitz
@ 2012-03-13 15:58 ` Aditya Mahajan
2012-03-13 16:33 ` Peter Rolf
1 sibling, 0 replies; 10+ messages in thread
From: Aditya Mahajan @ 2012-03-13 15:58 UTC (permalink / raw)
To: mailing list for ConTeXt users
> Hi all,
>
> scenario: for a presentation, I want the background to be a random picture,
> taken from a directory "backgroundpics." The pictures are numbered
> consecutively as 1.jpg through 22.jpg. For some complex reasons, it would be
> easier for me to include these pictures via metafun (I want to add other
> graphical elements on top). So my question is, how can I pick a random
> picture? Given the code
>
> StartPage ;
> draw externalfigure "backgoundpics/1" xscaled PaperWidth yscaled
> PaperHeight ;
> StopPage ;
>
> how can I obtain a random number and make metapost pick the corresponding
> picture? Sorry, difficult to make a minimal example here...
(Untested)
draw externalfigure ("backgroundpics/" & round(uniformdeviate(22)+1))
Aditya
___________________________________________________________________________________
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] 10+ messages in thread
* Re: random background picture in metafun
2012-03-13 14:45 random background picture in metafun Thomas A. Schmitz
2012-03-13 15:58 ` Aditya Mahajan
@ 2012-03-13 16:33 ` Peter Rolf
2012-03-13 16:56 ` Thomas A. Schmitz
2012-03-13 18:00 ` Aditya Mahajan
1 sibling, 2 replies; 10+ messages in thread
From: Peter Rolf @ 2012-03-13 16:33 UTC (permalink / raw)
To: mailing list for ConTeXt users
Am 13.03.2012 15:45, schrieb Thomas A. Schmitz:
> Hi all,
>
> scenario: for a presentation, I want the background to be a random
> picture, taken from a directory "backgroundpics." The pictures are
> numbered consecutively as 1.jpg through 22.jpg. For some complex
> reasons, it would be easier for me to include these pictures via metafun
> (I want to add other graphical elements on top). So my question is, how
> can I pick a random picture? Given the code
>
> StartPage ;
> draw externalfigure "backgoundpics/1" xscaled PaperWidth yscaled
> PaperHeight ;
> StopPage ;
>
> how can I obtain a random number and make metapost pick the
> corresponding picture? Sorry, difficult to make a minimal example here...
>
(slightly tested)
string mypath, rndfile;
mypath:= "backgroundpics/";
nofpics:= 22;
n:= round(uniformdeviate(nofpics-1)+1);
rndfile:= mypath & decimal n;
HTH, Peter
> Thomas
> ___________________________________________________________________________________
>
> 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
> ___________________________________________________________________________________
>
>
___________________________________________________________________________________
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] 10+ messages in thread
* Re: random background picture in metafun
2012-03-13 16:33 ` Peter Rolf
@ 2012-03-13 16:56 ` Thomas A. Schmitz
2012-03-13 17:09 ` Thomas A. Schmitz
2012-03-13 18:00 ` Aditya Mahajan
1 sibling, 1 reply; 10+ messages in thread
From: Thomas A. Schmitz @ 2012-03-13 16:56 UTC (permalink / raw)
To: mailing list for ConTeXt users
On 03/13/2012 05:33 PM, Peter Rolf wrote:
> string mypath, rndfile;
>
> mypath:= "backgroundpics/";
> nofpics:= 22;
>
> n:= round(uniformdeviate(nofpics-1)+1);
> rndfile:= mypath& decimal n;
>
>
> HTH, Peter
Aditya, Peter,
thank you both for your quick replies! Peter's works wonderfully;
Aditya's untested code throws an error "! Not implemented:
(string)&(known numeric)." I guess this is too arcane for the wiki?
Thanks, and best wishes
Thomas
___________________________________________________________________________________
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] 10+ messages in thread
* Re: random background picture in metafun
2012-03-13 16:33 ` Peter Rolf
2012-03-13 16:56 ` Thomas A. Schmitz
@ 2012-03-13 18:00 ` Aditya Mahajan
2012-03-13 18:24 ` Peter Rolf
1 sibling, 1 reply; 10+ messages in thread
From: Aditya Mahajan @ 2012-03-13 18:00 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Tue, 13 Mar 2012, Peter Rolf wrote:
> Am 13.03.2012 15:45, schrieb Thomas A. Schmitz:
>> Hi all,
>>
>> scenario: for a presentation, I want the background to be a random
>> picture, taken from a directory "backgroundpics." The pictures are
>> numbered consecutively as 1.jpg through 22.jpg. For some complex
>> reasons, it would be easier for me to include these pictures via metafun
>> (I want to add other graphical elements on top). So my question is, how
>> can I pick a random picture? Given the code
>>
>> StartPage ;
>> draw externalfigure "backgoundpics/1" xscaled PaperWidth yscaled
>> PaperHeight ;
>> StopPage ;
>>
>> how can I obtain a random number and make metapost pick the
>> corresponding picture? Sorry, difficult to make a minimal example here...
>>
> (slightly tested)
>
> string mypath, rndfile;
>
> mypath:= "backgroundpics/";
> nofpics:= 22;
>
> n:= round(uniformdeviate(nofpics-1)+1);
Actually, round (uniformdeviate(nopics-1)) does not give equal weightage
to 1 and nofpics. A better solution is
n:= floor(uniformdeviate(nofpics)) + 1;
which gives a uniform weight to all numbers.
> rndfile:= mypath & decimal n;
Aditya
___________________________________________________________________________________
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] 10+ messages in thread
* Re: random background picture in metafun
2012-03-13 18:00 ` Aditya Mahajan
@ 2012-03-13 18:24 ` Peter Rolf
2012-03-15 9:18 ` Thomas A. Schmitz
0 siblings, 1 reply; 10+ messages in thread
From: Peter Rolf @ 2012-03-13 18:24 UTC (permalink / raw)
To: mailing list for ConTeXt users
Am 13.03.2012 19:00, schrieb Aditya Mahajan:
> On Tue, 13 Mar 2012, Peter Rolf wrote:
>
>> Am 13.03.2012 15:45, schrieb Thomas A. Schmitz:
>>> Hi all,
>>>
>>> scenario: for a presentation, I want the background to be a random
>>> picture, taken from a directory "backgroundpics." The pictures are
>>> numbered consecutively as 1.jpg through 22.jpg. For some complex
>>> reasons, it would be easier for me to include these pictures via metafun
>>> (I want to add other graphical elements on top). So my question is, how
>>> can I pick a random picture? Given the code
>>>
>>> StartPage ;
>>> draw externalfigure "backgoundpics/1" xscaled PaperWidth yscaled
>>> PaperHeight ;
>>> StopPage ;
>>>
>>> how can I obtain a random number and make metapost pick the
>>> corresponding picture? Sorry, difficult to make a minimal example
>>> here...
>>>
>> (slightly tested)
>>
>> string mypath, rndfile;
>>
>> mypath:= "backgroundpics/";
>> nofpics:= 22;
>>
>> n:= round(uniformdeviate(nofpics-1)+1);
>
> Actually, round (uniformdeviate(nopics-1)) does not give equal weightage
> to 1 and nofpics. A better solution is
>
> n:= floor(uniformdeviate(nofpics)) + 1;
>
:-)
I used 'floor' in my prior tests, but changed it to 'round' because of
the very small chance of getting the highest number (at least with my
formula).
Let's hope, nobody has wikified my bad maths ;-)
> which gives a uniform weight to all numbers.
>
>> rndfile:= mypath & decimal n;
>
> Aditya
> ___________________________________________________________________________________
>
> 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
> ___________________________________________________________________________________
>
>
___________________________________________________________________________________
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] 10+ messages in thread
* Re: random background picture in metafun
2012-03-13 18:24 ` Peter Rolf
@ 2012-03-15 9:18 ` Thomas A. Schmitz
2012-03-15 18:06 ` Hans Hagen
0 siblings, 1 reply; 10+ messages in thread
From: Thomas A. Schmitz @ 2012-03-15 9:18 UTC (permalink / raw)
To: mailing list for ConTeXt users
On 03/13/2012 07:24 PM, Peter Rolf wrote:
>> Actually, round (uniformdeviate(nopics-1)) does not give equal weightage
>> > to 1 and nofpics. A better solution is
>> >
>> > n:= floor(uniformdeviate(nofpics)) + 1;
>> >
> :-)
>
> I used 'floor' in my prior tests, but changed it to 'round' because of
> the very small chance of getting the highest number (at least with my
> formula).
>
> Let's hope, nobody has wikified my bad maths;-)
>
>
>> > which gives a uniform weight to all numbers.
Hmm, I absolutely stink at math, but after a few days of testing: the
"randomness" is a bit disappointing. All my presentations start more or
less with the same set of background pictures, and since most have < 22
slides, some slides never come up in the rotation. Is there a way to
provide metafun with a random seed, say the decimal digit of pi
corresponding to the rounded number of my cpu's temperature (just
kidding)? Or maybe a lua solution would be nice, metafun seems to be a
bit to conservative in its choice of random numbers...
Thomas
___________________________________________________________________________________
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] 10+ messages in thread
* Re: random background picture in metafun
2012-03-15 9:18 ` Thomas A. Schmitz
@ 2012-03-15 18:06 ` Hans Hagen
2012-03-15 18:23 ` Thomas A. Schmitz
0 siblings, 1 reply; 10+ messages in thread
From: Hans Hagen @ 2012-03-15 18:06 UTC (permalink / raw)
To: mailing list for ConTeXt users; +Cc: Thomas A. Schmitz
On 15-3-2012 10:18, Thomas A. Schmitz wrote:
> On 03/13/2012 07:24 PM, Peter Rolf wrote:
>>> Actually, round (uniformdeviate(nopics-1)) does not give equal weightage
>>> > to 1 and nofpics. A better solution is
>>> >
>>> > n:= floor(uniformdeviate(nofpics)) + 1;
>>> >
>> :-)
>>
>> I used 'floor' in my prior tests, but changed it to 'round' because of
>> the very small chance of getting the highest number (at least with my
>> formula).
>>
>> Let's hope, nobody has wikified my bad maths;-)
>>
>>
>>> > which gives a uniform weight to all numbers.
>
> Hmm, I absolutely stink at math, but after a few days of testing: the
> "randomness" is a bit disappointing. All my presentations start more or
> less with the same set of background pictures, and since most have < 22
> slides, some slides never come up in the rotation. Is there a way to
> provide metafun with a random seed, say the decimal digit of pi
> corresponding to the rounded number of my cpu's temperature (just
> kidding)? Or maybe a lua solution would be nice, metafun seems to be a
> bit to conservative in its choice of random numbers...
Ah, but keep in mind that the random number is stored in the tuc file!
So, as long as that file is not wiped, you get the same random number
initialization. Imagine what would happen if we would not do that. So,
just erase the tuc if you want another seed.
Hans
-----------------------------------------------------------------
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] 10+ messages in thread
* Re: random background picture in metafun
2012-03-15 18:06 ` Hans Hagen
@ 2012-03-15 18:23 ` Thomas A. Schmitz
0 siblings, 0 replies; 10+ messages in thread
From: Thomas A. Schmitz @ 2012-03-15 18:23 UTC (permalink / raw)
To: Hans Hagen; +Cc: mailing list for ConTeXt users
On 03/15/2012 07:06 PM, Hans Hagen wrote:
>
> Ah, but keep in mind that the random number is stored in the tuc file!
> So, as long as that file is not wiped, you get the same random number
> initialization. Imagine what would happen if we would not do that. So,
> just erase the tuc if you want another seed.
Oops, yes of course, that makes sense - all presentations are generated
from the same xml file, so the tuc never changes! After deleting it, I
get more of the desired randomness - thanks a lot for the pointer!
All best
Thomas
___________________________________________________________________________________
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] 10+ messages in thread
end of thread, other threads:[~2012-03-15 18:23 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-13 14:45 random background picture in metafun Thomas A. Schmitz
2012-03-13 15:58 ` Aditya Mahajan
2012-03-13 16:33 ` Peter Rolf
2012-03-13 16:56 ` Thomas A. Schmitz
2012-03-13 17:09 ` Thomas A. Schmitz
2012-03-13 18:00 ` Aditya Mahajan
2012-03-13 18:24 ` Peter Rolf
2012-03-15 9:18 ` Thomas A. Schmitz
2012-03-15 18:06 ` Hans Hagen
2012-03-15 18:23 ` Thomas A. Schmitz
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).