From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/75070 Path: news.gmane.org!not-for-mail From: Peter Rolf Newsgroups: gmane.comp.tex.context Subject: Re: random background picture in metafun Date: Tue, 13 Mar 2012 19:24:22 +0100 Message-ID: <4F5F90D6.5040009@gmx.net> References: <4F5F5DA1.1050202@uni-bonn.de> <4F5F76CC.1090800@gmx.net> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1331663094 22743 80.91.229.3 (13 Mar 2012 18:24:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 13 Mar 2012 18:24:54 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Mar 13 19:24:53 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S7WOz-0004yd-Gf for gctc-ntg-context-518@m.gmane.org; Tue, 13 Mar 2012 19:24:53 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id E46D3CB2A3; Tue, 13 Mar 2012 19:24:52 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id tQvr6l3HpAKz; Tue, 13 Mar 2012 19:24:38 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 749AFCB291; Tue, 13 Mar 2012 19:24:38 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id ED201CB291 for ; Tue, 13 Mar 2012 19:24:37 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3cjQBXQpc6Y6 for ; Tue, 13 Mar 2012 19:24:22 +0100 (CET) Original-Received: from filter2-ams.mf.surf.net (filter2-ams.mf.surf.net [192.87.102.70]) by balder.ntg.nl (Postfix) with ESMTP id CA8A5CB04D for ; Tue, 13 Mar 2012 19:24:22 +0100 (CET) Original-Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.22]) by filter2-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with SMTP id q2DIOL4E032392 for ; Tue, 13 Mar 2012 19:24:22 +0100 Original-Received: (qmail invoked by alias); 13 Mar 2012 18:24:21 -0000 Original-Received: from ip-178-200-60-76.unitymediagroup.de (EHLO [192.168.178.3]) [178.200.60.76] by mail.gmx.net (mp028) with SMTP; 13 Mar 2012 19:24:21 +0100 X-Authenticated: #24293357 X-Provags-ID: V01U2FsdGVkX1/y4/84ePryK/EGUf8QViFcbhakqTUesdUCVnNslw nPEYS0JpbOt7gt User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: X-Enigmail-Version: 1.4 X-Y-GMX-Trusted: 0 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=213.165.64.22; country=DE; latitude=51.0000; longitude=9.0000; http://maps.google.com/maps?q=51.0000,9.0000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0QGJ6omlA - 7b439e11b19b - 20120313 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.70 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:75070 Archived-At: 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 ___________________________________________________________________________________