Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function pfn(p: Point) {
const q = $chart.plotToMathCoords(p);
const x = clamp(roundTo(q.x, 0.5), -4, 4);
return $chart.mathToPlotCoords(new Point(x, 3 / 4 * x + 2));
}
setTransform(posn, angle = 0, scale = 1) {
let t = '';
if (posn) t += `translate(${roundTo(posn.x, 0.1)}px,${roundTo(posn.y, 0.1)}px)`;
if (angle) t += ` rotate(${angle}rad)`;
if (scale) t += ` scale(${scale})`;
this._el.style.transform = t;
}
function getAngle(p1: Point, p2: Point) {
return roundTo(Math.atan2(p1.y - p2.y, p1.x - p2.x) * 180 / Math.PI + 90, 6);
}
draw(angle, isMomentum, dt) {
for (let $w of $wheels) $w.setTransform(undefined, angle);
if (!isMomentum) return;
ballSpeed *= 0.985;
if (Math.abs(ballSpeed) > 0.00032) {
ballAngle = (ballAngle + dt * ballSpeed) % (2 * Math.PI);
} else {
if (!ballOffset) ballOffset =
roundTo(ballAngle - angle, 2 * Math.PI / 37);
ballAngle = angle + ballOffset;
}
const ballRadius = Math.min(116 + 87500 * Math.abs(ballSpeed), 165);
const x = ballRadius * Math.sin(ballAngle);
const y = -ballRadius * Math.cos(ballAngle);
$ball.translate(x, y);
}
});
animation = animate((t, dt) => {
wheelSpeed *= 0.995;
wheelAngle = (wheelAngle + dt * wheelSpeed) % (2 * Math.PI);
ballSpeed *= 0.985;
if (Math.abs(ballSpeed) > 0.00032) {
ballAngle = (ballAngle + dt * ballSpeed) % (2 * Math.PI);
} else {
if (!ballOffset) ballOffset = roundTo(ballAngle - wheelAngle, 2 * Math.PI/ 37);
ballAngle = wheelAngle + ballOffset;
}
let ballRadius = Math.min(116 + 87500 * Math.abs(ballSpeed), 165);
draw(wheelAngle, ballAngle, ballRadius);
return wheelSpeed;
});
}
function pfn(p: Point) {
const q = $chart.plotToMathCoords(p);
const x = clamp(roundTo(q.x, 0.5), -4, 4);
return $chart.mathToPlotCoords(new Point(x, 1.5 * x));
}
move(p) {
let r = roundTo(p.subtract(drag.position).length, 20);
$outline.setAttr('r', r);
$outlineHalo.setAttr('r', r);
rReady = (r === 60);
if (rReady && cReady) complete(c[3], $handle, $outline, $outlineHalo);
}
});