get/set emotions


  
                  function getEmotion(strength,fraction) {
                      if (fraction > 5)      return getJoy(strength);
                      else if (fraction > 4) return getDisgust(strength);
                      else if (fraction > 3) return getAnger(strength);
                      else if (fraction > 2) return getSad(strength);
                      else if (fraction > 1) return getFear(strength);
                      else return getSurprise(strength);
                  }
                  function set_emotion(value,time) {
                      // 0 <= value[0] < 2 PI
                      // 0 <= value[1] < 1
                      fraction = (value[0] / (2*Math.PI)) * 6;
                      strength = value[1] * 10;
  //Browser.print('set_emotion '+fraction+'   strength '+strength);
                      
                      if (strength < 0.5) {
                          setFrame = neutral;
                      }
                      f1 = fraction;     if(f1<0)  f1 += 6;
                      f2 = fraction + 1; if(f2>6)  f2 -= 6;
                      em1 = getEmotion(strength  ,f1);
                      em2 = getEmotion(strength  ,f2);
                      em3 = getEmotion(strength+1,f1);
                      em4 = getEmotion(strength+1,f2);
                      while(strength>1) strength -= 1;
                      while(fraction>1) fraction -= 1;
  //Browser.print('f1 '+f1+'   f2 '+f2+'  fraction '+fraction);
                      interpolateEmotions(strength,fraction,em1,em2,em3,em4);
                      
                  }
              "
          }
  
      ]
  }