Skip to content

Instantly share code, notes, and snippets.

@n1ckfg
Last active November 7, 2017 16:58
Show Gist options
  • Save n1ckfg/5224660 to your computer and use it in GitHub Desktop.
Save n1ckfg/5224660 to your computer and use it in GitHub Desktop.
PVector p = new PVector(320, 240);
PVector t = p;
PVector e = new PVector(100, 100);
void setup() {
size(640, 480);
noCursor();
}
void draw() {
t = new PVector(mouseX, mouseY);
p.x = tween(p.x,t.x,e.x);
p.y = tween(p.y,t.y,e.y);
background(0);
noStroke();
fill(255);
ellipseMode(CENTER);
ellipse(p.x, p.y, 5, 5);
fill(255, 0, 0);
ellipse(t.x, t.y, 5, 5);
if(e.x>5){
e.x--;
e.y = e.x;
}
}
float tween(float v1, float v2, float e) {
v1 += (v2-v1)/e;
return v1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment