Smooth Number

<script src="./point_src/smooth-number"></script>

The SmoothNumber class receives fast number updates, and returns a averaged number when queried.

    const smoothVal = new SmoothNumber()
    speedNumber.push(stage.mouse.speed())

    stage.fps.text = speedNumber

A SmoothNumber combines a average of many values in a list, visually updated a (Framerate) modulo speed.

Push numbers into the list, to get an average over time allows for nicer-looking updates on a fast changing number, such as the FPS.

Setup

Create a new instance of the SmoothNumber:

const initValue = 40
    , width = 20      // how many historical points
    , updateRate = 10 // every X frames
    , valueFix = 0    // value.toFixed

const smoothVal = new SmoothNumber(initValue, width, updateRate, valueFix)

Then we can push a value to it:

smoothVal.push(currentFPS)

It can be done many (many) times. When required, we read the number:

smoothVal.get()

This secretly returns the smoothVal.value - but checks to ensure the value is fresh.

Easier

To save the hassle of pushing then getting a number, we can do this with one call.

fpsValue = this.smoothVal.pushGet(Math.round(currentFPS)+1)

This adheres to the update-rate, so the number fpsValue will change slower than directly reading currentFPS.

This is nicer for humans - as most of them can't read text at 60FPS+ apparently?

Meta Data
title Smooth Number
dependencies ()
unused_keys ()
unknown_keys ()
filepath_exists True
path smooth-number
filepath smooth-number.js
clean_files ()

  • ClassDeclaration
    class comments:

    title: Smooth Number

    The SmoothNumber class receives fast number updates, and returns a averaged number when queried.

        const smoothVal = new SmoothNumber()
        speedNumber.push(stage.mouse.speed())
    
        stage.fps.text = speedNumber
    

    A SmoothNumber combines a average of many values in a list, visually updated a (Framerate) modulo speed.

    Push numbers into the list, to get an average over time allows for nicer-looking updates on a fast changing number, such as the FPS.

    Setup

    Create a new instance of the SmoothNumber:

    const initValue = 40
        , width = 20      // how many historical points
        , updateRate = 10 // every X frames
        , valueFix = 0    // value.toFixed
    
    const smoothVal = new SmoothNumber(initValue, width, updateRate, valueFix)
    

    Then we can push a value to it:

    smoothVal.push(currentFPS)
    

    It can be done many (many) times. When required, we read the number:

    smoothVal.get()
    

    This secretly returns the smoothVal.value - but checks to ensure the value is fresh.

    Easier

    To save the hassle of pushing then getting a number, we can do this with one call.

    fpsValue = this.smoothVal.pushGet(Math.round(currentFPS)+1)
    

    This adheres to the update-rate, so the number fpsValue will change slower than directly reading currentFPS.

    This is nicer for humans - as most of them can't read text at 60FPS+ apparently?

    A SmoothNumber provides a nicer read-back of a number over a period of time. Similar to the FPS counter.

    Create an instance and push a number when required.
    Read the _value_ through a few routines.
    
    Create:
        const initValue = 40
        width = 20      // how many historical points
        updateRate = 10 // every X frames
        valueFix = 0    // value.toFixed
        const smoothVal = new SmoothNumber(initValue, width, updateRate, valueFix)
        smoothVal.push(currentFPS)
    
    Read:
    
        smoothVal.get()
    
    Push + Read:
    
        b = this.smoothVal.pushGet(Math.round(currentFPS)+1)
    
    • property

      modulusRate

      = 1
      from SmoothNumber
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • property

      width

      = 20
      from SmoothNumber
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • property

      fixed

      = 0
      from SmoothNumber
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos'])
    • constructor

      constructor

      (
      value , width = 10 , modulusRate = 1 , fixed
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      pushGet

      (
      val
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Apply a value, and return the current smooth value This returned the cached value not a new one.

    • method

      push

      (
      val
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      get

      (
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      [Symbol.toPrimitive]

      (
      hint
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      return this.value;

    • method

      update

      (
      modulusRate , val = 1
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      modUpdate

      (
      inc , modulusRate
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])

      Perform an update if the modulo matches, return the value

    • method

      mutateCompute

      (
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      computeValue

      (
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      fixValue

      (
      r , fixed
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      incrementPush

      (
      storeValue , tick = 1
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    • method

      reset

      (
      value
      )
      from SmoothNumber
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos'])
    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])