2D animation in Python

I'm writing a simulator in Python, and am curious about options and opinions regarding basic 2D animations. By animation, I'm referring to rendering on the fly, not displaying prerendered images.

I'm currently using matplotlib (Wxagg backend), and it's possible that I'll be able to continue using it, but I suspect it won't be able to sufficiently scale in terms of performance or capabilities.

Requirements are:

  • Cross-platform (Linux, MacOS X, Windows)
  • Low complexity overhead
  • Plays well with wxpython (at least won't step on each other's toes unduly)
  • Interactivity. Detect when objects are clicked on, moused over, etc.

Note that high performance isn't on the list, but the ability to handle ~100 bitmap objects on the screen would be good.

Your thoughts?


Asked by: Julian736 | Posted: 01-10-2021






Answer 1

I am a fan of pyglet which is a completely self contained library for doing graphical work under win32, linux, and OS X.

It has very low overhead, and you can see this for yourself from the tutorial on the website. It should play well with wxpython, or at least I seem to recall posts to the mailing list about wxpython and pyglet being used together.

It however does not offer selection of objects via mouse clicks - this you will have to handle yourself. Generally speaking for a 2D application this is not too difficult to do.

mactorii is an OS X application of mine written in pure python+pyglet, and has some basic animation (scrolling) and click detection. It doesn't use wxpython, but perhaps it will give you an idea of what is involved. Note however mactorii is using the old pyglet api, so the run loop I have in there is obsolete. I will get around to updating it one day... :P

Answered by: Marcus964 | Posted: 02-11-2021



Answer 2

You can try pygame, its very easy to handle and similar to SDL under c++

Answered by: Leonardo795 | Posted: 02-11-2021



Answer 3

Arcade works on any platform with OpenGL 3.3+ (i.e. not the Raspberry Pi, but most other platforms). Although it's intended for simple games, Arcade offers great bitmap and sprite handling, as well as simple graphics primitives such as rectangles, arcs and circles.

Answered by: Kellan755 | Posted: 02-11-2021



Similar questions

Python Animation Timing

I'm currently working on sprite sheet tool in python that exports the organization into an xml document but I've run into some problems trying to animate a preview. I'm not quite sure how to time the frame rate with python. For example, assuming I have all of my appropriate frame data and drawing functions, how would I go about coding the timing to display it at 30 frames per second (or any other arbitrary rate).


python - How can I speed up an animation?

I'm trying to create a Matplotlib animation of my paw data, where you can see the pressure distribution on the entire pressure plate over time (256x64 sensors for 250 frames). I found a working example on Matplotlib's own site


animation - Error in python script

I wrote a python script to make an animation but when I run it I get the error AttributeError: 'module' object has no attribute 'ion' Here is the script: import numpy as np import pylab as pl data = np.loadtxt( "random.dat" ) pl.ion() M = len( data[0] )-1 N = len( data[:,0] ) line , = pl.plot( data[0,1:] , pl.ones( M ) , 'o' ) for i in xrange( 1 , N ): ...


python - Motion Animation

I have a project in Python 2.7 and PyGTK 2.24. I am using the following code to create a motion animation of a gtk.Image inside a gtk.Fixed. def fishmove(): global fishmove if fishmove < 640: fishmove = fishmove + 10 fixed_hab.move(fish1, fishmove, 50) gobject.timeout_add(1, fishmove) However, while the program comes up without throwin...


python - Why does my pylab animation slow down with each update?

I'd like to display a simple animation by calling imshow in a for loop. Here's a demo of my problem: import pylab,time images = [pylab.uniform(0,255,(50,50)) for _ in xrange(40)] pylab.ion() timings = [] for img in images: tic = time.time() pylab.imshow(img) pylab.draw() toc = time.time() timings.append(toc-tic) pylab.clf() pylab.plot(timings) pylab.title('elapsed time per iteration')...


python - How to draw a line with animation in PyQt4

I have a list of points. For example, points = [[160, 75], [115, 567]]. How to draw a line in PyQt4, so it would be something like this: Thanks in advance. EDIT: For the record, I'm trying to implement Bezier Curves, so it looked like this:


python - pygame circle animation

I'm trying to make a circle animation and want it to bounce inside the window just for practice. I was told that pygame.draw.rect returns a Rect object, however, I made this little code to see if it worked, and it didn't. The circle didn't move downwards one pixel per iteration like expected. What might be the problem? import pygame, sys from pygame.locals import * pygame.init() s...


