please help me with this...
I have this code which is following my mouse pointer quite smoothly, now I want to replace the mouse pointer with my tracked face.....please guide me with how to do it
float gravity = -7.0;
float mass = 10.0;
int numsprings = 5;
ArrayList springs;
void setup()
{
size(1024, 768);
smooth();
fill(255, 255, 0);
noStroke();
springs = new ArrayList();
for (int i=0; i<numsprings; i++) { // make 5 boxes
springs.add(new Spring2D(0, 0, mass, gravity)); // tell x, y position, mass and gravity
}
}
void draw()
{
background(40);
Spring2D firstspring = (Spring2D) springs.get(0); // get position of the first box
firstspring.update(mouseX, mouseY); // update the position of box one
firstspring.display(mouseX, mouseY);
for (int i=1; i<springs.size(); i++) {
Spring2D spring = (Spring2D) springs.get(i);
Spring2D backspring = (Spring2D) springs.get(i-1);
spring.update(backspring.x, backspring.y);
spring.display(backspring.x, backspring.y);
}
}
class Spring2D {
float vx, vy; // The x- and y-axis velocities
float x, y; // The x- and y-coordinates
float gravity;
float mass;
float radius = 10;
float stiffness = 0.3;
float damping = 0.7;
Spring2D(float xpos, float ypos, float m, float g) {
x = xpos;
y = ypos;
mass = m;
gravity = g;
}
void update(float targetX, float targetY) {
float forceX = (targetX - x) * stiffness;
float ax = forceX / mass;
vx = damping * (vx + ax);
x += vx;
float forceY = (targetY - y) * stiffness;
forceY += gravity;
float ay = forceY / mass;
vy = damping * (vy + ay);
y += vy;
}
void display(float nx, float ny) {
rect(x, y, 40, 20);
}
}
thanks in advance
I have this code which is following my mouse pointer quite smoothly, now I want to replace the mouse pointer with my tracked face.....please guide me with how to do it
float gravity = -7.0;
float mass = 10.0;
int numsprings = 5;
ArrayList springs;
void setup()
{
size(1024, 768);
smooth();
fill(255, 255, 0);
noStroke();
springs = new ArrayList();
for (int i=0; i<numsprings; i++) { // make 5 boxes
springs.add(new Spring2D(0, 0, mass, gravity)); // tell x, y position, mass and gravity
}
}
void draw()
{
background(40);
Spring2D firstspring = (Spring2D) springs.get(0); // get position of the first box
firstspring.update(mouseX, mouseY); // update the position of box one
firstspring.display(mouseX, mouseY);
for (int i=1; i<springs.size(); i++) {
Spring2D spring = (Spring2D) springs.get(i);
Spring2D backspring = (Spring2D) springs.get(i-1);
spring.update(backspring.x, backspring.y);
spring.display(backspring.x, backspring.y);
}
}
class Spring2D {
float vx, vy; // The x- and y-axis velocities
float x, y; // The x- and y-coordinates
float gravity;
float mass;
float radius = 10;
float stiffness = 0.3;
float damping = 0.7;
Spring2D(float xpos, float ypos, float m, float g) {
x = xpos;
y = ypos;
mass = m;
gravity = g;
}
void update(float targetX, float targetY) {
float forceX = (targetX - x) * stiffness;
float ax = forceX / mass;
vx = damping * (vx + ax);
x += vx;
float forceY = (targetY - y) * stiffness;
forceY += gravity;
float ay = forceY / mass;
vy = damping * (vy + ay);
y += vy;
}
void display(float nx, float ny) {
rect(x, y, 40, 20);
}
}
thanks in advance
1