Advertisement
starbeamrainbowlabs

C# ease in/out test

Nov 22nd, 2015
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace EasingTest
  5. {
  6.     class MainClass
  7.     {
  8.         static int width = 75;
  9.         static int frameDelay;
  10.  
  11.         public static float QuadEaseInOut(float time)
  12.         {
  13.             return time < 0.5f ? 2.0f * time * time : -1.0f + (4.0f - 2.0f * time) * time;
  14.             //return t<.5 ? 2*t*t : -1+(4-2*t)*t
  15.         }
  16.  
  17.         public static void displayEase(float time)
  18.         {
  19.             float ease = QuadEaseInOut(time);
  20.  
  21.             int nextWidth = (int)(ease * width);
  22.             Console.Write("{0}{2}{1}\r", new string(' ', nextWidth), new String(' ', width - nextWidth), 'o');
  23.         }
  24.  
  25.         public static void Main(string[] args)
  26.         {
  27.             Console.Write("Enter the frame delay: ");
  28.             frameDelay = int.Parse(Console.ReadLine());
  29.  
  30.             int count = 0;
  31.             float step = 0.01f;
  32.             bool dir = false; // false = right->left, true = left->right
  33.             while(count < 10)
  34.             {
  35.                 if(!dir)
  36.                 {
  37.                     for(float t = step; t < 1; t += step)
  38.                     {
  39.                         displayEase(t);
  40.                         Thread.Sleep(frameDelay);
  41.                     }
  42.                     dir = true;
  43.                 }
  44.                 else
  45.                 {
  46.                     for(float t = 1; t > 0; t -= step)
  47.                     {
  48.                         displayEase(t);
  49.                         Thread.Sleep(frameDelay);
  50.                     }
  51.                     dir = false;
  52.                 }
  53.  
  54.                 count++;
  55.  
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement