1 Jun 2011 05:48

### Re: turningnumber revisited

At 12:19 PM 5/31/2011, Dan Luecking wrote:
>At 04:30 AM 5/31/2011, Boguslaw Jackowski wrote:
>
>>Dear colleagues,
>>
>>I was nearly sure that the problem of turningnumber has
>>gone forever... Alas, the simple example below shows that the
>>implementation of the turningnumber primitive needs fixing:
>>
>>%%%% BEGIN turnpath.mp
>>path p;
>>p=origin .. controls (100,200) and (300,500) ..
>>   (0,500) .. controls (-300,500) and (-100,200) ..
>>   origin & cycle;
>>for i:=0 upto 8: show turningnumber(p rotated 45i); endfor
>>end.
>>%%%% END turnpath.mp
>>
>>A 2-node, 4-control path above should have the turningnumber=1.
>>And this is the case with MF; with MP, however, the result depends
>>on the rotation of the path.
>>
>>MP 1.211 and MP 1.503 produce the result
>>
>>   >> -1
>>   >> -1
>>   >> -1
>>   >> 1
>>   >> 1
>>   >> 1


1 Jun 2011 07:03

### Re: turningnumber revisited


On 06/01/11 05:48, Dan Luecking wrote:
>
> On second thought, further testing show such consistency
> (when the sign is wrong, the starting angle is in (0,180])
> that this feels more like a simple bug that somehow imposes
> an incorrect sign in just that case, perhaps its even just a typo.

It should be something simple indeed.

Best wishes,
Taco

--
http://tug.org/metapost/


4 Jun 2011 06:55

### Re: turningnumber revisited


Hi all,

Which MP (or MF) paths are now claimed to have a well
defined 'turningnumber'? And what are the properties
asserted for the turning number function?
And who cares?

Taco > It should be something simple indeed.

Laurent S.

PS. I could venture reasonable answers for those paths
that are end-to-end composed of nowhere singular
b'eziers paths that abut at nonzero angles.

--
http://tug.org/metapost/


11 Jun 2011 08:18

### Animated graphics with Metapost?

I'd like to make an incremental version of a drawing, i.e.
when displayed it starts of with just a line and gradually
adds more lines, points, color fill-ins etc, which one can
then display as an animation.

I've thought of this approach:

1. Make a Metapost drawing of each stage, with the visible parts
in black and the not-yet visible parts white.  This is the
same drawing each time with only the colors varying so that
there is no problem about superimposing frames of different size.
2. Import the Postscript files into GIMP and get it to make them
into an animated GIF.

Questions:

1. If you straight off know amuch better way, please tell me.
2. For stage 1, is there a way in which I can implement the
following algorithm in Metapost?

a. Draw everything in white
b. for k=1 to n, draw k-th stage in black and export current
version of the drawing as postscript.

Dirk
--
http://tug.org/metapost/


11 Jun 2011 08:44

### Re: Animated graphics with Metapost?

Am 11.06.2011 um 08:18 schrieb Dirk Laurie:

I'd like to make an incremental version of a drawing, i.e.
when displayed it starts of with just a line and gradually
adds more lines, points, color fill-ins etc, which one can
then display as an animation.

I've thought of this approach:

1. Make a Metapost drawing of each stage, with the visible parts
in black and the not-yet visible parts white.  This is the
same drawing each time with only the colors varying so that
there is no problem about superimposing frames of different size.
2. Import the Postscript files into GIMP and get it to make them
into an animated GIF.

Questions:

1. If you straight off know amuch better way, please tell me.
2. For stage 1, is there a way in which I can implement the
following algorithm in Metapost?

a. Draw everything in white
b. for k=1 to n, draw k-th stage in black and export current
version of the drawing as postscript.

LaTeX and ConTeXt provide mechanism to generate animations in

For LaTeX the animate [1] package is necessary while ConTeXt
doesn’t need extra packages, there is a example in the MetaFun
manual [2] on page 296 ff.

Wolfgang

--
http://tug.org/metapost/
11 Jun 2011 09:30

### Re: Animated graphics with Metapost?

