float square(float center_x,
center_y,
scale_x,
scale_y)
{
return smoothstep(center_x-.5*scale_x ,center_x,s)*(1-smoothstep(center_x,center_x+.5*scale_x,s))
*smoothstep(center_y-.5*scale_y, center_y,t)*(1-smoothstep(center_y,center_y+.5*scale_y,t));
}
displacement snake_scale3(float len = .2,
deg = 75,
ss = 80,
tt = 5,
scale_x = .01,
scale_y = .2,
crease_scale_x =.5,
crease_scale_y =.1,
crease_height = .1
)
{
P = transform("object", P);
N = transform("object", N );
point pp;
pp = P;
float m=1,i,k,value=0;
float big_square,small_square;
for(i=0; i<=1; i+=1/ss)
{
for(k=0; k<=1; k+=1/tt)
{
if( mod(m,2) == 0 )
{
// value += square(i,k, scale_x, scale_y);
big_square = square(i, k, 1* scale_x, 1 * scale_y);
small_square = square(i-.25/ss, k, crease_scale_x * scale_x, crease_scale_y * scale_y);
value += big_square + crease_height * small_square;
}
else
{
// value += square(i,k+0.5/tt, scale_x, scale_y);
big_square = square(i, k+0.5/tt, 1* scale_x, 1 * scale_y);
small_square = square(i-.25/ss, k+0.5/tt, crease_scale_x * scale_x, crease_scale_y * scale_y);
value += big_square + crease_height * small_square;
}
}
m+=1;
}
P += normalize(N) * value * len;
vector tangent = normalize(vtransform("object",dPdv));
P= rotate(P,radians(deg),pp,pp+tangent);
P = transform("object", "current", P);
N = calculatenormal(P);
}