def __init__(self, delay, minValue, maxValue, step, function): """Specify a time interval ('delay', in milliseconds), the min and max values within which to oscillate, the 'step' increment by which to advance the oscillating value at every time interval, and finally the function to call when the time interval has passed. This function is passed on argument, namely the current value of the oscillator. """ self.minValue = minValue # the lowest point of the oscillating value self.maxValue = maxValue # the highest point of the oscillating value self.function = function # the function to call passing it the oscillating value # initialize oscillation self.oscillatorPhase = 0.0 # ranges from -0 to 2*pi self.oscillatingValue = mapValue( cos(self.oscillatorPhase), -1.0, 1.0, self.minValue, self.maxValue) # convert the step increment to an angle/phase increment (in radians) # NOTE: 'step' is allowed to range be between 0 and self.maxValue-self.minValue - as anything smaller # or larger does not make much sense. self.stepPhase = mapValue(step, 0.0, self.maxValue-self.minValue, 0.0, 2*pi) # define timer self.timer = Timer(delay, self.__oscillate__, [], True) # remember that this timer has been created and is active (so that it can be stopped/terminated by JEM, if desired) __ActiveTimers__.append(self)
def __init__(self, delay, minValue, maxValue, step, function): """Specify a time interval ('delay', in milliseconds), the min and max values within which to oscillate, the 'step' increment by which to advance the oscillating value at every time interval, and finally the function to call when the time interval has passed. This function is passed on argument, namely the current value of the oscillator. """ self.minValue = minValue # the lowest point of the oscillating value self.maxValue = maxValue # the highest point of the oscillating value self.function = function # the function to call passing it the oscillating value # initialize oscillation self.oscillatorPhase = 0.0 # ranges from -0 to 2*pi self.oscillatingValue = mapValue( cos(self.oscillatorPhase), -1.0, 1.0, self.minValue, self.maxValue) # convert the step increment to an angle/phase increment (in radians) self.stepPhase = mapValue(step, self.minValue, self.maxValue, 0.0, 2*pi) # define timer self.timer = Timer(delay, self.__oscillate__, [], True)
def __oscillate__(self): """It calls the callback function with the current oscillator value, and calculates the next oscillator value.""" # *** print "phase =", self.oscillatorPhase, ", value =", self.oscillatingValue self.function( self.oscillatingValue ) # advance angle and wrap around self.oscillatorPhase = (self.oscillatorPhase + self.stepPhase) % (2*pi) # caclulate new oscillation value self.oscillatingValue = mapValue( cos(self.oscillatorPhase), -1.0, 1.0, self.minValue, self.maxValue)
def __oscillate__(self): """It calls callback function with current oscillator value, and calculates next oscillator value.""" # *** #print "phase =", self.oscillatorPhase, ", value =", self.oscillatingValue self.function( self.oscillatingValue ) # advance angle and wrap around self.oscillatorPhase = (self.oscillatorPhase + self.stepPhase) % (2*pi) # caclulate new oscillation value self.oscillatingValue = mapValue( cos(self.oscillatorPhase), -1.0, 1.0, self.minValue, self.maxValue)
def __init__(self, delay, minValue, maxValue, step, function): """Specify a time interval ('delay', in milliseconds), the min and max values within which to oscillate, the 'step' increment by which to advance the oscillating value at every time interval, and finally the function to call when the time interval has passed. This function is passed on argument, namely the current value of the oscillator. """ self.minValue = minValue # the lowest point of the oscillating value self.maxValue = maxValue # the highest point of the oscillating value self.function = function # the function to call passing it the oscillating value # initialize oscillation self.oscillatorPhase = 0.0 # ranges from -0 to 2*pi self.oscillatingValue = mapValue(cos(self.oscillatorPhase), -1.0, 1.0, self.minValue, self.maxValue) # convert the step increment to an angle/phase increment (in radians) self.stepPhase = mapValue(step, self.minValue, self.maxValue, 0.0, 2 * pi) # define timer self.timer = Timer(delay, self.__oscillate__, [], True)