On Sat, Jun 11, 2011 at 8:18 AM, Dirk Laurie <dpl <at> sun.ac.za> wrote:
> I'd like to make an incremental version of a drawing, i.e.
> when displayed it starts of with just a line and gradually
> adds more lines, points, color fill-ins etc, which one can
> then display as an animation.
>
> I've thought of this approach:
>
> 1. Make a Metapost drawing of each stage, with the visible parts
>    in black and the not-yet visible parts white.  This is the
>    same drawing each time with only the colors varying so that
>    there is no problem about superimposing frames of different size.
> 2. Import the Postscript files into GIMP and get it to make them
>    into an animated GIF.
>
> Questions:
>
> 1. If you straight off know amuch better way, please tell me.
> 2. For stage 1, is there a way in which I can implement the
>    following algorithm in Metapost?
>
>    a. Draw everything in white
>    b. for k=1 to n, draw k-th stage in black and export current
>        version of the drawing as postscript.
>
> Dirk
> --
> http://tug.org/metapost/
>

You can also use MetaPost to make swf animations
http://melusine.eu.org/syracuse/metapost/animations/chupin/?idsec=devcercle

--

--
luigi

--
http://tug.org/metapost/
11 Jun 2011 11:37

### Re: Animated graphics with Metapost?

luigi scarso napsal(a):
> On Sat, Jun 11, 2011 at 8:18 AM, Dirk Laurie <dpl <at> sun.ac.za> wrote:
>> I'd like to make an incremental version of a drawing, i.e.
>> when displayed it starts of with just a line and gradually
>> adds more lines, points, color fill-ins etc, which one can
>> then display as an animation.
>>
>> I've thought of this approach:
>>
>> 1. Make a Metapost drawing of each stage, with the visible parts
>>    in black and the not-yet visible parts white.  This is the
>>    same drawing each time with only the colors varying so that
>>    there is no problem about superimposing frames of different size.

In that stage it is not necessary to draw whole  image  in white,
you can keep only its bounding box and then use it with every next
picture (see mpman.pdf, bbox macro, then use setbounds for every
partial picture).

Now you can define a sequence of pictures:

picture p[];
path bb;

p1:=image(...first drawing..);
...
p<number>:=image(last part of drawing);

Finally you can produce a sequence of final PS pictures:

beginfig(0); %% the whole picture for the common bbox
for k=1 upto <number>: draw p[k]; endfor
bb:=bbox(currentpicture);
endfig;

for $=1 upto <number>: beginfig($); for k=1 upto \$: draw p[k]; endfor
setbounds currentpicture  to bb;
endfig;
endfor

>> 2. Import the Postscript files into GIMP and get it to make them
>>    into an animated GIF.
>>

There are many ways how to convert resulting PS files into one
animation.

Happy mposting,
Karel Horak
--
http://tug.org/metapost/


11 Jun 2011 18:30

### Re: Animated graphics with Metapost?

2011/6/11 luigi scarso <luigi.scarso <at> gmail.com>:
> You can also use MetaPost to make swf animations
> http://melusine.eu.org/syracuse/metapost/animations/chupin/?idsec=devcercle

This nice but doesn't explain how to get swf out of mp...

Best
Martin
--
http://tug.org/metapost/


11 Jun 2011 19:24

### Re: Animated graphics with Metapost?

Martin,

I generated this SWF a while back using MetaPost.

http://www.tlhiv.org/tmp/ellipse.swf

Basically, I drew each frame of the animation programmatically (as
previously suggested).  The key to making the animations work like you
expect them to is (as suggested) to have the BoundingBox of each frame
be the same.  You can do this explicitly in MetaPost by the command

setbounds currentpicture to p;

where p is a path (I would assume preferably a rectangular path).

Once this is done, you can include each of these MPS/EPS files into a
LaTeX document and create a single PDF in which each page is exactly
the size it should be and contain a single graphic.  I will provide
the code for this at the end of this message.

You can then convert this PDF to SWF using SWFtools by

pdf2swf foo.pdf foo.swf

The only thing you might want to do after converting to this SWF is to
change the delay between frames.  This can be accomplished by (again
with SWFtools)

swfcombine -dr <fps> foo.swf -o bar.swf

where <fps> is the number of frames per second you want in the animation.

Below is the code for the aforementioned ellipse.  It creates a LaTeX
file automatically, but you have to execute PDFLaTeX on the file
followed by the pdf2swf and swfcombine commands (which it tells you to
do in the MetaPost output).

