Curve Blending

The Shockwave panel below shows the result of blending two simple curves in amounts determined by the horizontal position of the mouse. This code simply blends the vector and handle positions of the curves linearly. The routines involved are:

Main blending procedure:

on blendvertices alpha,m1,m2    -- blend the vertices of two vector shapes
  
  verts1 = m1.vertexlist    -- get the two lists of vertices to be blended
  verts2 = m2.vertexlist
  
  if count(verts1) < count(verts2) then    -- swap; verts1 should be at least as long
    temp = verts1
    verts1 = verts2 
    verts2 = temp
  end if
  
  c1 = count(verts1)    -- get the number of vertices in each list
  c2 = count(verts2)
  
  repeat with j = 1 to c1     -- iterate over all the vertices, blending them
    
    vert1_j = verts1[j]
    
    if j > c2 then             -- the second list is shorter, so
      vert2_j = verts2[c2]     -- use its last vertex repeatedly
    else
      vert2_j = verts2[j]     -- use the actual j-th vertex
    end if
    
    newv = [:]                    -- start to build the blended vertex, as a property list
    vert1_j_v = vert1_j.vertex    -- get and blend the 'vertex' components
    vert2_j_v = vert2_j.vertex
    setaProp newv,#vertex,blend_points(alpha,vert1_j_v,vert2_j_v) 
    
    vert1_j_h1 = getaProp(vert1_j,#handle1)    -- get the 'handle1' components
    vert2_j_h1 = getaProp(vert2_j,#handle1)
    
    if vert1_j_h1 = void and vert2_j_h1 <> void then    -- two voids blend to void
      setaProp newv,#handle1,blend_points(alpha,vert1_j_h1,vert2_j_h1)     -- otherwise blend
    end if
    
    vert1_j_h2 = getaProp(vert1_j,#handle2)    -- get the 'handle2' components
    vert2_j_h2 = getaProp(vert2_j,#handle2)
    
    if vert1_j_h2 = void and vert2_j_h2 <> void then    -- two voids blend to void
      setaProp newv,#handle2,blend_points(alpha,vert1_j_h2,vert2_j_h2)     -- otherwise blend
    end if
    
    verts1[j] = newv    -- capture the new vertex, putting it in the list to output
    
  end repeat
  
  return verts1    -- return the list of blended vertices
  
end

Point blending subprocedure:


on blend_test      -- driver routine
  
  the_val = float(the mouseH - 320)/64.0      -- get and normalize the mouse postion
  member(1).vertexlist = blendvertices(the_val,member(2),member(3))
  sprite(6).rotation = float(the mouseV - 320) * 1.5
  
  if the mouseV < 75 then 
    sprite(6).forecolor = max(min(the mouseV/2,255),0)
  end if
  
  -- set vertices of the output shape
  member("show_val").text = "" & the_val         -- display the blend parameter
end

Driver routine, called once per frame:

on blend_test      -- driver routine
  the_val = float(the mouseH - 320)/64.0      -- get and normaize the mouse postion
  member(1).vertexlist = blendvertices(the_val,member(2),member(3))
           -- set vertices fof the output shape
  member("show_val").text = "" & the_val         -- display the blend parameter
end