* Buffered metapost function freezes random numbers
@ 2016-05-25 17:09 DesdeChaves
2016-05-25 17:30 ` Wolfgang Schuster
2016-05-27 9:19 ` Hans Hagen
0 siblings, 2 replies; 4+ messages in thread
From: DesdeChaves @ 2016-05-25 17:09 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 1791 bytes --]
For educational purposes I try to simulate a ammeter for reading practice.
I would like create six or more ammeter with different readings, but i'm
not able to do that because metapost create the same random number every
time I call the buffer that defines my ammeter.
How can I fix that?
Thanks
Jorge
My code:
\startbuffer[ammeter]
\startMPcode
r := 4cm; len := 10bp; min_thickness := 1.75bp; hour_thickness := 3bp;
path cadran; cadran = fullcircle scaled (2r);
numeric escala;
escala := 0;
for i = 50 upto 70:
if i mod 5 = 0:
j := i div 5; angl := 90-30j;
freelabel("\tfb\bf" & decimal escala, (r+len)*dir angl, r*dir
angl);
draw ((r, 0) -- (r - len, 0)) rotated angl withpen pencircle
scaled min_thickness;
escala:= escala + 0.5;
else:
angl := 90 - 6i;
draw ((r, 0) -- (r - .5len, 0)) rotated angl;
fi
endfor
pickup pencircle scaled min_thickness;
numeric minute;
%randomseed := uniformdeviate infinity;
minute:= 50 + uniformdeviate(20);
pair A, B, C;
A:=1.6r*right+.5r*up;
C:=1.6r*right+.8r*up;
B:=1.1r*left;
drawarrow origin -- r*dir(90-minute*6) cutends (0, 1.5len);
fill fullcircle scaled .75len;
draw unitsquare xscaled 3.2r yscaled 1.5r shifted B;
label("\tfb I (A)", 1.2r*up+1.6r*right) withcolor red;
draw fullcircle scaled 2len shifted A;
draw fullcircle scaled 2len shifted C;
\stopMPcode
\stopbuffer
\startbuffer[programa]
\placefigure[center,nonumber]{}{
\startcombination[2*1]
{\externalfigure[ammeter][type=buffer,width=8cm]}{\_\_\_\_\_\_\_\_\_\_$\pm$\_\_\_\_\_\_\_\_}
{\externalfigure[ammeter][type=buffer,width=8cm]}{\_\_\_\_\_\_\_\_\_\_$\pm$\_\_\_\_\_\_\_\_}
}
\stopcombination
\stopbuffer
\starttext
\dorecurse{3} {\getbuffer[programa]}
\stoptext
[-- Attachment #1.2: Type: text/html, Size: 2743 bytes --]
[-- Attachment #2: output.pdf --]
[-- Type: application/pdf, Size: 11302 bytes --]
[-- Attachment #3: Type: text/plain, Size: 485 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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Buffered metapost function freezes random numbers
2016-05-25 17:09 Buffered metapost function freezes random numbers DesdeChaves
@ 2016-05-25 17:30 ` Wolfgang Schuster
2016-05-25 17:44 ` DesdeChaves
2016-05-27 9:19 ` Hans Hagen
1 sibling, 1 reply; 4+ messages in thread
From: Wolfgang Schuster @ 2016-05-25 17:30 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 524 bytes --]
> DesdeChaves <mailto:desdechaves@gmail.com>
> 25. Mai 2016 um 19:09
> For educational purposes I try to simulate a ammeter for reading
> practice.
> I would like create six or more ammeter with different readings, but
> i'm not able to do that because metapost create the same random number
> every time I call the buffer that defines my ammeter.
>
> How can I fix that?
Is there a reason why you use \externalfigure because the width can be
set with \scale, e.g.
\scale[width=8cm]{\getbuffer[ammeter]}
Wolfgang
[-- Attachment #1.2: Type: text/html, Size: 1627 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 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://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Buffered metapost function freezes random numbers
2016-05-25 17:09 Buffered metapost function freezes random numbers DesdeChaves
2016-05-25 17:30 ` Wolfgang Schuster
@ 2016-05-27 9:19 ` Hans Hagen
1 sibling, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2016-05-27 9:19 UTC (permalink / raw)
To: mailing list for ConTeXt users
On 5/25/2016 7:09 PM, DesdeChaves wrote:
> For educational purposes I try to simulate a ammeter for reading practice.
> I would like create six or more ammeter with different readings, but i'm
> not able to do that because metapost create the same random number every
> time I call the buffer that defines my ammeter.
>
> How can I fix that?
>
> Thanks
>
> Jorge
>
> My code:
>
>
> \startbuffer[ammeter]
> \startMPcode
> r := 4cm; len := 10bp; min_thickness := 1.75bp; hour_thickness := 3bp;
> path cadran; cadran = fullcircle scaled (2r);
> numeric escala;
> escala := 0;
> for i = 50 upto 70:
> if i mod 5 = 0:
> j := i div 5; angl := 90-30j;
> freelabel("\tfb\bf" & decimal escala, (r+len)*dir angl, r*dir
> angl);
> draw ((r, 0) -- (r - len, 0)) rotated angl withpen pencircle
> scaled min_thickness;
> escala:= escala + 0.5;
> else:
> angl := 90 - 6i;
> draw ((r, 0) -- (r - .5len, 0)) rotated angl;
> fi
> endfor
> pickup pencircle scaled min_thickness;
> numeric minute;
> %randomseed := uniformdeviate infinity;
> minute:= 50 + uniformdeviate(20);
> pair A, B, C;
> A:=1.6r*right+.5r*up;
> C:=1.6r*right+.8r*up;
> B:=1.1r*left;
> drawarrow origin -- r*dir(90-minute*6) cutends (0, 1.5len);
> fill fullcircle scaled .75len;
> draw unitsquare xscaled 3.2r yscaled 1.5r shifted B;
> label("\tfb I (A)", 1.2r*up+1.6r*right) withcolor red;
> draw fullcircle scaled 2len shifted A;
> draw fullcircle scaled 2len shifted C;
> \stopMPcode
> \stopbuffer
>
>
>
> \startbuffer[programa]
>
> \placefigure[center,nonumber]{}{
> \startcombination[2*1]
> {\externalfigure[ammeter][type=buffer,width=8cm]}{\_\_\_\_\_\_\_\_\_\_$\pm$\_\_\_\_\_\_\_\_}
> {\externalfigure[ammeter][type=buffer,width=8cm]}{\_\_\_\_\_\_\_\_\_\_$\pm$\_\_\_\_\_\_\_\_}
> }
> \stopcombination
\stopcombination in wrong spot
> \stopbuffer
>
>
> \starttext
>
> \dorecurse{3} {\getbuffer[programa]}
>
> \stoptext
disable object reuse
\startplacefigure
\startcombination[2*1]
{\externalfigure[ammeter][type=buffer,object=no,width=8cm]}{\_\_\_\_\_\_\_\_\_\_$\pm$\_\_\_\_\_\_\_\_}
{\externalfigure[ammeter][type=buffer,object=no,width=8cm]}{\_\_\_\_\_\_\_\_\_\_$\pm$\_\_\_\_\_\_\_\_}
\stopcombination
\stopplacefigure
\stopbuffer
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | 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] 4+ messages in thread
end of thread, other threads:[~2016-05-27 9:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-25 17:09 Buffered metapost function freezes random numbers DesdeChaves
2016-05-25 17:30 ` Wolfgang Schuster
2016-05-25 17:44 ` DesdeChaves
2016-05-27 9:19 ` Hans Hagen
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).