Programming animation

91 views
Skip to first unread message

LFS

unread,
Feb 5, 2012, 11:20:59 AM2/5/12
to sage-support
Hiya!

Is there a relatively simple way to get a point to animate a point
through a cycle keeping in mind my low programming skills ((like
adding a "wait" between iterations?) ?

I made this video with stop animation and an animated gif but it was a
real pain.
http://www.youtube.com/watch?v=2ddeHKk9ssg

Now I really want to show how the parameter moves through 3d curves
(and then surfaces) ....
e.g. I would like to animate a point through the first curve on:
http://sagenb.org/home/pub/4212/

Thanks for any help. Linda

Socius

unread,
Feb 6, 2012, 11:31:10 AM2/6/12
to sage-support
On 5 Feb, 17:20, LFS <lfahlb...@gmail.com> wrote:
> Hiya!
>
> Is there a relatively simple way to get a point to animate a point
> through a cycle keeping in mind my low programming skills ((like
> adding a "wait" between iterations?) ?
>
> I made this video with stop animation and an animated gif but it was a
> real pain.http://www.youtube.com/watch?v=2ddeHKk9ssg
>
> Now I really want to show how the parameter moves through 3d curves
> (and then surfaces) ....
> e.g. I would like to animate a point through the first curve on:http://sagenb.org/home/pub/4212/

Hi Linda.
Recently Jason wrote that they are developing a new framework for the
Slider control in the new versions of Sage. I don't know if that will
allow to directly animate the slider. I hope so, because probably that
would solve your problem. I recently started to experiment a little
with Geogebra, and apart the fact that it is obviously more limited
and less ambitious than Sage, there is a very nice and simple
animation feature for each parameter associated with a slider, really
useful for quickly creating animated graphs.

A.

LFS

unread,
Feb 6, 2012, 12:57:32 PM2/6/12
to sage-support
Thanks A.
That is good to hear about the sage slider!
----
I have to admit that I use GeoGebra for almost everything not 3d. It
is absolutely fantastic (I do videos on the youtube.com/
geogebrachannel and have a wiki and a moodle on ggb.)

But sage is great (and I have started a youtube.com/sagemath channel
and a sage wiki, but they are in their infancy.)
(a) for 3d and
(b) for creating "solvers" because of its linearity which helps kids
focus on the steps.
(c) I really like the "organization" in sage with the text fields and
sage fields.

(I also use scratch to teach my kids to test their probability
results).

Nils Bruin

unread,
Feb 6, 2012, 2:48:17 PM2/6/12
to sage-support
On Feb 5, 8:20 am, LFS <lfahlb...@gmail.com> wrote:
> Hiya!
>
> Is there a relatively simple way to get a point to animate a point
> through a cycle keeping in mind my low programming skills ((like
> adding a "wait" between iterations?) ?

You are probably aware of the "animate" command that does this for 2d
graphics. It really does stop-motion animation, but it automates the
whole process, so it is easy to use. With a bit of surgery you can
adapt the procedure to animate 3d as well. The bit below should work
in your example worksheet. For a non-interactive movie, this will
basically be the way to go. For more interactive things (move the
point by moving a slider), you'd probably want to look at "interact".

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
def scene(f):
return C+point3d(s(t=f*(t2-t1)),size=15,color='purple')
os.mkdir("my_anim")

N=10
for f in [0..N]:
scene(f/N).save("my_anim/frame%s.png"%sage.misc.misc.pad_zeros(f,
8))

delay=1
iterations=10
cmd = '''
cd "my_anim";
sage-native-execute convert -delay %s -loop %s *.png "movie.gif"
'''%(int(delay), int(iterations))
from subprocess import check_call, CalledProcessError

check_call(cmd, shell=True)
os.system("mv my_anim/movie.gif movie.gif; rm my_anim/*; rmdir
my_anim")

% the animated gif movie.gif should now be in the current directory
%(of the notebook cell, if you're using the notebook)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Socius

unread,
Feb 6, 2012, 2:58:37 PM2/6/12
to sage-support
On 6 Feb, 18:57, LFS <lfahlb...@gmail.com> wrote:
> I have to admit that I use GeoGebra for almost everything not 3d. It
> is absolutely fantastic (I do videos on the youtube.com/
> geogebrachannel and have a wiki and a moodle on ggb.)
>
> But sage is great (and I have started a youtube.com/sagemath  channel
> and a sage wiki, but they are in their infancy.)
> (a) for 3d and
> (b) for creating "solvers" because of its linearity which helps kids
> focus on the steps.
> (c) I really like the "organization" in sage with the text fields and
> sage fields.
>
> (I also use scratch to teach my kids to test their probability
> results).

Hi Linda.
Congrats for your activities with Geogebra and now Sage. Do you
publish videos on the official Youtube geogebra channel? I often visit
the channel, and I am surely interested also in new videos about Sage.
Actually my secret (not so) dream is a program with all the modules of
Sage, the simplicity and interactivity (also for animations) of
Geogebra, and a free structure notebook-style as Mathcad. I hope that
both GG and Sage (maybe together one day?) will develop towards that
goal.

Ciao

A.

kcrisman

unread,
Feb 6, 2012, 3:39:08 PM2/6/12
to sage-support, sage-...@googlegroups.com


On Feb 6, 2:58 pm, Socius <ant...@gmail.com> wrote:
> On 6 Feb, 18:57, LFS <lfahlb...@gmail.com> wrote:
>
> > I have to admit that I use GeoGebra for almost everything not 3d. It
> > is absolutely fantastic (I do videos on the youtube.com/
> > geogebrachannel and have a wiki and a moodle on ggb.)
>
> > But sage is great (and I have started a youtube.com/sagemath  channel
> > and a sage wiki, but they are in their infancy.)
> > (a) for 3d and
> > (b) for creating "solvers" because of its linearity which helps kids
> > focus on the steps.
> > (c) I really like the "organization" in sage with the text fields and
> > sage fields.
>
> > (I also use scratch to teach my kids to test their probability
> > results).
>
> Hi Linda.
> Congrats for your activities with Geogebra and now Sage. Do you
> publish videos on the official Youtube geogebra channel? I often visit
> the channel, and I am surely interested also in new videos about Sage.

So you did
http://www.youtube.com/sagemath
? Very interesting! Jason Grout has already been singing your 3D
worksheets' praises.

We do post a lot of videos from Sage Days at YouTube (see
http://www.youtube.co/user/wstein389, William's posted videos), but I
didn't realize someone (LFS) had started a channel. That could be
useful. cc:ing sage-devel - there should be some coordination here
among people who upload videos.

> Actually my secret (not so) dream is a program with all the modules of
> Sage, the simplicity and interactivity (also for animations) of
> Geogebra, and a free structure notebook-style as Mathcad. I hope that
> both GG and Sage (maybe together one day?) will develop towards that
> goal.

Could be hard! But at least you can use Geogebra from within Sage to
some extent because of the web start for GG.

http://flask.sagenb.org/home/pub/87/

A longer-term ticket, with a lot of work on it done already:
http://trac.sagemath.org/sage_trac/ticket/7489

- kcrisman

LFS

unread,
Feb 7, 2012, 6:13:20 AM2/7/12
to sage-support
Hiya all - thanks for all the replies!
@Nils I will definitely try the code and get back to you. I am a very
slow worker ...
@A I am the "voice" of the http://youtube.com/geogebrachannel
(everyone else is mostly the strong silent type :) )
@Kcrisman, et.al. Please write me lfah...@gmail.com for the login if
you want to upload to the youtube sagemath channel. I will organize
playlists and stuff so no worries there.
OM - I just tried pasting the applet code from geogebra into my sage
page - loads slow in the notebook, but seems okay in the published.
Never thought of that! Thanks.
==== Here is link: http://sagenb.org/home/pub/4250 THIS IS COOL!

I have this dream too; I get so annoyed when mathematicians (myself
totally included) spend time forcing our students to learn techniques
that a computer can do, but don't spend time teaching them carefully
and with understanding the techniques a computer cannot do. With
respect to this, I have gotten a bit stuck trying to explain
parameterization and so have slowed down with the sage videos. I will
be back :)

BTW: If I ever use something from somebody without credit, please
write me immediately. Sometimes I get confused about where I find
things.
Best, Linda


On Feb 6, 9:39 pm, kcrisman <kcris...@gmail.com> wrote:
> On Feb 6, 2:58 pm, Socius <ant...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > On 6 Feb, 18:57, LFS <lfahlb...@gmail.com> wrote:
>
> > > I have to admit that I use GeoGebra for almost everything not 3d. It
> > > is absolutely fantastic (I do videos on the youtube.com/
> > > geogebrachannel and have a wiki and a moodle on ggb.)
>
> > > But sage is great (and I have started a youtube.com/sagemath  channel
> > > and a sage wiki, but they are in their infancy.)
> > > (a) for 3d and
> > > (b) for creating "solvers" because of its linearity which helps kids
> > > focus on the steps.
> > > (c) I really like the "organization" in sage with the text fields and
> > > sage fields.
>
> > > (I also use scratch to teach my kids to test their probability
> > > results).
>
> > Hi Linda.
> > Congrats for your activities with Geogebra and now Sage. Do you
> > publish videos on the official Youtube geogebra channel? I often visit
> > the channel, and I am surely interested also in new videos about Sage.
>
> So you didhttp://www.youtube.com/sagemath
> ?  Very interesting!  Jason Grout has already been singing your 3D
> worksheets' praises.
>
> We do post a lot of videos from Sage Days at YouTube (seehttp://www.youtube.co/user/wstein389, William's posted videos), but I

Jason Grout

unread,
Feb 7, 2012, 8:22:10 AM2/7/12
to sage-s...@googlegroups.com
On 2/7/12 5:13 AM, LFS wrote:
> I have this dream too; I get so annoyed when mathematicians (myself
> totally included) spend time forcing our students to learn techniques
> that a computer can do, but don't spend time teaching them carefully
> and with understanding the techniques a computer cannot do. With
> respect to this, I have gotten a bit stuck trying to explain
> parameterization and so have slowed down with the sage videos. I will
> be back :)


I am really curious how you use these worksheets in your teaching.
Classroom demonstrations in a lab? Student work outside of class?

I ask because I am always looking for better ways to use computer tools
to enhance learning.

Thanks,

Jason


Socius

unread,
Feb 7, 2012, 9:00:29 AM2/7/12
to sage-support
On 7 Feb, 12:13, LFS <lfahlb...@gmail.com> wrote:

> OM - I just tried pasting the applet code from geogebra into my sage
> page - loads slow in the notebook, but seems okay in the published.
> Never thought of that! Thanks.
> ==== Here is link:http://sagenb.org/home/pub/4250 THIS IS COOL!

This is really interesting. Actually the GG applet loads quite slowly,
but once loaded works well.
It is very promising for a fully functional integration between the
two packages.
I also read that in these period GG developers are working to include
a Python window, for adding more programming power. Maybe also this
can be a good sign of a common future path.

Ciao

A.

LFS

unread,
Feb 7, 2012, 6:34:17 PM2/7/12
to sage-support
Hiya Jason,
It really depends and certainly I am no expert. And probably most of
this is boring so feel free to ignore.

As I said above, I use a combination of GeoGebra and Scratch and Sage
and I am just starting with sage.
I would say that MY most important use of the worksheets in SAGE has
been to help ME understand the material and find an understandable way
to teach it. A friend in mathfuture forum quoted somebody saying
something like "If I can explain it to a computer, then I understand
it". That is EXACTLY how I feel.

With respect to students: Mostly classroom demonstration via an LCD
projector.
My rule 1: Build the applet/worksheet in class so they don't think its
magic. I rarely show "ready-to-use" stuff unless I have built the
basic model first.
My rule 2: Make sure they understand the stuff that no computer will
do for you. Then if the curriculum requires that we solve the
"computer part" by hand, show them how to check it using the applet/
worksheet.

Given this:
The 3D Line and Surface Integrals, Vector Calculus stuff is for my son
and daughter-in-law. Neither of them does the sage. They watch me do
it :)
He is studying chemical engineering and hates this math because he
sees no use for it (and like many boys and men refuses to learn
something he doesn't understand). He likes the visuals and it connects
to understanding.
But even my daughter-in-law (who is a very dedicated electrical
engineering student) was horribly frustrated by this material. She got
A's on the tests and said she didn't know what she was doing. The sage
demos helped.
---
I have been doing this for them for awhile. Usually, I try to make a
combination of short youtube videos, worksheets with lots of graphic
explanations, solvers, applets/ interactivities.
Once I make them, I tend to post them online and usually get decent
feedback and views (nothing like khan of course...). I try to do some
in english and macedonian so there is often an odd combination of
resources :)

In my math undergraduate courses, I tend to just do in-class demos. (I
currently teach Calc1 and Calc2, so e.g. I show them how do calculate
Taylor polynomials and then draw both functions so they see if, where,
how approximation works.)
I tried integrating IT into the grading, but I have huge class sizes
and that wasn't working.
They love to look at the 3d stuff so I do show the sage stuff in class
as reward for good behavior :)

In my math modelling courses (smaller), I hold online classes (in
macedonian) and my kids have to create a variety of (usually geogebra)
worksheets and then make little videos about what they learn. It
usually takes twice as long as you think it will :)
In my graduate courses, I do in-class demos and then assign "similar"
problems where they create worksheets themselves. (This is mostly
probability and statistics to IT engineers and we use scratch.)
and on and on i go.... Linda

LFS

unread,
Feb 8, 2012, 12:09:43 PM2/8/12
to sage-support
@Nils
Got the animation to work - Really pleased! (Momentarily nothing will
publish - when it does I will add the link.)
Thanks for writing the script so simply. I was able to change things I
wanted to change.
BTW - if anyone copies and pastes the script from above, there is an
bad line break after "rmdir" that forces an error.
Thanks. Linda

Message has been deleted

LFS

unread,
Feb 9, 2012, 4:46:39 AM2/9/12
to sage-support
Hiya
I have now managed to publish a working version of the 3d animation:
http://test.sagenb.org/home/pub/33/
However, the code appears to cause some problems with respect to the
publisher.
== I could not publish at all from sagenb (I checked - I could
publish other sage worksheets without animation).
== Even on the beta, I cannot make any changes to the worksheet that
transfer to the published version (i.e. no official "save"). I either
get a "failed to save" or "internal server error".
Hence the 2 published versions on test. Version 32 can be deleted - it
doesn't work. (I copied the text of the working code into a new
worksheet, immediately saved and published; after that no changes were
allowed to be saved :).)

@Nils
Is there a way to have a delay between iterations of the whole cycle?
Thanks!

Thank-you all for your support. Linda

Jason Grout

unread,
Feb 9, 2012, 4:07:43 PM2/9/12
to sage-s...@googlegroups.com
On 2/9/12 3:46 AM, LFS wrote:
> == I could not publish at all from sagenb (I checked - I could
> publish other sage worksheets without animation).

The problem was that the notebook wasn't correctly handling things when
you delete a file in the cell.
https://github.com/sagemath/sagenb/commit/25aadd9eec6439cbacf9be5f76647079080bed12
should fix this problem. I'll push it out to sagenb.org after we've
verified that the big changes from yesterday are not causing any issues.

Thanks,

Jason


Nils Bruin

unread,
Feb 9, 2012, 9:19:38 PM2/9/12
to sage-support
On Feb 9, 1:46 am, LFS <lfahlb...@gmail.com> wrote:
> Is there a way to have a delay between iterations of the whole cycle?
> Thanks!

It looks like animated GIFs in principle allow for a duration to be
specified for each frame indiviually, so the answer is yes in
principle:

http://en.wikipedia.org/wiki/Graphics_Interchange_Format#Animated_GIF

I have no idea whether ImageMagick (to which the "convert" command
belongs) supports specifying it, though. If it does, you should
probably do something like:

