Permalink
Browse files

stillness detection

  • Loading branch information...
1 parent 15e0441 commit 06781f65c5b18b865739231d248d9a6358f08a0e unknown committed Apr 20, 2012
Showing with 29 additions and 12 deletions.
  1. +18 −6 Person.pde
  2. +11 −6 spt.pde
View
@@ -1,25 +1,37 @@
class Person{
int x;
int y;
+ float t;
+ float speed;
+ float lastmoved;
int r=50;
- boolean selected=false;
- boolean moved=false;
Person(int x, int y){
this.x=x;
this.y=y;
+ this.t=millis()/1000.0;
+ this.speed=0;
+ this.lastmoved=t;
+ }
+
+ boolean still(float timeout){
+ return ((millis()/1000.0)-this.lastmoved)>timeout;
}
void move(int x, int y){
- this.x+=x;
- this.y+=y;
- this.moved=true;
+ update(this.x+x,this.y+y);
}
void update(int x, int y){
+ float now = millis()/1000.0;
+ this.speed= dist(this.x,this.y,x,y)/(now-this.t);
+ if(speed>300){
+ this.lastmoved=now;
+ }
+
this.x=x;
this.y=y;
- this.moved=true;
+ this.t=now;
}
void draw(float transx,float transy,float scalex,float scaley){
View
@@ -89,11 +89,11 @@ void draw(){
int deltax=(mouseX-pmouseX);
int deltay=(mouseY-pmouseY);
person.move(deltax,deltay);
- person.draw(transx,transy,scalex,scaley);
}
+
+ println( person.still(0.75) );
- if( person.moved ){
- person.moved=false;
+ if( !person.still(0.75) ){
Point pt = person.getGeoCoord(transx,transy,scalex,scaley);
String newid = map.nearest( pt ).id;
@@ -103,12 +103,17 @@ void draw(){
for(int i=0;i<500;i++){dijkstra.step_to(150.0,true);}
image(backdrop,0,0);
+
}
}
- //for(int i=0; i<40; i++){
- // dijkstra.step(true);
- //}
+ person.draw(transx,transy,scalex,scaley);
+
+ if( person.still(0.75) ){
+ for(int i=0; i<40; i++){
+ dijkstra.step(true);
+ }
+ }
dijkstra.draw_deferred();
}

0 comments on commit 06781f6

Please sign in to comment.