Beispiel #1
0
 def _leaf(self,group,here,t,dt):
     if False:
         ss=2-random()*4
         se=2-random()*4
         ss,se=sorted((ss,se))
         es=4-random()*8
         ee=4-random()*8
         es,ee=sorted((es,ee))
         N=8
         for i in range(N+1):
             p=PrettyPath(here,Vec2D(r=t.r*(1.1-0.2*random()),t=t.t+_map(i,0,N,dt.l,dt.r)),_map(i,0,N,ss,se),_map(i,0,N,es,ee))
             tp=p.taperedpath(5,stroke='green',stroke_width=0,start_width=5,fill='green',debug=False)
         #tp=svgwrite.shapes.Ellipse(here.car,(2,4),fill='green')
         #tp.rotate(t.t,here.car)
             group.add(tp)
Beispiel #2
0
def profile():
    start = Vec2D(random() * 1000, random() * 1000)
    #start=Vec2D(21,25)
    t0 = Vec2D(r=100, t=radians(random() * 360))
    #t0=Vec2D(r=100,t=radians(45))
    tgoal = Vec2D(r=1, t=radians(random() * 360))
    end = Vec2D(random() * 1000, random() * 1000)
    p = PrettyPath(start, t0, -2, 2)
    #print("start",start.x,start.y)
    #print("p.start",p.start.x,p.start.y)
    #print("end",end.x,end.y)
    #p.pathpoints(5)
    #print("p.start",p.start.x,p.start.y)
    #print("p.end",p.end.x,p.end.y)

    #p.path_to(end,5)
    o = optimize(width=10,
                 error=1,
                 path=p,
                 start=start,
                 t0=t0,
                 t1=tgoal,
                 end=end,
                 segs=5,
                 bounds=10)
    return o
 def __init__(self, start, t0, c0, c1):
     self.t0 = t0
     self.start = start
     self.c0 = c0
     self.c1 = c1
     self.end = None
     self.t1 = None
     self.pp = PP(self.t0, self.start, self.c0, self.c1)
     print("wprettypath: self.start:", self.start, "self.pp.start",
           self.pp.start)
Beispiel #4
0
def prettyline(start, end, **kwargs):
    dt0 = kwargs.pop('dt0', radians(30))
    dt1 = kwargs.pop('dt1', radians(30))
    start_width = kwargs.pop('start_width')
    end_width = kwargs.pop('end_width', 0)
    render = kwargs.pop('render', False)
    t = (end - start).t
    t0 = t + dt0
    t1 = t + dt1

    if render:
        p = PrettyPath(start, Vec2D(1, 0), 0, 0, tightness=1)
        #print("optimizing...")
        p.optimize(t0=t0, t1=t1, end=end, segs=5)
        kwargs['end_width'] = end_width

        return p.taperedpath(5, start_width, **kwargs)
    else:
        kwargs['stroke_width'] = start_width
        if kwargs['fill'] == 'none':
            kwargs['stroke'] = '#00aa00'
        return svgwrite.shapes.Line(start.car, end.car, **kwargs)
Beispiel #5
0
from cprettypath import PrettyPath
from vec2d import Vec2D
p=PrettyPath(Vec2D(0,0),Vec2D(r=100,t=90),-2,2)
p.pathpoints(5)
Beispiel #6
0
        x_p, y_p = self.on_path(x_p, y_p)

        return x_p, y_p

    def on_path(self, x, y):
        #print('x:',x)
        pathpoint = get_point(self.path, self.segs, x)
        tan = Vec2D(r=y, t=pathpoint[1] + radians(90))
        #tan._update_car()
        xy = pathpoint[0] + tan
        #return x,y
        return xy.x, xy.y


linecolor = '#cc1111'
p = PrettyPath(Vec2D(10, 50), Vec2D(r=320, t=radians(25)), -3, 7)
t = TextPath('h**o sapiens', 30, 20, p, 5)
svg = t.text_to_svg()
ps = p.taperedpath(5,
                   34,
                   end_width=0,
                   fill='none',
                   stroke_width=2,
                   stroke=linecolor)
ps = ps.tostring()

p2 = PrettyPath(Vec2D(10, 50), Vec2D(r=320, t=radians(25)), 3, -7)
t = TextPath('h**o sapiens', 30, 20, p2, 5)
svg2 = t.text_to_svg()
ps2 = p.taperedpath(5,
                    34,
class PrettyPath():
    def __init__(self, start, t0, c0, c1):
        self.t0 = t0
        self.start = start
        self.c0 = c0
        self.c1 = c1
        self.end = None
        self.t1 = None
        self.pp = PP(self.t0, self.start, self.c0, self.c1)
        print("wprettypath: self.start:", self.start, "self.pp.start",
              self.pp.start)

    def _cp(self, s):
        return self.pp._cp(s)

    def pathpoints(self, segs):
        t = Vec2D(r=self.t0.r(), t=self.t0.t())
        #t=self.t0
        ret = []
        p = self.start
        #max dtheta! that's what we care about.
        c = 0
        for i in range(segs):
            s = _map(i, 0, segs, 0, 1)
            curvature = self._cp(s)
            dt = curvature * (1 / segs)
            subdiv = int(abs(dt) // MAXDTHETA) + 1
            jret = []
            for j in range(subdiv):
                #print("i:",i," j:",j," t:",t)
                jret.append((p, 1 / c if c != 0 else None, t.t))
                s = _map(i + j / subdiv, 0, segs, 0, 1)
                curvature = self._cp(s)

                dt = curvature * (1 / (segs * subdiv))
                if curvature < -MIN_C or curvature > MIN_C:
                    pass
                else:
                    curvature = 0

                c = curvature / t.r()

                if curvature:
                    #r=t*(1/curvature)
                    #r._update_pol()
                    r = Vec2D(r=1 / c, t=t.t())
                    delta = Vec2D(r=2 * r.r() * np.sin(dt / 2),
                                  t=r.t() + dt / 2)
                    p = p + delta
                    #r.rotate(0.5*np.pi)
                    #p=p+r
                    #r.rotate(dt)
                    #p=p-r
                    t.rotate(dt)
                else:
                    #self.straights+=1
                    delta = t * (1 / (segs * subdiv))
                    p = p + delta
            ret.append(jret)
        ret.append([(p, 1 / c if c != 0 else None, t.t())])
        #assert(len(ret)>1)
        self.pp.end = p
        self.end = p
        self.t1 = t
        self.pp.t1 = t
        return (ret)

    def path_to(self, *args):
        self.pp.path_to(*args)
        self.t0 = self.pp.t0
        self.end = self.pp.end
        self.t1 = self.pp.t1