from .pturtle import *

class FPTurtle(PTurtle):
    """ Field Polygon Turtle.

        Compute field interactions before walking. 
    """
    def __init__(self, pos=None, orient=None, v_t=0, f=None, acum=None):
        super().__init__(pos, orient, v_t)
        if f is None:
            f = lambda a : (0, 0, -0.005)
        self.f = f
        if acum is None:
            acum = Vector([0, 0, 0])
        self.acum = acum
    def clone(self):
        return FPTurtle(self.pos, self.orient, self.v_t, self.f, self.acum)
    def wf(self, dist):
        super().wf(dist)
        f0 = Vector(self.f(self.pos))
        self.acum += f0*dist
        self.pos += self.acum
    def follow(self,t):
        super().follow(t)
        self.acum = t.acum.copy()
