I’ve added a new svgElement()
identifier to the image widget. This allows us to draw SVGs to an image from a string. For example, the code below will create this shape:
svgStar.csd (693 Bytes)
instr 1
cabbageSet "image1", "svgElement", {{
<polygon points="100,10 40,198 190,78 10,78 160,198" style="fill:lime;stroke:purple;stroke-width:5;fill-rule:nonzero;"/>
}}
endin
You can pass any number of elements, i.e, rectangles, circles, paths, etc. You do not need to wrap the elements in <svg> tags. These are automatically appended.
Because an SVG elements can contain any number of Cabbage syntax wildcards, and delimiters, it will quickly break the Cabbage preprocessor. So ONLY use this identifier within your Csound code! The path elements are really nice, because they let you do things like this:
svgElements.csd (3.6 KB)
- This example could be a lot better. If I was doing it again I would create a UDO to generate the envelopes with the components encapsulated, rather than creating the various components in the <Cabbage> section and pulling them together in my Csound code.
Animations are also possible. All you need to do is keep updating the SVG elements in realtime. But be forewarned that this might cause a spike in your CPU!
This is very poorly tested for now, so please let me know if you have any issues with it.