# NodeBox

Create visual output with Python programming code
Home Download Reference Tutorial Library Gallery About

# SVG

## Description

The SVG library provides enhanced control over vector work imported into NodeBox. Rectangles, circles and paths from an SVG file are imported as native NodeBox paths, thus their individual points and colors can be manipulated (see the tutorial on Paths).

"SVG" means Scalable Vector Graphics and is an XML format. You can save SVG files from Illustrator - you can draw your shapes and forms in Inkscape or Adobe Illustrator and then manipulate them in NodeBox.

Right now the SVG library has been tested for the following Illustrator functionalities: rectangles, ellipses, polygons, lines, curves constructed with the pen-tool, fill colors, stroke colors, stroke widths and transparency. Complicated things like gradient fills are ignored.

## Download

| svg.zip (3KB) Last updated for NodeBox 1.8.

## Commands in the SVG library

- parse()

## Example

One of Ludivine Lechat's Illustrator drawings, imported into NodeBox. I can alter each path separately, their colors for example.

Since all of the imported artwork are standard NodeBox paths, I can manipulate them with path mathematics, transform them like the LetterKnitter. After some fumbling with paths and a nice gradient background, here is a hairy version of our flower. The bottom paths are darker to create a sense of depth.

Below is the basic code used to alter the path. You can see it in use in the Superfolia project in the gallery.

    bezier = ximport("bezier")
    def furry(path):
      l = bezier.length(path, segmented=True)
      prev = None
      for i in range(100):
        p = bezier.point(path, i*0.01, segments=l)
        strokewidth(random(0.5))
        if prev != None:
          autoclosepath(False)
          beginpath(prev.x, prev.y)
          curveto(p.ctrl1.x-random(30), p.ctrl1.y,
                  p.ctrl2.x, p.ctrl2.y+random(30),
                  p.x, p.y)
          curveto(p.ctrl1.x+random(10), p.ctrl1.y,
                  p.ctrl2.x, p.ctrl2.y-random(10),
                  random(-20,20)+p.x, random(-10,10)+p.y)
          endpath()
          prev = p