python - Is there a simple way to make and save an animation with Pygame?

I made a very simple fractal generator that prints out each step; I want to put it in a presentation I made. The tool with which I'm making the presentation obviously doesn't support pygame, is there any way to save it as a video? Preferably as an animated .gif or the like.


python - How to create an animation in a QtGui?

I'm fairly new to Python and Qt, but I'm trying to create a GUI with some animated graphic elements. I can make a simple animation work; in the following code class MyView will work when called, but class GraphicsView is not animated! Can anyone help me see the problem? The problem is in the class GraphicsScene, I think: import sys from PyQt4 import QtGui, QtCore c...


python - PyQT4 and tiles animation

I'm just started to learn PyQT4. How to define a class, whose instances will be animated images? I have a few png files, so I'd like that object to render one such file in one moment and other file in other moment in a loop. Should I use QMovie, or Qt Animation Framework, or what? Thanks!


animation - What is the fastest way to scale and display an image in Python?

I am required to display a two dimensional numpy.array of int16 at 20fps or so. Using Matplotlib's imshow chokes on anything above 10fps. There obviously are some issues with scaling and interpolation. I should add that the dimensions of the array are not known, but will probably be around thirty by four hundred. These are data from a sensor that are supposed to have a real-time display, so the data has to be re-s...


animation - How do I track an animated object in Python?

I want to automate playing a video game with Python. I want to write a script that can grab the screen image, diff it with the next frame and track an object to click on. What libraries would be useful for this other than PIL?


Python Animation Timing

I'm currently working on sprite sheet tool in python that exports the organization into an xml document but I've run into some problems trying to animate a preview. I'm not quite sure how to time the frame rate with python. For example, assuming I have all of my appropriate frame data and drawing functions, how would I go about coding the timing to display it at 30 frames per second (or any other arbitrary rate).


animation - Python problem with resize animate GIF

I'm want to resize animated GIF with save animate. I'm try use PIL and PythonMagickWand (ImageMagick) and with some GIF's get bad frame. When I'm use PIL, it mar frame in read frame. For test, I'm use this code: from PIL import Image im = Image.open('d:/box_opens_closes.gif') im.seek(im.tell()+1) im.seek(im.tell()+1) im.seek(im.tell()+1) im.show() When I'm use MagickWand with this code...


How to extract a given frame from a .gif animation in Python

I'm trying to figure out how to extract a given frame from an animated-gif, possibly in PIL, in Python. I'm not able to easily dig this up, and I'm guessing it would take some knowledge of the gif format, something that is not readily understandable to me. Is there any straightforward way to accomplish this? Do I need to do some custom parsing?


python - How can I speed up an animation?

I'm trying to create a Matplotlib animation of my paw data, where you can see the pressure distribution on the entire pressure plate over time (256x64 sensors for 250 frames). I found a working example on Matplotlib's own site


animation - Error in python script

I wrote a python script to make an animation but when I run it I get the error AttributeError: 'module' object has no attribute 'ion' Here is the script: import numpy as np import pylab as pl data = np.loadtxt( "random.dat" ) pl.ion() M = len( data[0] )-1 N = len( data[:,0] ) line , = pl.plot( data[0,1:] , pl.ones( M ) , 'o' ) for i in xrange( 1 , N ): ...


python - Motion Animation

I have a project in Python 2.7 and PyGTK 2.24. I am using the following code to create a motion animation of a gtk.Image inside a gtk.Fixed. def fishmove(): global fishmove if fishmove < 640: fishmove = fishmove + 10 fixed_hab.move(fish1, fishmove, 50) gobject.timeout_add(1, fishmove) However, while the program comes up without throwin...


python - 3D Animation of Fractals

I'm giving a presentation on Fractal Antennas (take a look at my previous threads) in November and I wanted to incorporate some animation to make my presentation easier to visualize the content I am referring to. Most of these animations would be relatively short, probably a minute long at the most. There are a few animations that would be fantastic to have: Fractal Mountains - The animation continues to a...


python - wx.Timer for animation

Simple animation, this works but would the replaced image data stay in the buffer? And is using timer for animation harmful to CPU? I mean like self.timer.Start(25) does some cool animations from individual image files. self.nm = ['01.png', '02.png', '03.png', '04.png'] self.stop = 0 def time(self, event): self.count += 1 if self.count == 1: self.anime = wx.StaticBitmap(self, -...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top