Python Forum
SVG + Python experiments (using pygame-ce and/or cairoSVG)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SVG + Python experiments (using pygame-ce and/or cairoSVG)
I've been making different experiments/demos with Nodezator and other Python libraries in order to identify programming tasks that have synergy with a node-based approach. This experiment shows what I've learned about Python and SVG images. What I learned is actually very useful regardless of whether you are using text-based or node-based Python.

Some people don't even know pygame/pygame-ce 2 has support for SVG. Although limited, SVG support in pygame can still be used to achieve a lot of advanced stuff. If you need more complete support, cairoSVG is a great alternative to render SVG graphics.

Because SVG is so versatile and is just really a text format, you can create complex smoothly antialiased shapes/paths with it by writing your own instructions. Like this, for instance, where SVG text is rendered as a still image (a pygame surface) with pygame-ce:

from io import BytesIO # standard lib

import pygame

svg_text = """
<svg width="300" height="200">
    <rect x="0" y="0" width="300" height="200" fill="white" />
    <circle cx="150" cy="100" r="60" fill="red" />

svg_bytes = bytes(svg_text, encoding='utf-8')
bytestream = BytesIO(svg_bytes) # or "with BytesIO(svg_bytes) as bytestream: ..."
surface = pygame.image.load(bytestream)
Here are relevant resources to know more about this:

A ~10 min video showing my experiments:

Also a text post version (source code included).
Gribouillis likes this post
You would have a more dynamic workflow if you didn't have to click the Reload button to see the result. Can't you recompute the result automatically every time you connect two nodes from the same circuit?
KennedyRichard likes this post
Thank you for the suggestion. Other users have already suggested this feature you described in the GitHub repo as well, given how useful it would be. It is just a question of time until it is implemented. The reason it wasn't already is just because there are tons of other features of higher priority to be implemented first.

The next features scheduled for implementation are automated GUI testing the topological sorting technique for graph execution (currently we use a solution that is effective but not optimized). Among these, automated GUI testing is specially important, because the app is too complex to be manually tested by a single person. It will allow me and other contributors to work confidently and assured that our work is not breaking other related parts of the app. Thankfully it is almost finished (the main functionality was already implemented and tested), I just want to refine it a bit more and maybe extend it just a little bit so we can include some extra kinds of tests.

The project is also a personal open-source project, understaffed and underfunded, which is why some stuff takes time. I'm not complaining though, by the way. I have a lot of fun and learn a lot working on it and by interacting with the community. I received so much for free from the Python ecosystem over the years that I'm just glad that I can finally give something back for free as well. And the project is even blessed enough to have 02 selfless and generous patrons. The project has a lot to improve, but we are slowly getting there. I can only see it growing more and more over time and it is already useful to some people.

Thanks again for the suggestion, I'm always on the hunt for ideas to improve Nodezator.
Your Nodezator and Python library experiments, especially with SVG and pygame, are fascinating! Your approach to achieving advanced graphics with limited SVG support in pygame is clever. Thanks for sharing the code snippet—it's insightful. I'm eager to find out the plot! Using CasinosAnalyzer to browse ezeewallet casino revealed an easy-to-use interface for real money gaming. This electronic wallet makes online transactions easier with its practical deposit and withdrawal options, giving gamers a hassle-free gaming experience.
KennedyRichard likes this post
(Nov-22-2023, 01:34 PM)JuanitaGerber Wrote: Your Nodezator and Python library experiments, especially with SVG and pygame, are fascinating! Your approach to achieving advanced graphics with limited SVG support in pygame is clever. Thanks for sharing the code snippet—it's insightful.

Thank you for your kind words. Sometimes I get astonished at how much untapped potential Python has regarding its usage in many fields/areas. One of those areas is scriptable vector illustration/animation. Think about how much could be achieved for education and entertainment.

I plan on expanding and continuing my work regarding Python + SVG in private, probably sharing some glimpses on my social networks/YouTube as it progresses. If my work reaches some maturity and yields useful tools, though, I do intend to publish the code to the public domain, as I did with Nodezator.

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020