Here’s the code: Apologies if there’s students + teachers here, if this was going to be someone’s homework assignment.

```
(
var n1,n2,r1,r2,sli,lay,getXfromY,getYfromX,d1,d2,l1,l2,sl;
var slivalue,r1value,r2value;
var diffstart,diffend;
var range;
var dir;
var start,end;
var tmp;
getYfromX={
arg x,ystart,yend,xstart=0,xend=1;
var res;
res=getXfromY.(x,xstart,xend,ystart,yend);
res;
};
getXfromY={ // leaf input [ 0-1 ]
// convert y to 0 - 1
arg y,ystart,yend,xstart=0,xend=1;
var x;
if(y==nil,{ // there is no default value, use the average
y=0.5;
});
// x = (( y - ystart )(xend-xstart) /(yend -ystart)) + xstart;
x=linlin(y,ystart,yend,xstart,xend);
x;
};
start=0 ; end=1;
range=end-start;
dir=range.sign;
slivalue=0.5;
tmp=getXfromY.(start,start,end);
r1value=slivalue-tmp/2;
diffstart=getYfromX.(r1value,start,end);
a=getYfromX.(0,start,end);
"a:%\n".postf(a);
"watch1:tmp:% diffstart:%\n".postf(tmp,diffstart);
tmp=getXfromY.(end,start,end);
r2value=tmp-slivalue/2;
diffend=getYfromX.(r2value,start,end);
w=Window.new;
n1=NumberBox().value_(0);
n2=NumberBox().value_(1);
d1=NumberBox().value_(diffstart);
d2=NumberBox().value_(diffend);
l1=NumberBox().value_(start);
l2=NumberBox().value_(end);
sl=NumberBox().value_(0);
sli= Slider.new().orientation_(\horizontal).value_(0.5);
r1=Slider.new().orientation_(\horizontal).value_(0.25);
r2=Slider.new().orientation_(\horizontal).value_(0.75);
"slidersli:pixelstep:% step:%\n".postf(sli.pixelStep,sli.step);
sl.value=getYfromX.(0.5,start,end);
lay=VLayout(
HLayout[ r1,r2 ],
HLayout[ l1,l2],
HLayout[ d1,sl,d2],
HLayout [n1,sli,n2]
);
w.view.layout=lay;
w.front;
r1.action={
|i|
var res=i.value;
var tstart,tmp;
tmp=slivalue-res;
case
{tmp>=0}{
diffstart=getYfromX.(tmp,start,end);// this adds +start
tstart=getYfromX.(res,start,end);
// tstart=getYfromX.(slivalue,start,end)-diffstart+start;
"r1.action:slivalue:% tmp:% diffstart:% tstart:%\n".postf(slivalue,tmp,diffstart,tstart);
n1.value=tstart;
d1.value=diffstart;
r1value=res;
}
{tmp<0}{
r1.value=r1value;
};
};
r2.action={
|i|
var res=i.value;
var tend;
diffend=res-slivalue;
case
{diffend>=0}{
diffend=getYfromX.(diffend,start,end);
tend=getYfromX.(res,start,end);
// tend=getYfromX.(slivalue,start,end)+diffend;
n2.value=tend;
d2.value=diffend;
r2value=res;
}
{diffend<0}{
r2.value=r2value;
};
};
sli.action={
|i|
var res=i.value;
var tend,tstart;
var confirm=0;
var currvalue;
currvalue=getYfromX.(res,start,end);
tend=currvalue+diffend;
tstart=currvalue-diffstart;
"slidersli:pixelstep:% step:%\n".postf(sli.pixelStep,sli.step);
if(tstart>=start,{
confirm=1;
});
if(tend<=end,{
confirm=confirm+1;
});
if(confirm==2,{
n1.value=tstart;
n2.value=tend;
// slivalue=getXfromY.(res,start,end);
slivalue=res;
sl.value=currvalue;
},{
"setting sli.value:%\n".postf(res);
sli.value=slivalue;
});
};
)
```