function start() {
var circleCount = Playground.AddInt('circleCount', 5);
var exponent = Playground.AddInt('exponent', 2);
var easeIn = Playground.AddBool('easeIn', true);
var easeOut = Playground.AddBool('easeOut', false);
Playground.AddOptionInt(circleCount, 'Circle count', 2, 32);
Playground.AddOptionInt(exponent, 'Exponent', 1, 8);
Playground.AddOptionBool(easeIn, 'In');
Playground.AddOptionBool(easeOut, 'Out');
}
function update() {
var circleCount = Playground.GetValueInt('circleCount');
var exponent = Playground.GetValueInt('exponent');
var easeIn = Playground.GetValueBool('easeIn');
var easeOut = Playground.GetValueBool('easeOut');
var points = [
new Vector2(173, 248),
new Vector2(214, 240),
new Vector2(234, 164),
new Vector2(188, 128),
new Vector2(94, 121),
new Vector2(17, 189),
new Vector2(18, 314),
new Vector2(66, 390),
new Vector2(179, 406),
new Vector2(284, 391),
new Vector2(310, 275),
new Vector2(328, 221),
new Vector2(268, 178),
new Vector2(257, 92),
new Vector2(307, 53),
new Vector2(397, 53),
new Vector2(458, 75)
];
var slider = Playground.AddSlider(CurveType.Bezier, points, false);
for (var i = 0; i < circleCount; i++) {
var inT = i / (circleCount - 1);
Playground.AddHitCircle(slider.PositionAt(ease(inT, exponent, easeIn, easeOut)));
}
}
function ease(t, exponent, easeIn, easeOut) {
if (exponent == 1 || (!easeIn && !easeOut)) {
return t;
}
var multiplier = exponent % 2 == 0 ? -1 : 1;
if (easeIn && !easeOut) {
return Math.pow(t, exponent);
}
else if (!easeIn && easeOut) {
return multiplier * Math.pow(t - 1, exponent) + 1;
}
else {
var power = 1 << exponent - 1;
if (t < 0.5) {
return power * Math.pow(t, exponent);
}
return multiplier * power * Math.pow(t - 1, exponent) + 1;
}
}