function unique(m)=
[for(i=[0:len(m)-1])if(search([m[i]],m,1)==[i])m[i]];
function unique(m)=
[for(i=[0:len(m)-1])if(search([m[i]],m,1)==[i])m[i]];
echo(clamplist([10,-.20,03,40,21,1,0,0.6,-2]));
function clamplist(v,b=0,c=1) =
len(v) == undef ? min(max(v,min(b,c)),max(b,c)):
len(v) == 0 ? [] :
[for (i = v) clamplist(i,b,c)];
My_selection=sel_rnd( [1, 3, 0.5, 100, sin(2)] );
function sel_rnd(v)=v[floor(rnd(len(v)))];
function AdjustBezier(v,l, precision = 0.00001)=
l<norm(v[0]-v[3])?
let(e=echo("Cant be that short, sorry"))[v[0],v[0] ,v[3] ,v[3]]:
let(
current_lenght=len3bz(v),
error=l/current_lenght,
e=echo(l,current_lenght,error),
new_v=[v[0],v[0]+(v[1]-v[0])*error,v[3]+(v[2]-v[3])*error,v[3]]
)
abs(1-error)>precision?AdjustBezier(new_v,l):v;
function len3bz(v, precision = 0.001, t = 0, acc = 0) =
t > 1 ? acc :
len3bz(v, precision, t + precision, acc
+ norm(bez2(t, v) - bez2(t + precision, v)));
function bez2(t, v) = (len(v) > 2) ? bez2(t, [
for (i = [0: len(v) - 2]) v[i]* (t) + v[i + 1] * (1 - t)
]): v[0]* (t) + v[1]* (1 - t) ;
module ShowControl(v) { // translate(t(v[0])) sphere(v[0][3]);
for (i = [1: len(v) - 1]) {
// vg translate(t(v[i])) sphere(v[i][3]);
hull() {
translate(t(v[i])) sphere(0.5);
translate(t(v[i - 1])) sphere(0.5);
}
}
}
module ShowBezier(v,steps=50)
{ // translate(t(v[0])) sphere(v[0][3]);
step=1/steps;
for (i = [-step:step: 1+step]) {
// vg translate(t(v[i])) sphere(v[i][3]);
hull() {
translate(t(bez2(clamp(i), v) ))sphere(1);
translate(t(bez2(clamp(i+step), v))) sphere(1);
}
}
}
function t(v) = [v.x, v.y, v.z];
function clamp(a, b = 0, c = 1) = min(max(a, b), c);
MyBezier=[[0,0,0],[0,0,10],[50,0,50],[50,10,50]];
Newlengh=175;
ShowControl(MyBezier) ;
ShowBezier(MyBezier) ;
echo(len3bz(MyBezier));
MyNewBezier=AdjustBezier(MyBezier,Newlengh) ;
color("red"){
ShowControl(MyNewBezier) ;
ShowBezier(MyNewBezier) ;
echo(len3bz(MyNewBezier));}
v1=rnd();v2=rnd();
for(i=[-0:1/160:1])translate([i,0])square([1/160, (( comp(i,v1,v2)))]);
function comp(i,c=0.5,s=0.75)=i<c? ramp(i,0,c,0,s) :ramp(i,c,1,s,1) ;
function ramp(v,bi1=1/3,bi2=2/3,start=1/3, end=2/3) =
let(b1=min(bi1,bi2),b2=max(bi1,bi2))
v<=b1?start:v<=b2?lerp(start,end,(v-b1)/(b2-b1)) :end;
function lerp(start, end, bias) = (end * bias + start * (1 - bias));
function rnd(a = 1, b = 0, s = []) =
s == [] ?
(rands(min(a, b), max( a, b), 1)[0])
:
(rands(min(a, b), max(a, b), 1, s)[0])
;
for(i=[-1:1/160:1])translate([bisignmap(i),0])square([1/160, map(infmap(i*12) ) ]); // Map takes a number in some range // and remaps it into the desired range function map( value,istart=-1, istop=1, ostart=0, ostop=1) = ostart + (ostop - ostart) * ((value - istart) / (istop - istart)); // BiSignMap takes a number in the range -1 - 1 // and remaps it into the range 0 - 1. function bisignmap(i)=(i+1)/2;// InfMap takes a number in the range -inf - inf// and remaps it into the range -1 - 1 .function infmap(i)=max(0,1-(1/(abs(i)+1)))*sign(i);
for(i=[-0:1/160:1])translate([i,0])square([1/160, ( ( smooth2(i) )) ]);
function smooth2(x,k=5,n=4) =1- (exp( -k*pow(x,n) ));
for(i=[-0:1/160:1])translate([i,0])square([1/160, (icosw( (i))) ]);
function icosw(i)=-cos(i*360)/2+0.5+i;
for(i=[-0:1/160:1])translate([i , min(0,cosw(i))])
square([1/160, abs(cosw( (i))) ]);
function cosw(i)=cos(i*360)/2 -0.5+i;
for(i=[-0:1/160:1])translate([i, min(0,isinw(i))])
square([1/160, abs(isinw( (i))) ]);
function isinw(i)=gauss(i)-sin(i*360)/2;
function gauss(x) = x + (x - smooth(x));
function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
function clamp(a, b = 0, c = 1) = min(max(a, b), c);
for(i=[-0:1/160:1])translate([i,0])square([1/160, (sinw( (i))) ]);
function sinw(i)=sin(i*360)/2+smooth(i);
function gauss(x) = x + (x - smooth(x));
function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
function clamp(a, b = 0, c = 1) = min(max(a, b), c);
for(i=[-0:1/160:1])translate([i,0])square([1/160, (gauss( (i))) ]);
function gauss(x) = x + (x - smooth(x));
function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
function clamp(a, b = 0, c = 1) = min(max(a, b), c)
for(i=[-0:1/160:1])translate([i,0])
square([1/160, (ramp( (i),1/3,2/3,0.1)) ]);
function ramp(v,bi1=1/3,bi2=2/3,start=1/3, end=2/3) =
let(b1=min(bi1,bi2),b2=max(bi1,bi2))
v<=b1?start:v<=b2?lerp(start,end,(v-b1)/(b2-b1)) :end;
function lerp(start, end, bias) = (end * bias + start * (1 - bias));
