Closed danieltorrer closed 8 years ago
import hype.*;
import hype.extended.behavior.HFollow;
HFollow mf;
HRect r;
void setup(){
size(900,900);
H.init(this).background(#242424);
H.add( r = new HRect(100) ).noStroke().fill(#FF3300).anchor(-50,-50);
mf = new HFollow().target(r).ease(0.05).spring(0.95);
}
void draw(){
H.drawStage();
}
the trick is changing the anchor position of the rect / .anchor(-50,-50)
BTW what HLocatable allows you to do is this...
println( mf.goal().x() );
so you could also...
import hype.*;
import hype.extended.behavior.HFollow;
HFollow mf;
HRect r;
float dx, dy;
void setup(){
size(900,900);
H.init(this).background(#242424);
H.add( r = new HRect(100) ).noStroke().fill(#FF3300);
mf = new HFollow().ease(0.05).spring(0.95);
}
void draw(){
H.drawStage();
float xPos = mf.goal().x() + 50;
float yPos = mf.goal().y() + 50;
dx = dx*mf.spring() + (xPos-r.x()) * mf.ease();
dy = dy*mf.spring() + (yPos-r.y()) * mf.ease();
r.x( r.x()+dx );
r.y( r.y()+dy );
}
only this option would be handy if you wanted to track the mouse... use ease... use spring... but apply different offsets to other objects on screen - notice the rect has no anchor - and the offset of 50 is done in xPos and yPos
Thanks man, i'm planning to track finger movements with the leap motion and draw a Hshape near each finger so the second example suits me better.
rocking!
I want to make an
HFollow
and aHRect
to follow it. But instead of following the mouse I want to build theHFollow
with custom coordinates ( e.g.mouseX + 50, mouseY + 50
).Is there a way i can achieve this? In the docs I see a reference to a
HLocatable
. Do I need to build a customHLocatable
with my coordinates and pass it to theHFollow
?