Java tutorial
//package com.java2s; public class Main { private static double getBreathingY(long time, int n, int t) { float k = 1.0f / 3; float pi = 3.1415f; float x = time / 1000.0f; t = (int) (t / 1000.0f); if (x >= ((n - 1) * t) && x < ((n - (1 - k)) * t)) { double i = pi / (k * t) * ((x - (0.5f * k * t)) - (n - 1) * t); return 0.5f * Math.sin(i) + 0.5f; } else if (x >= ((n - (1 - k)) * t) && x < n * t) { double j = pi / ((1 - k) * t) * ((x - (0.5f * (3 - k) * t)) - (n - 1) * t); double one = 0.5f * Math.sin(j) + 0.5f; return one * one; } return 0; } }