xxxxxxxxxx
34
var px = 0;
var py = 0;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(200);
var A = 0.965;
var B = 1.0 - A;
var targetX = mouseX;
var targetY = mouseY;
var qx = px; // stash previous values.
var qy = py;
px = A*px + B*targetX;
py = A*py + B*targetY;
var dx = px - qx;
var dy = py - qy;
var orientation = atan2(dy, dx);
push();
rectMode(CENTER);
translate(px, py);
rotate(orientation);
rect(0,0, 40, 40);
ellipse(20,-20, 20,20);
ellipse(20,20, 20,20);
pop();
}