Essential Python for the Physicist by Giovanni Moruzzi
Author:Giovanni Moruzzi
Language: eng
Format: epub, pdf
ISBN: 9783030450274
Publisher: Springer International Publishing
7.5 Creating Video Files Under Tkinter
It is often convenient to create video files from our Python animations, both for sending them to friends (or for showing them in conferences), and because animations can involve complex computations between successive frames, causing the program to run very slowly. Unfortunately Tkinter does not have any method equivalent to .FuncAnimation() that we met in Sect. 3.7. The easiest way is using one of the many available programs that record the entire computer screen or a selected part of it.
A good choice for Linux is SimpleScreenRecorder by Maarten Baert. It is easy to install and to use, and has the possibility to reduce the video frame rate if your animation is running too slow due to the complex computations mentioned above. Recording the screen of a Mac is easy if you are using macOS Mojave: just hit the keyboard shortcut Shift+cmd+5 and all the controls for capturing video and still images from your desktop will appear. You can record the whole screen, a section, or a specific window, then trim, save or share the resulting footage. Windows 10 offers the built-in Xbox app, featuring screen capturing tools. Launch the Xbox app, then press the Windows and G icons on the keyboard and choose ’Yes this is a game’ option. If you want to change the video quality or adjust the audio settings, you can do so by opening Game DVR options menu. If you are satisfied with one of the above options, or if you have found another screen-capturing application of your taste, you can skip the rest of Sect. 7.5. Honestly, you are advised to do so.
Creating a video file under Tkinter is possible and absolutely not complicated. However, it is true that it can be somewhat time-consuming, but it is the computer’s time, not necessarily yours! The basic idea is copying each animation frame into a picture file, then merging all the pictures into a single video file with the help of an external program. As we saw in Sect. 6.4.2, the method canvas.postscript() saves the canvas content into an Encapsulated PostScript (eps) file. Thus, if we want to create a video file from Script 7.4, we start by modifying Lines 78–94 as follows
where we have added Lines 79 and 88–91. Variable iFrame, defined at Line 79, is an animation-frame counter. Lines 88–91 are executed only if RunMotion is True (if the ball is moving). Line 89 creates a name for the eps frame picture in the form path/frameXXXXXXXX.eps, where XXXXXXXX is a zero-padded integer number ranging from 0000000000 to 99999999, equal to the frame counter. Actually, in all practical cases, the highest number will be much smaller, since is a very high number of frames. Even running at 50 frames/second, a video comprising frames would last hours! For the path, here we are assuming that you have previously created an empty directory named VideoFrames parallel to your working directory, where the animation frames will be stored. Under Windows all slashes ( / ) in the path must be replaced by backslashes ( ).
Download
Essential Python for the Physicist by Giovanni Moruzzi.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7784)
Autodesk Civil 3D 2024 from Start to Finish by Stephen Walz Tony Sabat(6539)
Mathematics for Game Programming and Computer Graphics by Penny de Byl(6421)
Taking Blender to the Next Level by Ruan Lotter(6201)
Express Your Creativity with Adobe Express by Rosie Sue(6023)
Hands-On Unity 2022 Game Development - Third Edition by Nicolas Alejandro Borromeo(5638)
Hands-On Unity 2022 Game Development by Nicolas Alejandro Borromeo(4754)
Adobe Illustrator for Creative Professionals by Clint Balsar(3679)
Unreal Engine 5 Character Creation, Animation, and Cinematics by Henk Venter & Wilhelm Ogterop(3623)
Going the Distance with Babylon.js by Josh Elster(3592)
Mastering Graphics Programming with Vulkan by Marco Castorina & Gabriel Sassone(3494)
Squeaky Clean Topology in Blender by Michael Steppig(3430)
Drawing Shortcuts: Developing Quick Drawing Skills Using Today's Technology by Leggitt Jim(2915)
Unreal Engine 5 Character Creation, Animation, and Cinematics by Henk Venter Wilhelm Ogterop(2874)
Rapid Viz: A New Method for the Rapid Visualization of Ideas by Kurt Hanks & Larry Belliston(2701)
The 46 Rules of Genius: An Innovator's Guide to Creativity (Voices That Matter) by Marty Neumeier(2657)
Learn Qt 5: Build modern, responsive cross-platform desktop applications with Qt, C++, and QML by Nicholas Sherriff(2365)
Fusion 360 for Makers by Lydia Sloan Cline(2221)
Hands-On Neural Networks with Keras by Niloy Purkait(2168)
