Being new at this I ran into several problems. First some code: 
    
    
    import vmath
    
    type
      Seg = array[4, Vec2]
      Segs = array[4, Seg]
      Spline = tuple[t: seq[float32], xy: seq[Vec2], v: seq[Vec2], a: 
seq[Vec2], lengt: seq[float32]]
    
    proc bezier(segment: Seg, res: int): Spline =
      #var t: seq[float32]
      let
        t1  = 1 / float32(res)
        t2 = t1 * t1
        t3 = t2 * t1
        b0 = segment[0]
        b1 = segment[1]
        b2 = segment[2]
        b3 = segment[3]
        a  = -b0 + 3 * b1 + -3 * b2 + b3
        b  = 3 * b0 + -6 * b1 + 3 * b2
        c  = -3 * b0 + 3 * b1
      var
        d  = b0
        fd1 = a * t3 + b * t2 + c * t1  #initial velocity
        fd2 = 6 * a * t3 + 2 * b * t2   #initial acceleration
        fd3 = 6 * a * t3                #acceleration change
        seqt = @[float32(0.0)]
        seqxy = @[d]
        seqfd1 = @[fd1]
        seqfd2 = @[fd2]
        seqlen = @[length(d)]
      
      for i in 1 .. res:
        d += fd1
        fd1 += fd2    #speed
        fd2 += fd3    #acceleration
        seqt.add(float32(i)*t1)
        seqxy.add(d)
        seqfd1.add(fd1)
        seqfd2.add(fd2)
        seqlen.add(length(d))
      let spline: Spline = [t: seqt, xy: seqxy, v: seqfd1, a: seqfd2]
      return spline
    
    
    Run

Error: undeclared identifier t after uncomment t I get: Error: cannot evaluate 
at compile time: t

Simple question, what to do.

Second question, in python I would use a dictionary to hold the several lists 
and work directly with that. What would a suitable container be with Nim. I 
tried tables (can't work with mixed type?), put it all in a seq (gets a bit 
cumbersome) and tuples so far.

Reply via email to