JSFiddle - React, Tailwind, and code Playground
HTML
<h2> Bezier Curve </h2>
<canvas id="Editor" width="600" height="600"></canvas>
<p>
Shift: Add Point
</p>
<p>
<input type="checkbox" id="smooth" checked />
<label for="smooth"> Keep Smooth </label>
</p>
<a href="https://github.com/jareguo/curve-editor"> https://github.com/jareguo/curve-editor </a>
<!--TYPES-->
<script>
function v2 (x, y) {
return {
x: x || 0,
y: y || 0
};
}
v2.add = function (lhs, rhs) {
return v2(lhs.x + rhs.x, lhs.y + rhs.y);
};
v2.sub = function (lhs, rhs) {
return v2(lhs.x - rhs.x, lhs.y - rhs.y);
};
v2.mul = function (v, scaling) {
return v2(v.x * scaling, v.y * scaling);
};
v2.div = function (v, scaling) {
return v2(v.x / scaling, v.y / scaling);
};
v2.lerp = function (from, to, ratio) {
return v2(from.x + (to.x - from.x) * ratio, from.y + (to.y - from.y) * ratio);
};
v2.sqrDistance = function (lhs, rhs) {
var dx = lhs.x - rhs.x;
var dy = lhs.y - rhs.y;
return dx * dx + dy * dy;
};
v2.distance = function (lhs, rhs) {
return Math.sqrt(v2.sqrDistance(lhs, rhs));
};
v2.dir = function (lhs, rhs) {
var len = v2.distance(v2, {x: 0, y: 0});
return v2(v2.x / len, v2.y / len);
};
function Curve (points) {
this.points = points || [];
this.beziers = [];
this.computeBeziers();
}
Curve.prototype.computeBeziers = function () {
this.beziers.length = 0;
for (var i = 1; i <...
CSS
canvas {
border: 1px solid black;
}