# NodeBox

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

# Manipulating Paths

Each of the NodeBox shape commands (oval(), rect(), etc.) returns a path. This path is actually a list of points, in which each point has certain properties that you can manipulate. This way you can retrieve or edit the coordinates for each point, the coordinates of its control handles, and the kind of points you are dealing with (the start of a curve or a straight line).

This is the path and its points returned from the textpath() command, for the character e in the Dolly typeface: | This is the same path, but modified. Each point in the path was lowered by twenty points.
    font("Dolly-Bold", 300)
    path = textpath("e", 200, 200)
    drawpath(path)
    font("Dolly-Bold", 300)
    path = textpath("e", 200, 200)
    points = []
    for point in path:
      point.y += 20
      points.append(point)
      drawpath(points)

## Looping through all the points

As the above example shows, you can easily manipulate a path by looping through all of the points in the path with a for-loop, before actually drawing the path.

    path = textpath("hello", 100, 100)
    points = []
    for point in path:
      .html#Manipulate points here
      points.append(point)
    drawpath(points)

    autoclosepath(close=False)
    beginpath(100,100)
    curveto(150, 100, 200, 200, 50, 400)
    path = endpath(draw=False)
    points = []
    for point in path:
      #Manipulate points here
      points.append(point)
    drawpath(points)

## Manipulating points

Each point has the following attributes:

- point.x (the x-coordinate),
- point.y ((the y-coordinate),
- point.cmd (the type of curve, either LINETO, CURVETO or CLOSE),
- point.ctrl1.x,
- point.ctrl1.y,
- point.ctrl2.x (the x-coordinate of the point's control handle),
- point.ctrl2.y (the y-coordinate of the point's control handle),

The handles are useful for compound paths, paths that consist of multiple Bezier curves. The ctrl1 handle of a point controls how the curve connects to the previous point, the ctrl2 handle how the curve connects to the next point.

For example:

    beginpath(100,100)
    autoclosepath(close=False)
    nofill()
    curveto(150, 100, 200, 200, 150, 200)
    curveto(100, 200, 200, 350, 300, 300)
    endpath()

## Example

The following example manipulates a text path, letting each curving point droop a bit (I hope I don't make the guys at Underware freak when they see what I'm doing to their type)! Some more advanced math could create a handwritten variation of the text, or a text in which character looks different each time.

    font("Dolly-Bold", 100)
    path = textpath("broken", 200, 200)

    points = []
    for point in path:

        if point.cmd == CURVETO:
            point.ctrl2.x += 5
            point.ctrl2.y -= 10
            point.y += 5
        points.append(point)

    drawpath(points)