2D animation in Python - 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?

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

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

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.

Related

Difference between pyglet and pygame, in simple words?

There are many questions dealing with pyglet and pygame, but what I want to know is difference in theses two, in simple terms.
Not in technical terms, not experimental features and all that.
They are both libraries, both API, both for creation of games and multimedia apps, right?
Just in plain English, for someone like me, relative begginer, who has finished course about Python in Codecademy and read Head first Python book.
Pyglet is a wrapper around OpenGL, while Pygame is wrapper around SDL.
OpenGL is primarily concerned with 3d rendering, while SDL
is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.
PyGame is low-level library. You have to do all on your own - starting at mainloop and all functions called by mainloop. You can do it in different ways.
(And you can learn something about mainloops in Pyglet, Tkinter, PyQt, wxPython and other GUIs, not only in Python)
Pyglet is framework - it has already mainloop and you can't change it and you can't see how it works. You override functions which mainloop calls. You have to keep its rules.
I've tried pyglet and pygame and rate pygame as the best .

Creating an animated graphics overlay with Python

I'd like to hear the best means for displaying graphics that move on-screen as an overlay with Python. The intended initial platform is Linux. I've worked up some small demos using PyQt using frameless windows and looping and updating their location on screen. This works, but I have a feeling it is not the ideal solution.
The end result is an activity indicator that would show more objects swarming in an upward direction as activity increased. That would result in spawning perhaps a hundred windows in a go and that is why I think my PyQt demo is not optimal.
I'm open to any suggestions since this will be an open project and installing obscure modules is a non-issue.
There are examples for making transparent / unclickable windows in java and in javascript. Here are a couple of transparency related posts for QT.

Graphical User Interfaces for cracks, keygens, etc

Have you ever used those cracks and keygens with the really nice interfaces and 8-bit music playing in the bg with special effects when you clicked buttons and stuff? I'd like to create works like such (the GUI part), but I'm wondering which GUI toolkit has that kind of flexibility.
Do all GUI toolkits have the ability to create such out-of-the-box (literally) designs? I even remember one famous cracker had a dancing panda or some animal at the top of his program that was really trippy. I bet that wasn't easy.
I was planning on trying to get started with Python and PyGTK, if it's even possible, I guess I'll find out.
I'd wager most of those cracks are written in C or even assembly language, using the Windows API at a very low level. Very few, if any, are written in Python, and positively none are written using GTK. :) Crackers have different aesthetics than ordinary programmers, and they tend to idealize low-level programs with small executable size. They also usually know Assembly, C and low-level Windows API much better than they're familiar with cross platform toolkits such as GTK and Qt.
That being said, most modern toolkits can do at least some of what you describe. Playing sound when a button is clicked, for instance, is quite easy: all you have to do is to hook the to the button events and play a sound using your toolkit's sound API (or an additional library if your toolkit doesn't have sound capabilities). The same goes for music. Drawing graphics on your window's background is also possible with most toolkits I know, and although I have no experience with GTK, I guess it can do that as well.
Some of the things that might be harder to implement (depending on your toolkit) are non-rectangular windows (e.g. an egg-shaped window), and smooth animations that require at least some sort of double-buffering (if not hardware graphic acceleration support).

GUI-embeddable Python drawing widget with anti-aliasing

I am writing a small diagram drawing application (similar to Graphviz in spirit), and need a GUI library that would allow me to embed a canvas capable of drawing anti-aliased lines and text. I want to have a text editor in one half of the window to edit the diagram code and a (perhaps live) preview pane in the other.
Right now I have the text editor in a tkinter window and the rendered diagram in a separate pygame one. This technically works, but it's messy (e.g. having two event loops), and in general I would much prefer having both parts in one window. I have searched for ways of integrating the two, but haven't been able to find anything cross-platform, and pygame explicitly suggests not trying to do it.
An alternative would be to have pygame export the image into a file and load it back into tkinter, but tkinter can read only GIF/PPM without PIL (and I use Python 3, which PIL doesn't support) and pygame can't write GIF/PPM. I could backport to Python 2, since it's a tiny app, but even then, having a large extra library for a simple image conversion doesn't seem right, and the round-trip to a file will probably be too slow for live preview (not to mention ugly).
Finally, a simple tkinter canvas is almost what I want, except it can't draw anti-aliased lines, and for a program whose main purpose is to draw line figures, that is not acceptable.
I'm using Python 3 so libraries that support it are preferred, but if there's no way to do that whatsoever Python 2 libs are Ok as well. The library needs to be cross-platform, and of course, the fewer external packages are required, the better.
If you don't mind the way GTK looks, pygtk has an option for antialising in their canvas widget (see this) and is considered by many to be as powerful as Tkinter, though it is not included in standard Python installs.
Also, it's Python 3.x compatible, which can't be said of most non-standard library modules and packages.
Screwing around with Tkinter+pygame is silly. I would use wxPython. In fact, I've done a diagramming widget using wxPython, and it has anti-aliasing:
Unfortunately it was for work, so I can't distribute the code.
The wxPython classes you want to look at for anti-aliasing are wx.GCDC and/or wx.GraphicsContext.
After a thorough search I ended up using PyQt4. It does fit all my requirements (Python 3, cross-platform, anti-aliasing), and now that I've gotten through the basics, it's also quite intuitive and easy to use.
Posting this as an answer to my own question and accepting it for future reference.

Fast Graphics with XServer

I am working on embedded linux platform with limited system resources.
I want to do fullscreen slideshow with simple transistions (like slide in-out, fade in-out ).
I tried PyGtk+GTK+Cairo but its very slow, when I animate GTK image controls I get just two or three frames per second. But smplayer is playing video at good speed!
I did some little research and came to know about directfb, libggi, svgalib etc. and I don't know what library should be used.
Which library is the best for this kind of application? I would prefer to do this without stopping X.
I would try this first using just PyCairo, not using GTK controls at all.
However, if that does not give you the speed that you need, then you might want to try PyGame which gives you access to SDL including OpenGL backends. PyGame is very actively developed and used in building applications that include full screen animation so even if you are not writing a game, you will still likely find the best support by using PyGame.

Categories

Resources