Jump to content

User:Ember314/lerp.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*** this is a simple script that uses linear interpolation to make an object nicely follow your cursor
 * use as you like
 * see if I care
 ***/
 var FOLLOW_AMNT = 0.15; //change this if you want
$('body').prepend('<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.min.js" integrity="sha512-WJXVjqeINVpi5XXJ2jn0BSCfp0y80IKrYh731gLRnkAS9TKc5KNt/OfLtu+fCueqdWniouJ1ubM+VI/hbo7POQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>');
$('body').prepend("<div id='funCanvas'></div>");
$('body').prepend('<style>#funCanvas{  position: absolute; left: 0; right: 0;top: 0;bottom: 0;height: 200%;width: 100%; z-index: 1000000;pointer-events: none; overflow: auto;}</style>');
var sketchHeight,
	sketchWidth,
	objX=0,
	objY=0;
function setup() {
	  sketchWidth = document.getElementById("funCanvas").offsetWidth;
  sketchHeight = document.getElementById("funCanvas").offsetHeight;
    var canvas = createCanvas(sketchWidth, sketchHeight);
    canvas.parent('funCanvas');
    	
}

function draw() {
	clear() /*optional*/
	objX=lerp(objX,mouseX,FOLLOW_AMNT);
	objY=lerp(objY,mouseY,FOLLOW_AMNT);
    circle(objX,objY,50,50)
}