Skip to content

Instantly share code, notes, and snippets.

@hell03610
Created August 5, 2013 18:31
Show Gist options
  • Save hell03610/6158245 to your computer and use it in GitHub Desktop.
Save hell03610/6158245 to your computer and use it in GitHub Desktop.
quadratic curve for processingjs
var processing_canvas = document.getElementById("processing");
animation = new Processing(processing_canvas, function($p){
$p.setup = function(){
$p.size(500, 400);
$p.strokeWeight(2);
$p.smooth();
$p.noLoop();
},
$p.draw = function(){
$p.quadraticBezierVertex(79,71,239,147,397,58);
},
$p.quadraticBezierVertex = function(x0, y0, cpx, cpy, x, y) {
var cp1x = x0+ 2.0/3.0*(cpx - x0);
var cp1y = y0 + 2.0/3.0*(cpy - y0);
var cp2x = cp1x + (x - x0)/3.0;
var cp2y = cp1y + (y - y0)/3.0;
$p.noFill();
$p.beginShape();
$p.vertex(x0, y0);
$p.bezierVertex(cp1x, cp1y, cp2x, cp2y, x, y);
$p.endShape();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment