Library for googly eyes

Dependents:   Eyes_Demo

Files at this revision

API Documentation at this revision

Comitter:
electromotivated
Date:
Tue Apr 12 02:30:40 2016 +0000
Parent:
1:0791bb5735b4
Commit message:
Added new method look_there(theta, dist) allowing finer control of direction and distance to look;

Changed in this revision

Eyes.cpp Show annotated file Show diff for this revision Revisions of this file
Eyes.h Show annotated file Show diff for this revision Revisions of this file
--- a/Eyes.cpp	Tue Dec 15 00:42:09 2015 +0000
+++ b/Eyes.cpp	Tue Apr 12 02:30:40 2016 +0000
@@ -25,6 +25,16 @@
     }
 }
 
+void Eyes::look_there(int theta, float dist){
+    theta = theta % 361;       // Clamp theta to 0 to 360 degrees
+    if(dist > 1.0) dist = 1.0;  // Clamp dist to 1.0 max
+    if(dist < 0.0) dist = 0.0;  // Clamp dist to 0.0 min
+    
+    int radius(eye_radius - iris_radius);
+    eye_direction_offset.x = (int)(dist*radius*cos(theta*3.14/180.0)); 
+    eye_direction_offset.y = (int)(dist*radius*sin(theta*3.14/180.0));
+}
+
 void Eyes::express(EXPRESSION expression){}
 
 void Eyes::gesture(GESTURE gesture){
@@ -56,13 +66,16 @@
                      LGREY);
             lcd.line(left_eye_center.x - eye_radius, left_eye_center.y,
                      left_eye_center.x + eye_radius, left_eye_center.y,
-                     LGREY); 
+                     LGREY);
+            break;
+            
+        case SHAKE:
+            break; 
     }
 }
 
 void Eyes::draw(){
-    /* TODO: Draw over last eye in black to "erase" before drawing 
-        new eye */
+    //Draw over last eye in black to "erase" before drawing new eye
     lcd.filled_circle(right_eye_center.x,
                       right_eye_center.y,
                       eye_radius, BLACK);
--- a/Eyes.h	Tue Dec 15 00:42:09 2015 +0000
+++ b/Eyes.h	Tue Apr 12 02:30:40 2016 +0000
@@ -21,7 +21,7 @@
     enum EXPRESSION{NORMAL, SUPRISED, SCARED, ANGRY}; 
     enum DIRECTION{U = 270, D = 90, L = 0, R = 180, C, 
                    UL= 315, UR= 225,DL= 45, DR = 135};
-    enum GESTURE{BLINK, CLOSE};
+    enum GESTURE{BLINK, CLOSE, SHAKE};
     typedef struct{int x; int y;}Coord_t;
     
     /*
@@ -36,6 +36,16 @@
     void look(DIRECTION direction);
     
     /*
+        Change the distance and direction the eyes look.
+        @param theta    The angle to look in degrees
+        @param dist     The normalized distance to look in given theta, i.e
+                        0 keeps eyes centered and 1 looks fully in given theta
+                        in between values give make eyes look more or less in 
+                        theta.
+    */
+    void look_there(int theta, float dist);
+    
+    /*
         Display a gesture. 
         
         BLINK is random ~100 to ~400ms. For user defined blink duration