Troy

----

N:=64; % Number of frames in the animation
T:=4; % Approximate time (in seconds) to complete an animation cycle
u:=136; % Maximum height/width of ellipse (in PostScript points)

pair f;
if c<1: f:=(1+-+c,0); v:=u/2; else: f:=(0,1+-+(1/c)); v:=u/c/2; fi; %
Focus f is defined
path p,q;
picture base;
beginfig(0);
p:=fullcircle yscaled c; % This is the ellipse
draw p scaled (2*v) withpen pencircle scaled (v/260) dashed evenly; %
Draw the ellipse dashed (will be traced later)
input mp-tool;
q:=bbox currentpicture enlarged (v/64); % Enlarge the bounding box slightly
fill fullcircle scaled (v/32) shifted (f*v) withcolor red; % Focus
fill fullcircle scaled (v/32) shifted (-f*v) withcolor red; % Focus
base:=currentpicture; % Save this picture to draw in every frame
setbounds currentpicture to q; % Set the bounding box as described before
endfig;
W:=ceiling(xpart urcorner q - xpart llcorner q)+1; % The width to pass to LaTeX
H:=ceiling(ypart urcorner q - ypart llcorner q)+1; % The height to pass to LaTeX

write "\documentclass{minimal}" to jobname & ".ltx";
write "\usepackage[paperwidth=" & decimal(W) & "bp,paperheight=" &
decimal(H) & "bp,margin=0bp,noheadfoot]{geometry}" to jobname &
".ltx";
write "\usepackage{graphicx}" to jobname & ".ltx";
write "\usepackage{ifpdf}\ifpdf\DeclareGraphicsRule{*}{mps}{*}{}\fi"
to jobname & ".ltx";
write "\usepackage[pdfstartview=Fit,bookmarks=false]{hyperref}" to
jobname & ".ltx";
write "\begin{document}" to jobname & ".ltx";
write "\noindent\includegraphics{" & jobname & ".0}\clearpage" to
jobname & ".ltx";

L:=length p; % Length (in "time") of the ellipse curve
pair z;
for n=1 upto (N-1): % Generate each frame of the animation
beginfig(n);
fill q withcolor 0.99*white;
draw base; % Draw the common picture saved above
draw subpath (0,(n-1)/(N-1)*L) of p scaled (2*v) withpen pencircle
scaled (v/130) withcolor blue; % Trace the ellipse in blue
z:=point ((n-1)/(N-1)*L) of p scaled v; % The point on the ellipse
where we are thusfar
fill fullcircle scaled (v/32) shifted (2*z) withcolor blue; % Draw the point
draw (-f*v)--(2*z)--(f*v) withpen pencircle scaled (v/260); % Draw
the string used to trace the ellipse
setbounds currentpicture to q; % Set the bounding box so that it is
the same for each frame
endfig;
write "\noindent\includegraphics{" & jobname & "." & decimal(n) &
"}\clearpage" to jobname & ".ltx"; % Update LaTeX file
endfor;
write "\end{document}" to jobname & ".ltx"; % Finish up the LaTeX file

message " ";
message "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
message "Execute the following commands to generate the animation:";
message " ";
message "pdflatex " & jobname & ".ltx";
message "pdf2swf " & jobname & ".pdf";
message "swfcombine -dr " & decimal(max(min(ceiling(N/T),255),1/255))
& " " & jobname & ".swf -o " & jobname & ".swf";
message " ";
message "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
message " ";

end

Attachment (ellipse.mp): application/octet-stream, 3681 bytes
--
http://tug.org/metapost/
12 Jun 2011 00:41

### Re: Animated graphics with Metapost?

On Sat, Jun 11, 2011 at 6:30 PM, Martin Schröder <martin <at> oneiros.de> wrote:
> 2011/6/11 luigi scarso <luigi.scarso <at> gmail.com>:
>> You can also use MetaPost to make swf animations
>> http://melusine.eu.org/syracuse/metapost/animations/chupin/?idsec=devcercle
>
> This nice but doesn't explain how to get swf out of mp...
>
> Best
>   Martin
Ah now I've seen that you were not in Brejlov last year..
http://meeting.contextgarden.net/2010/talks/2010-09-17-luigi-flash/

--

--
luigi

--
http://tug.org/metapost/

Gmane