hype / HYPE_Processing

HYPE for Processing
BSD 3-Clause "New" or "Revised" License
928 stars 149 forks source link

Question: Make HFollow with custom coordinates instead of mouse #134

Closed danieltorrer closed 8 years ago

danieltorrer commented 8 years ago

I want to make an HFollowand a HRectto follow it. But instead of following the mouse I want to build the HFollowwith 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 custom HLocatablewith my coordinates and pass it to the HFollow?

hype commented 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)

hype commented 8 years ago

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

danieltorrer commented 8 years ago

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.

hype commented 8 years ago

rocking!