home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / ANIM / SLOW_IN_.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  3.7 KB  |  119 lines

  1. package sub_arctic.anim;
  2.  
  3. /**
  4.  * Implements the pacing function for a slow in slow out, ala the artkit
  5.  * pacing function of the same name. This function has two transition
  6.  * points, one for the end of the slow in and the other for the end
  7.  * of the slow out. These must be symmetrical, i.e. if you supply
  8.  * boundary value of 0.2 to the constructor the first 20% of the
  9.  * time will be slow in and the last 20% will be in the slow_out.<p>
  10.  *
  11.  * @author Ian Smith
  12.  */
  13. public class slow_in_slow_out implements pacer {
  14.  
  15.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  16.  
  17.   /**
  18.    * Where to end the slow in, and where to begin the slow out (although 
  19.    * 1-_boundary is more correct for where to begin the slow out). 
  20.    */
  21.   protected double _boundary;
  22.  
  23.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  24.  
  25.   /**
  26.    * What is the amount of of time covered by the slow in and slow out?
  27.    */
  28.   protected double _val_at_boundary;
  29.  
  30.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  31.  
  32.   /**
  33.    * Construct a slow in slow out pacer. <P>
  34.    * 
  35.    * Providing the values 0.2 and 0.4 to this constructor would 
  36.    * cause the following to happen: <P>
  37.    * <OL>
  38.    * <LI> The first 40% of the actual time would be spent in the first 20% 
  39.    *      of the transition (slow in)
  40.    * <LI> The middle part of the transition would occur, and would occupy 20% 
  41.    *      of the actual time
  42.    * <LI> The final 40% of the actual time would be spent in the final 20% of 
  43.    *      the transition
  44.    * </OL>
  45.    *
  46.    * @param double bnd at what percent of the transition to end the slow in 
  47.    *                   and (symmetrically) at what point from the end of the 
  48.    *                   transition to begin the slow out. 
  49.    * @param double val the value of the pacing function at the end of the 
  50.    *                   slow-in (this is also symmetrical) 
  51.    */
  52.   public slow_in_slow_out(double bnd, double val) {
  53.  
  54.     /* assign the values */
  55.     _boundary=bnd;
  56.     _val_at_boundary=val;
  57.  
  58.     /* validity check boundary */
  59.     if (_boundary > 0.5) {
  60.       _boundary = 0.5;
  61.     } else {
  62.       if (_boundary <= 0.0) {
  63.     _boundary = 0.001;
  64.       }
  65.     }
  66.  
  67.     /* other validity check */
  68.     if (_val_at_boundary < 0.0) {
  69.       _val_at_boundary = 0.0;
  70.     } else {
  71.       if (_val_at_boundary > 1.0) {
  72.     _val_at_boundary = 1.0;
  73.       }
  74.     }
  75.  
  76.   }
  77.  
  78.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  79.  
  80.   /**
  81.    * Perform the transformation.
  82.    * @param double t the value to transform (time value from 0.0 to 1.0)
  83.    * @return double the transformed value under the slow-in-slow-out parameters
  84.    */
  85.   public double pace(double t) {
  86.     /* leaving */
  87.     if (t < _boundary) {
  88.       return t*_val_at_boundary/_boundary;
  89.     } else {   /* arriving */
  90.       if (t > 1.0-_boundary) {
  91.         return (1-_val_at_boundary) + 
  92.           (t-(1-_boundary))*_val_at_boundary/_boundary;
  93.       }  else {    /* normal  */
  94.         return _val_at_boundary + 
  95.       (t-_boundary)* (1-2*_val_at_boundary)/(1-2*_boundary);
  96.       }
  97.     }
  98.   }
  99.  
  100.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  101. }
  102.  
  103. /*=========================== COPYRIGHT NOTICE ===========================
  104.  
  105. This file is part of the subArctic user interface toolkit.
  106.  
  107. Copyright (c) 1996 Scott Hudson and Ian Smith
  108. All rights reserved.
  109.  
  110. The subArctic system is freely available for most uses under the terms
  111. and conditions described in 
  112.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  113. and appearing in full in the lib/interactor.java source file.
  114.  
  115. The current release and additional information about this software can be 
  116. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  117.  
  118. ========================================================================*/
  119.