Squirtle - an SVG mini-library for Pyglet
As some of you may know, last PyWeek, as part of our entry, Robot Underground, I wrote a fairly minimal Pyglet-based SVG parser and renderer. Since then, I've seen a number of people do similar things for their Pyglet projects.
Rather than have people continually reinvent the wheel, I've taken the parser from RU, and spruced it up a bit. I'm releasing it under a BSD license, similar to that used for Pyglet itself. You can read about it and download a copy from the Super Effective website. It's not perfect, and it's by no means complete, but as far as I'm aware, it's the best pure-Python solution out there to the problem.
I'd appreciate any comments, and particularly any bug reports or patches.
(log in to comment)
Comments
richard: Glad you like it!
It was using pyglet.graphics, but I started getting weird artifacts. I meant to report a bug, work up a test case, etc, but various things intervened. There's some commented out code in there that might still work, or might not. I can't remember. I'll look into it again when I get some free time, or I'm happy to answer any questions anyone else has if they want to try.
As for holes, they would require rewriting the triangulation algorithm, which I probably should do anyway. It's a big job though, and I'd like to do a little research first into how best to do it, particularly as it's the most computationally intensive part of the code.
How do the vector lines with caps work? Are you turning the lines into polygons?
A friend has given me his (in his view) quite optimal and optimised triangulation code. It doesn't handle holes and is written in C++ but he'd given me permission to transcode it to Python if I got a chance. Would you be interested in seeing it?
I don't think there's much point in rewriting the triangulation code if I'm not rewriting it to allow holes. At the moment, I've got a little bit done on an implementation of this algorithm, but it'll probably be a while before it's finished.
I no longer have the code, but its relatively easy to use. google gluNewTess for more info.
simonwittber: Hmm. I had a brief look at the gluTesselator functions, but thought it was likely to require more Python/C interfacing than I was comfortable with (e.g. passing Python functions as C callbacks). Perhaps I should take another look. How widely available are the gluTesselator functions?
Treeform: Port away! It's under a BSD license, so I couldn't stop you even if I wanted to. I'd just ask that I am credited appropriately, and that you keep me up to date on what you're doing (particularly any improvements you make).
Traceback (most recent call last): File "run_game.py", line 12, in main() File "run_game.py", line 9, in main m.main() File "lib/main.py", line 12, in main game.Game(window) File "lib/game.py", line 14, in __init__ LoadSVGS() File "lib/images.py", line 11, in LoadSVGS "player": squirtle.SVG(pygutil.filepath("data/ship.svg")), File "lib/squirtle.py", line 177, in __init__ self.generate_disp_list() File "lib/squirtle.py", line 223, in generate_disp_list self.parse_doc() File "lib/squirtle.py", line 315, in parse_doc self.parse_element(e) File "lib/squirtle.py", line 468, in parse_element self.parse_element(c) File "lib/squirtle.py", line 464, in parse_element self.gradients[e.get('id')] = LinearGradient(e, self) File "lib/squirtle.py", line 94, in __init__ style = parse_style(e.get('style')) File "lib/squirtle.py", line 32, in parse_style key, value = item.split(':') ValueError: need more than 1 value to unpackHelp?
richard on 2008/08/07 04:32:
Oh this frickin' ROCKS!!!Two questions: