duck

duck

May 6th, 2010
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.41 KB | None | 0 0
  1.  
  2. public class Oscillator {
  3.  
  4.     float min;
  5.     float max;
  6.     float value;
  7.     float velocity;
  8.     float speed;
  9.     float target;
  10.  
  11.     public Oscillator(float min, float max, float speed) {
  12.         this.min = min;
  13.         this.max = max;
  14.         this.speed = speed;
  15.         target = (min+max) * 0.5f;
  16.         value = min;
  17.     }
  18.    
  19.     public float GetNext() {
  20.         velocity += (value < target ? 1 : -1) * speed;
  21.         value += velocity;
  22.         return value;
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment