Ask Your Question
3

3d animation with tachyon

asked 2012-05-17 10:35:17 +0100

Roctiv gravatar image

updated 2012-05-17 10:37:27 +0100

Hello!

I'm trying to create a 3d animations, frame per frame. I've discovered that tachyon plotter is very usefull to create images. But after that, I'm unable to make it as animation.

For example, I have copied a code and generate some scenes with tachyon with this:

saved = []
for j in srange(-0.9,1,0.3):
   t = Tachyon(xres=512,yres=512, camera_center=(3,0.3,0))
   t.light((4,3,2), 0.2, (1,1,1))
   t.texture('t0', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1.0,0,0))
   t.texture('t1', ambient=0.1, diffuse=0.9, specular=0.3, opacity=1.0, color=(0,1.0,0))
   t.texture('t2', ambient=0.2,diffuse=0.7, specular=0.5, opacity=0.7, color=(0,0,1.0))
   k=0
   for i in srange(-1,j,0.05):
      k += 1
      t.sphere((i,i^2-0.5,i^3), 0.1, 't%s'%(k%3))
   saved.append(t)

In "saved" array I have all the png of the animation I want to do, and I can view it with saved[i].show().

I tried to unite all the frames with the command animate:

animate(saved[i].show() for i in range(0,len(saved)))

But it didn't work. What other alternatives do I have? (without using ffmpeg)

Thank you!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
3

answered 2012-05-17 13:19:01 +0100

kcrisman gravatar image

I see. Well, first off, the things in your saved are not actually graphics file, but Tachyon scenes. Secondly, we can access things in the notebook via the DATA variable. Borrowing some ideas from the thread mentioned in the other post:

for i in range(len(saved)):
    saved[i].save(filename=DATA+'mypic%d.png'%i)

os.system('cd '+DATA+'; convert -delay %s -loop %s *.png "Done.gif"'%(int(100),int(2)))
os.system('ls '+DATA)

This shows that the Done.gif is there. If you then go to the "Data..." menu and choose it, you will see it and be able to download it. That's not ideal, but a lot better than nothing.

where to look

Naturally, this all assumes you have animate working properly (because that requires the convert command we are using here). Probably I should also use sage-native-execute but I don't really understand that.

edit flag offensive delete link more

Comments

Thank you!!! That's it! I wanted something simple, because I can only use the notebook (I cannot modify the system). Thank you very much

Roctiv gravatar imageRoctiv ( 2012-05-17 13:35:31 +0100 )edit
1

To the guy who will see this in the future (he could be me tomorrow): that funtion is ok if len(saved) < 10, if it's bigger the names of the should have more digits.

Roctiv gravatar imageRoctiv ( 2012-05-17 13:53:13 +0100 )edit

Oh, maybe I should have used %s instead of %d?

kcrisman gravatar imagekcrisman ( 2012-05-17 14:47:43 +0100 )edit
1

@Roctiv you're right. This should be used instead: 'mypic%02d.png' % i. Then it is ok if len(saved) < 100. You can of course change 02 to something bigger if desired.

Joel Sjögren gravatar imageJoel Sjögren ( 2013-07-08 12:11:12 +0100 )edit
1

answered 2012-05-17 11:53:43 +0100

kcrisman gravatar image

updated 2012-05-17 14:50:26 +0100

You say without ffmpeg, but apparently that's the only obvious way to do it. You might also find Trac 7298 helpful, though apparently that has unresolved issues.

Note that this "answer" is really just Marshall's from the other ask.sagemath.org question.

Edit: Trac 12827 actually is about adding more types to the animate command, such as Tachyon-generated pictures.

edit flag offensive delete link more

Comments

Thank you. I had already seen that answer. But I think, that what I want to do is too simple to attack it with a powerfull tool (that I don't know how to use). I mean, animate function should be enough to join a couple of photgrams... or not?

Roctiv gravatar imageRoctiv ( 2012-05-17 12:04:56 +0100 )edit

It looks like there would be a way to use the code in `animate??` to do this, but as it stands the `animate` command is for animating either 2-D graphics objects or something which can be 2-D plotted. Extending it to do what you want is probably not a bad idea, but would take some work.

kcrisman gravatar imagekcrisman ( 2012-05-17 12:31:48 +0100 )edit

I thought animate function had more freedom to choose the types :(

Roctiv gravatar imageRoctiv ( 2012-05-17 13:41:16 +0100 )edit

No, it's pretty clear in the constructor what it does. Doesn't mean we couldn't add them! See my edit to this answer.

kcrisman gravatar imagekcrisman ( 2012-05-17 14:49:58 +0100 )edit

I wanted to aswer just ":)", but I need 10 chararcters :D

Roctiv gravatar imageRoctiv ( 2012-05-18 12:14:14 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-05-17 10:35:17 +0100

Seen: 1,555 times

Last updated: May 17 '12