convert -delay 100 frame001.png ... frame48.png -delay 500 frame49.png
movie.gif

If that doesn't work you could of course put the last frame in with a
higher multiplicity to make it seem like the animation is waiting
before starting again.

Another thing is that for longer animations, an animated GIF is
probably not the best format. You should probably use something that
can collate a bunch of frames into an mpeg movie or similar. I am sure
there are command-line programs for that which would allow you to take
the same approach as with "convert". Good luck!

Jonathan Bober

unread,
Feb 10, 2012, 1:53:09 AM2/10/12
to sage-s...@googlegroups.com
On Thu, Feb 9, 2012 at 6:19 PM, Nils Bruin <nbr...@sfu.ca> wrote:

Another thing is that for longer animations, an animated GIF is
probably not the best format. You should probably use something that
can collate a bunch of frames into an mpeg movie or similar. I am sure
there are command-line programs for that which would allow you to take
the same approach as with "convert". Good luck!


I usually use mencoder for animations. I almost always need to look up command syntax, so here is the same example, except it makes a 10 second avi with 100 frames. One note about this, though: I feel like mencoder often (always?) produces avi files that many programs can't understand. There are probably some command line options which will fix the format, but I think my current strategy is to use HandBrake after mencoder to convert the movie to a different format. 

Another note: for this sort of thing I find @parallel to be great. (Except it won't really help here because the bottleneck is Tachyon, which is already multithreaded and, at least on my desktop, already hits all my cpus at 100%.)

##########
var('t')

s = vector((2*cos(t)^2,3*sin(t),2*t))
t1 = 0
t2 = 4*pi
C = parametric_plot(s,(t,t1,t2),color='orange',thickness=6, opacity=.7)
def scene(f):
   return C + point3d(s(t=f*(t2-t1)),size=15,color='purple')

os.mkdir("my_anim")

number_of_frames = 100

for frame_number in range(number_of_frames):
   scene(frame_number/number_of_frames).save("my_anim/frame%s.png"%sage.misc.misc.pad_zeros(frame_number,8))

frames_per_second = 10
cmd = '''cd "my_anim"; sage-native-execute mencoder "mf://*.png" -mf fps=%d -ovc lavc -o movie.avi '''% int(frames_per_second)
from subprocess import check_call, CalledProcessError

check_call(cmd, shell=True)
os.system("mv my_anim/movie.avi movie.avi; rm my_anim/*; rmdir my_anim")
##########

(I had no idea if this would work on sagenb.org, so I tried, and it does. Sure enough, though, the output of mencoder is some format that Chrome won't play. I can download the movie and play it locally, though, and maybe some other web browsers would play it.)

Vegard Lima

unread,
Feb 10, 2012, 2:55:59 AM2/10/12
to sage-s...@googlegroups.com
On Fri, Feb 10, 2012 at 7:53 AM, Jonathan Bober <jwb...@gmail.com> wrote:
> os.system("mv my_anim/movie.avi movie.avi; rm my_anim/*; rmdir my_anim")
> ##########
>
> (I had no idea if this would work on sagenb.org, so I tried, and it does.
> Sure enough, though, the output of mencoder is some format that Chrome won't
> play. I can download the movie and play it locally, though, and maybe some
> other web browsers would play it.)

Very nice example. I tried adding the line (locally, didn't try on sagenb.org)

os.system("ffmpeg -i movie.avi movie.webm")

and then I got a webm file that at least firefox plays without problem.
For some reason it didn't work in Chromium, which is kind of odd.


Cheers,
--
Vegard Lima

David Joyner

unread,
Feb 10, 2012, 9:27:08 AM2/10/12
to sage-s...@googlegroups.com
These would make great examples for the sage wiki!

> --
> To post to this group, send email to sage-s...@googlegroups.com
> To unsubscribe from this group, send email to sage-support...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org

Jason Grout

unread,
Feb 11, 2012, 7:44:24 AM2/11/12
to sage-s...@googlegroups.com
On 2/9/12 3:46 AM, LFS wrote:
> == I could not publish at all from sagenb (I checked - I could
> publish other sage worksheets without animation).

My fix is live on sagenb.org now, so you should be able to publish that
worksheet.

Thanks,

Jason


Reply all
Reply to author
Forward
0 new messages