Showing posts with label softcurve. Show all posts
Showing posts with label softcurve. Show all posts

Sunday, February 11, 2018

Morphing between two 2D shapes with the same number of points.

Morph from one set (of points) to another.
Softcurve()makes transition ease in and out.


for(i=[-0:0.1:1])
{
morphed=lerp(rabbit(),elephant(),softcurve(i)) ;
translate([i*200,0,0])
polygon( morphed);
}

function lerp(start,end,bias)=(end*bias+start*(1-bias));
function softcurve(a)=let(b=clamp(a))(b*b*(3-2*b));
function clamp(a,b=0,c=10)=min(max(a,b),c);
  

function rabbit()=[[-4.76,-3.76],[-5.76,-5.76],[-4.76,-9.76],[0.24,-9.76],[4.24,-9.76],[6.24,-5.76],[6.24,-3.76],[4.24,-2.76],[2.24,-1.76],[4.24,-0.76],[5.24,1.24],[3.24,3.24],[2.24,3.24],[3.24,5.24],[3.24,7.24],[1.24,6.24],[0.24,3.24],[-0.76,3.24],[-1.76,3.24],[-2.76,6.24],[-7.76,6.24],[-4.76,4.24],[-3.76,2.24],[-5.76,0.24],[-3.76,-1.76]]
+[for(i=[0: (24) ])rands(-1,1,2)]*0.5;
function elephant()=[[-11,-5.84],[-8,-5.84],[-8,-0.84],[-4,-1.84],[0,-1.84],[1,-0.84],[1,-5.84],[4,-5.84],[4,-0.84],[7,-4.84],[10,-4.84],[10,-2.84],[8,-2.84],[6,0.16],[8,4.16],[6,7.16],[3,6.16],[1,9.16],[-2,8.16],[-2,5.16],[1,4.16],[-3,4.16],[-10,3.16],[-11,-0.84],[-11,-5.84]]
+[for(i=[0: (24) ])rands(-1,1,2)]*0.5;