Thu 09 Jul 2009 (12:07:00)
“Things”
Vector, Animation, API, Python, Cairo, Frames, Keyframes, Tweening, GNU/Linux, Tutorial, 2D, 2D Animation, Export PNG, Export SVG
This thing is counting the html in my API help files as lines of code. Urgh.
Vector Animation in Python!
While it’s neither perfect nor quick, Things is a working API which is very easy to use. Fetch it and run the demos to see what I mean.
In order to get the code, use subversion (svn) (apt-get install subversion) and this incantation:
svn co svn://svn.savannah.nongnu.org/things/trunk
Screenshot
Features
- Keyframe and tweening by using simple strings.
- Containment — place things within other things to get complex animations.
- Path following — this works, but the code needs some love. Please help me.
- Clipping — You can clip things into any path.
- Hit detection — A basic “is the mouse on me” test. There is also a button Thing based on this.
- Manage your artwork and fonts — Use the Bag Of Stuff to contain all your raw materials.
- Quick shapes and other functions — Use the Box Of Tricks to do all kinds of things.
- It all works from Python via a simple API. Have a look at the tutorial linked above.
-
Export each frame to alpha PNG files or SVG files! This will let you make:
- Quick AJAX throbbers.
- Animated gifs.
- import frames into other software (Blender for example.)
Example code
01. from Things.ThingsApp import *
02. class Ball(Thing):
03. def __init__(self ):
04. Thing.__init__(self)
05. self.keys ( "#----#----#",Props(),Props(x=100),Props())
06. def draw(self,ctx,fr):
07. bos["art:ball"].draw(ctx)
08. bos = BagOfStuff()
09. bos.add ( "artwork.svg", "art")
10. app = AllThings ( 400, 400, speed = 30, title = "A Ball" )
11. app.add(Ball())
12. app.comeToLife ( )
- First, we import the API.
- Line 2 defines a Ball — it is a “Thing”.
- Line 5 shows that the ball will tween along three keyframes.
- Line 7 pulls the ball out of an Inkscape file and draws it.
- Line 8 & 9 are where you define your “Bag of stuff”
- Line 10 defines the ‘app’ and sets the speed.
- Line 11 is where you add the Ball to the app.
- Line 12 start the animation.
That’s it!
Python and Cairo
A handy link is this Python-Cairo tutorial.
Call for help
I need some help with this:
- Follow path code is kind of fugly. (And broken.)
- If this could be converted to C or C++ this API would be properly useful. At the moment it’s a mere proof of concept.
- Events need improvement — they are too slow. (And sort of broken…)
- New Things can be added. A path-tweener (shape changing) Thing for example.
\d
