xxxxxxxxxx
57
//Quartic Bezier curve vertex: https://editor.p5js.org/Codefish/sketches/W3ogOcv_t
let s;
function setup() {
createCanvas(windowHeight, windowHeight);
colorMode(HSB);
s = width/4;
}
function draw() {
background(0);
stroke(255);
strokeWeight(10);
point(0, 2*s);
point(s, s);
point(mouseX, mouseY);
point(3*s, s);
point(4*s, 2*s);
strokeWeight(5);
noFill();
quarticBezier(0, 2*s, s, s, mouseX, mouseY, 3*s, s, 4*s, 2*s);
/*stroke(0, 255, 255);
line(0, 2*s, s, s);
line(3*s, s, 4*s, 2*s);*/
}
p5.Vector.quarterp = function(v1, v2, v3, v4, v5, t) {
let l1 = p5.Vector.lerp(v1, v2, t);
let l2 = p5.Vector.lerp(v2, v3, t);
let l3 = p5.Vector.lerp(v3, v4, t);
let l4 = p5.Vector.lerp(v4, v5, t);
let q1 = p5.Vector.lerp(l1, l2, t);
let q2 = p5.Vector.lerp(l2, l3, t);
let q3 = p5.Vector.lerp(l3, l4, t);
let c1 = p5.Vector.lerp(q1, q2, t);
let c2 = p5.Vector.lerp(q2, q3, t);
let quar = p5.Vector.lerp(c1, c2, t);
return quar;
}
function quarticBezier(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5) {
beginShape();
for(let t = 0; t <= 1.000000001; t += 0.01) {
let v = p5.Vector.quarterp(createVector(x1, y1), createVector(x2, y2), createVector(x3, y3), createVector(x4, y4), createVector(x5, y5), t);
vertex(v.x, v.y);
}
endShape();
}
function quarticBezierVertex(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5) {
for(let t = 0; t <= 1.000000001; t += 0.01) {
let v = p5.Vector.quarterp(createVector(x1, y1), createVector(x2, y2), createVector(x3, y3), createVector(x4, y4), createVector(x5, y5), t);
vertex(v.x, v.y);
}
}