1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Fit text to path

Posted by Tom De Smedt on Feb 20, 2009



Some code to display text on a path.
It's a rough approximation but I thought it might be useful to someone.

autoclosepath(False)
beginpath(113, 105)
curveto(226, 45, 200, 277, 390, 367)
curveto(716, 509, -284, 325, 106, 109)
path = endpath(draw=False)
#path = oval(200, 200, 200, 200)
 
nofill()
stroke(0)
drawpath(path)
 
#font("Courier")
fontsize(10)
fill(0)
txt = "text following a path"
 
from nodebox.geo import angle
def trace(path, txt, start=0.01, dy=10, loop=False):
    W = textwidth(txt)
    dW = W / path.length
    first = True
    for ch in txt:
        w = textwidth(ch)
        if first:
            t = start
            first = False
        else:
            t += w / W * dW
        if loop:
            t = t % 1.0
        pt = path.point(t)
        a = angle(pt.x, pt.y, pt.ctrl2.x, pt.ctrl2.y)
        transform(CORNER)
        push()
        translate(pt.x, pt.y)
        rotate(-a+0)
        text(ch, -w, -dy)
        pop()
 
speed(20)
def draw():
    drawpath(path)
    trace(path, txt, start=FRAME*0.01, loop=True)


 
Posted by piupiu on Mar 04, 2009

Thanks!



Posted by john on Apr 23, 2012

This definitely works so good. You are able to get so much great use from it. The options are endless with it. zoloft suit