Skip to content

Instantly share code, notes, and snippets.

@lmccart
Created September 15, 2015 19:38
Show Gist options
  • Save lmccart/7f0d5194496c741d65e4 to your computer and use it in GitHub Desktop.
Save lmccart/7f0d5194496c741d65e4 to your computer and use it in GitHub Desktop.
example.js
var x = 0;
var y = 0;
var easing = 0.05; // smaller means slower follow, bigger means faster follow
function setup() {
createCanvas(600, 400);
x = mouseX;
y = mouseY;
noFill();
}
function draw() {
background(255, 10);
// easing step
var diffx = mouseX - x;
var diffy = mouseY - y;
x = x + easing * diffx;
y = y + easing * diffy;
// add a little jitter to endpoint
x = x + random(-20, 20);
y = y + random(-20, 20);
// line(x, y, mouseX, mouseY);
stroke(0);
bezier(x, y, x + random(-100, 0), y + random(0, 100), mouseX + random(0, 100), mouseY + random(-100, 0), mouseX, mouseY);
var offx = -5 * diffx; // 100;
var offy = -5 * diffy; // 0;
stroke(255, 0, 0);
bezier(x+offx, y, x + random(-100, 0), y + random(0, 100), mouseX + random(0, 100), mouseY + random(-100, 0), mouseX+offx, mouseY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment