Java Float Number Clamp clampNumberFromTime(long ms, float seconds)

Here you can find the source of clampNumberFromTime(long ms, float seconds)

Description

clamp Number From Time

License

Open Source License

Declaration

public static float clampNumberFromTime(long ms, float seconds) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static float clampNumberFromTime(long ms, float seconds) {
        float f = getNumberFromTime(ms, seconds);
        if (f >= 0.5f) {
            return 1f - f;
        } else/*from www .j a v  a2s . c  o  m*/
            return f;
    }

    public static float clampNumberFromTime(float sec) {
        return clampNumberFromTime(System.currentTimeMillis(), sec);
    }

    /**
     * get a number from 0, 1 based on time
     * 
     * @return
     */
    public static float getNumberFromTime() {
        return getNumberFromTime(System.currentTimeMillis(), 1);
    }

    public static float getNumberFromTime(float seconds) {
        return getNumberFromTime(System.currentTimeMillis(), seconds);
    }

    public static float getNumberFromTime(long time, float seconds) {
        if (seconds == 0)
            throw new IllegalArgumentException("Seconds cannot be zero!");
        return ((time % Math.round((seconds * 1000))) / (seconds * 1000f));
    }
}

Related

  1. clampColour(float value)
  2. clampDegree0To360(float degree)
  3. clampFloat(float value, float minimum, float maximum)
  4. clampLevel(float level)
  5. clampLevel(float level)
  6. clampPercentage(float value)
  7. clampRoundByte(float in)
  8. clampToMinusOneToOne(float value)
  9. clampToPositiveNonZero(float value)