1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-30 19:50:01 +02:00
This commit is contained in:
Pomax
2016-01-12 13:39:35 -08:00
parent 98bb8d5a86
commit 8db94a3f50
26 changed files with 129 additions and 93 deletions

View File

@@ -252,7 +252,7 @@ var Graphic = React.createClass({
setCurve: function(c) {
var pts = [];
c = (typeof c === "array") ? c : Array.prototype.slice.call(arguments);
c = (c instanceof Array) ? c : Array.prototype.slice.call(arguments);
c.forEach(nc => {
pts = pts.concat(nc.points);
});
@@ -380,7 +380,7 @@ var Graphic = React.createClass({
},
drawHull: function(curve, t, offset) {
var hull = typeof curve === "array" ? curve : curve.hull(t);
var hull = (curve instanceof Array) ? curve : curve.hull(t);
if(hull.length === 6) {
this.drawLine(hull[0], hull[1], offset);
this.drawLine(hull[1], hull[2], offset);

View File

@@ -1,7 +1,7 @@
var React = require('react');
var Ribbon = React.createClass({
getInitialState() {
getInitialState: function() {
return {
href: "http://github.com/pomax/BezierInfo-2"
};

View File

@@ -36,7 +36,7 @@ var ABC = React.createClass({
var h = api.getPanelHeight();
api.setColor("black");
if (!!api.t) {
if (api.t) {
api.drawCircle(api.curve.get(api.t),3);
api.setColor("lightgrey");
var hull = api.drawHull(curve, api.t);
@@ -51,7 +51,7 @@ var ABC = React.createClass({
api.setColor("lightgrey");
api.drawLine(curve.points[0], curve.points[2]);
} else if(hull.length === 10) {
A = hull[5]
A = hull[5];
B = hull[9];
C = utils.lli4(A, B, curve.points[0], curve.points[3]);
api.setColor("lightgrey");
@@ -79,7 +79,7 @@ var ABC = React.createClass({
},
setCT: function(evt,api) {
api.t = evt.offsetX / api.getPanelWidth();
api.t = evt.offsetX / api.getPanelWidth();
},
drawCTgraph: function(api) {
@@ -94,7 +94,7 @@ var ABC = React.createClass({
var value = api.u(t),
res = { x: pad + t*fwh, y: pad + value*fwh };
return res;
}
};
api.drawFunction(uPoint);
if (api.t) {
var v = api.u(api.t),
@@ -124,7 +124,7 @@ var ABC = React.createClass({
drawCCT: function(api) {
api.u = api.u || function(t) {
var top = (1-t) * (1-t) * (1-t),
bottom = t*t*t + top;
bottom = t*t*t + top;
return top/bottom;
};
this.drawCTgraph(api);

View File

@@ -28,8 +28,8 @@ var Introduction = React.createClass({
},
values: {
"38": 0.1, // up arrow
"40": -0.1, // down arrow
"38": 0.1, // up arrow
"40": -0.1 // down arrow
},
onKeyDown: function(e, api) {

View File

@@ -38,7 +38,7 @@ var ArclengthApprox = React.createClass({
var len = curve.length();
var alen = 0;
for(var i=0,p0,p1,dx,dy; i<pts.length-1; i++) {
for(var i=0,p1,dx,dy; i<pts.length-1; i++) {
p0 = pts[i];
p1 = pts[i+1];
dx = p1.x-p0.x;
@@ -52,8 +52,8 @@ var ArclengthApprox = React.createClass({
},
values: {
"38": 1, // up arrow
"40": -1, // down arrow
"38": 1, // up arrow
"40": -1 // down arrow
},
onKeyDown: function(e, api) {

View File

@@ -32,16 +32,13 @@ var CatmullRomMoulding = React.createClass({
convert: function(p1, p2, p3, p4) {
var t = 0.5;
return [
p2,
{
p2, {
x: p2.x + (p3.x-p1.x)/(6*t),
y: p2.y + (p3.y-p1.y)/(6*t),
},
{
y: p2.y + (p3.y-p1.y)/(6*t)
}, {
x: p3.x - (p4.x-p2.x)/(6*t),
y: p3.y - (p4.y-p2.y)/(6*t),
},
p3
y: p3.y - (p4.y-p2.y)/(6*t)
}, p3
];
},

View File

@@ -35,7 +35,7 @@ var Circles = React.createClass({
y: api.h/2,
r: api.r,
s: api.angle < 0 ? api.angle : 0,
e: api.angle < 0 ? 0 : api.angle,
e: api.angle < 0 ? 0 : api.angle
};
api.drawArc(p);
api.setColor("black");

View File

@@ -77,7 +77,7 @@ var CirclesCubic = React.createClass({
y: api.h/2,
r: api.r,
s: api.angle < 0 ? api.angle : 0,
e: api.angle < 0 ? 0 : api.angle,
e: api.angle < 0 ? 0 : api.angle
};
api.drawArc(p);

View File

@@ -24,7 +24,7 @@ var Control = React.createClass({
api.setRandomColor();
api.drawFunction(generator);
api.setFill(api.getColor());
if (!!label) api.text(label, where);
if (label) api.text(label, where);
},
drawLerpBox: function(api, dim, pad, p) {
@@ -38,7 +38,7 @@ var Control = React.createClass({
drawLerpPoint: function(api, tf, pad, fwh, p) {
p.y = pad + tf*fwh;
api.drawCircle(p, 3)
api.drawCircle(p, 3);
api.setFill("black");
api.text(((tf*10000)|0)/100 + "%", {x:p.x+10, y:p.y+4});
api.noFill();
@@ -136,19 +136,19 @@ var Control = React.createClass({
api.drawAxes(pad, "t",0,1, "S","0%","100%");
var factors = [1,15,105,455,1365,3003,5005,6435,6435,5005,3003,1365,455,105,15,1]
var factors = [1,15,105,455,1365,3003,5005,6435,6435,5005,3003,1365,455,105,15,1];
var p = api.hover;
var p = api.hover, n;
if (p && p.x >= pad && p.x <= dim-pad) {
this.drawLerpBox(api, dim, pad, p);
for(var n=0; n<=15; n++) {
for(n=0; n<=15; n++) {
var t = (p.x-pad)/fwh,
tf = factors[n] * Math.pow(1-t, 15-n) * Math.pow(t, n);
this.drawLerpPoint(api, tf, pad, fwh, p);
}
}
for(var n=0; n<=15; n++) {
for(n=0; n<=15; n++) {
var label = false, position = false;
if (n===0) {
label = "first term";

View File

@@ -102,9 +102,9 @@ var CurveIntersections = React.createClass({
});
// filter out likely duplicates
var curr = results[0], _, same = ((a,b) => abs(a.t1-b.t1) < 0.01 && abs(a.t2-b.t2) < 0.01);
for(var i=1; i<results.length; i++) {
var _ = results[i];
var curr = results[0], _, i, same = ((a,b) => abs(a.t1-b.t1) < 0.01 && abs(a.t2-b.t2) < 0.01);
for(i=1; i<results.length; i++) {
_ = results[i];
if (same(curr, _)) {
results.splice(i--,1);
} else { curr = _; }

View File

@@ -33,8 +33,8 @@ var Derivatives = React.createClass({
<p>Or, in plain text: the derivative of an n<sup>th</sup> degree Bézier curve is an (n-1)<sup>th</sup>
degree Bézier curve, with one fewer term, and new weights w'<sub>0</sub>...w'<sub>n-1</sub> derived
from the original weights as n(w<sub>i+1</sub> - w<sub>i</sub>), so for a 3rd degree curve, with four weights,
the derivative has three new weights w'<sub>0</sub>=3(w<sub>1</sub>-w<sub>0</sub>),
w'<sub>1</sub>=3(w<sub>2</sub>-w<sub>1</sub>) and w'<sub>2</sub>= 3(w<sub>3</sub>-w<sub>2</sub>).</p>
the derivative has three new weights w'<sub>0</sub> = 3(w<sub>1</sub>-w<sub>0</sub>),
w'<sub>1</sub> = 3(w<sub>2</sub>-w<sub>1</sub>) and w'<sub>2</sub> = 3(w<sub>3</sub>-w<sub>2</sub>).</p>
<div className="note">
<h3>"Slow down, why is that true?"</h3>

View File

@@ -10,8 +10,8 @@ var Explanation = React.createClass({
},
values: {
"38": 0.1, // up arrow
"40": -0.1, // down arrow
"38": 0.1, // up arrow
"40": -0.1 // down arrow
},
onKeyDown: function(e, api) {

View File

@@ -40,8 +40,8 @@ var Flattening = React.createClass({
},
values: {
"38": 1, // up arrow
"40": -1, // down arrow
"38": 1, // up arrow
"40": -1 // down arrow
},
onKeyDown: function(e, api) {

View File

@@ -36,8 +36,8 @@ var GraduatedOffsetting = React.createClass({
},
values: {
"38": 1, // up arrow
"40": -1, // down arrow
"38": 1, // up arrow
"40": -1 // down arrow
},
onKeyDown: function(e, api) {

View File

@@ -113,7 +113,7 @@ var Moulding = React.createClass({
p1 = {x: api.newB.x + dbl.x, y: api.newB.y + dbl.y},
sc1 = {
x: api.newA.x - (api.newA.x - p1.x)/(1-api.t),
y: api.newA.y - (api.newA.y - p1.y)/(1-api.t),
y: api.newA.y - (api.newA.y - p1.y)/(1-api.t)
},
// find new point on c2--e
p2 = {x: api.newB.x + dbr.x, y: api.newB.y + dbr.y},

View File

@@ -41,7 +41,7 @@ var Offsetting = React.createClass({
var offset = curve.offset(api.distance);
offset.forEach(c => {
api.drawCircle(c.points[0],1);
api.drawCurve(c)
api.drawCurve(c);
});
last = offset.slice(-1)[0];
api.drawCircle(last.points[3] || last.points[2],1);
@@ -50,15 +50,15 @@ var Offsetting = React.createClass({
offset = curve.offset(-api.distance);
offset.forEach(c => {
api.drawCircle(c.points[0],1);
api.drawCurve(c)
api.drawCurve(c);
});
last = offset.slice(-1)[0];
api.drawCircle(last.points[3] || last.points[2],1);
},
values: {
"38": 1, // up arrow
"40": -1, // down arrow
"38": 1, // up arrow
"40": -1 // down arrow
},
onKeyDown: function(e, api) {

View File

@@ -40,7 +40,7 @@ var PointCurves = React.createClass({
t3 = t*t*t,
mt3 = mt*mt*mt,
bottom = t3 + mt3,
top = bottom - 1
top = bottom - 1;
return abs(top/bottom);
},
@@ -65,7 +65,7 @@ var PointCurves = React.createClass({
B = api.lpts[1],
C = {
x: (S.x + E.x)/2,
y: (S.y + E.y)/2,
y: (S.y + E.y)/2
};
api.setColor("blue");
api.drawLine(S, E);
@@ -75,8 +75,8 @@ var PointCurves = React.createClass({
A = {
x: B.x + (B.x-C.x)/ratio,
y: B.y + (B.y-C.y)/ratio
},
curve = new api.Bezier([S, A, E]);
};
curve = new api.Bezier([S, A, E]);
api.setColor("lightgrey");
api.drawLine(A, B);
api.drawLine(A, S);
@@ -108,7 +108,7 @@ var PointCurves = React.createClass({
B = api.lpts[1],
C = {
x: (S.x + E.x)/2,
y: (S.y + E.y)/2,
y: (S.y + E.y)/2
};
api.setColor("blue");
@@ -155,7 +155,7 @@ var PointCurves = React.createClass({
y: E.y + (v2.y-E.y)*2
};
var curve = new api.Bezier([S, nc1, nc2, E]);
curve = new api.Bezier([S, nc1, nc2, E]);
api.drawLine(e1, e2);
api.setColor("lightgrey");
api.drawLine(A, C);

View File

@@ -23,7 +23,7 @@ var PolyBezier = React.createClass({
// subsequent curve
{x:pad,y:h-pad}, {x:pad,y:cy},
// final curve control point
{x:pad,y:pad},
{x:pad,y:pad}
];
api.lpts = pts;
},

View File

@@ -48,7 +48,7 @@ var Reordering = React.createClass({
q[i] = {
x: q[i].x + (q[i+1].x - q[i].x) * t,
y: q[i].y + (q[i+1].y - q[i].y) * t
}
};
}
q.splice(q.length-1, 1);
}

View File

@@ -42,20 +42,19 @@ var TightBounds = React.createClass({
ty = offset.y,
cos = Math.cos,
sin = Math.sin,
v = [points.x.min, points.y.min, points.x.max, points.y.max],
points = [
{x: v[0], y: v[1] },
{x: v[2], y: v[1] },
{x: v[2], y: v[3] },
{x: v[0], y: v[3] }
].map(p => {
var x=p.x, y=p.y;
return {
x: x*cos(angle) - y*sin(angle) + tx,
y: x*sin(angle) + y*cos(angle) + ty
};
});
return points;
v = [points.x.min, points.y.min, points.x.max, points.y.max];
return [
{x: v[0], y: v[1] },
{x: v[2], y: v[1] },
{x: v[2], y: v[3] },
{x: v[0], y: v[3] }
].map(p => {
var x=p.x, y=p.y;
return {
x: x*cos(angle) - y*sin(angle) + tx,
y: x*sin(angle) + y*cos(angle) + ty
};
});
},
draw: function(api, curve) {

View File

@@ -61,8 +61,8 @@ var Tracing = React.createClass({
},
values: {
"38": 1, // up arrow
"40": -1, // down arrow
"38": 1, // up arrow
"40": -1 // down arrow
},
onKeyDown: function(e, api) {
@@ -102,7 +102,7 @@ var Tracing = React.createClass({
ts.push(pts[p]);
}
for(var i=0; i<pts.length-1; i++) {
for(i=0; i<pts.length-1; i++) {
api.drawLine(pts[i], pts[i+1], offset);
}
@@ -117,15 +117,15 @@ var Tracing = React.createClass({
api.drawLine(pd, {x:pt.x, y:pd.y}, offset);
});
var offset = {x:2*w, y:0};
offset = {x:2*w, y:0};
api.drawLine({x:0,y:0}, {x:0,y:h}, offset);
var idx=0, colors = ["rgb(240,0,200)", "rgb(0,40,200)"];
api.setColor(colors[idx]);
var p0 = curve.get(pts[0].t);
var p0 = curve.get(pts[0].t), p1;
api.drawCircle(curve.get(0), 4, offset);
for (var i=1, p1; i<pts.length; i++) {
for (i=1, p1; i<pts.length; i++) {
p1 = curve.get(pts[i].t);
api.drawLine(p0, p1, offset);
if (ts.indexOf(pts[i]) !== -1) {

View File

@@ -24,7 +24,8 @@ var Whatis = React.createClass({
p2=pts[1],
p3 = pts[2],
p1e, p2e, m, t, i,
offset = {x:0, y:0};
offset = {x:0, y:0},
d,v,tvp;
api.reset();
@@ -44,7 +45,7 @@ var Whatis = React.createClass({
api.text("Curve points generated this way", {x:5, y:15}, offset);
api.setColor("lightgrey");
for(var t=1,d=20,v,tvp; t<d; t++) {
for(t=1,d=20,v,tvp; t<d; t++) {
v = t/d;
tvp = curve.get(v);
api.drawCircle(tvp,2,offset);
@@ -68,7 +69,7 @@ var Whatis = React.createClass({
m = {
x: p1e.x + t * (p2e.x - p1e.x),
y: p1e.y + t * (p2e.y - p1e.y)
}
};
offset = {x:0, y:0};
api.drawCircle(p1e,3, offset);
@@ -98,8 +99,8 @@ var Whatis = React.createClass({
},
values: {
"38": 1, // up arrow
"40": -1, // down arrow
"38": 1, // up arrow
"40": -1 // down arrow
},
onKeyDown: function(e, api) {