Package joy :: Module plans :: Class CyclePlan
[hide private]
[frames] | no frames]

Class CyclePlan

source code


A CyclePlan implements a circular list of action callbacks, indexed by 'phase' -- a real number between 0 and 1. At any given time the CyclePlan has a position (stored in the private variable ._pos) on this cycle.

The position can change by using .moveToPhase or by the passage of time, through setting a period or frequency for cycling. This frequency or period may also be negative, causing the CyclePlan to cycle in reverse order.

In abstract, it is ambiguous in which direction around the cycle a given .moveToPhase should proceed. This ambiguity is resolved by allowing the goal phase to be outside the range 0 to 1. Goals larger than current phase cycle forward and goals smaller than current phase cycle back.

Whenever phase changes, all actions in the circular arc of phases between the previous and new phase are executed in order. If the arc consists of more than one cycle, phase changes to 0, the .onCycles method is called with the integer number of positive or negative cycles, and the remaining partial cycle to the goal is called.

Instance Methods [hide private]
 
__init__(self, app, actions, maxFreq=10.0, *arg, **kw)
Instantiate a CyclePlan
source code
 
__initSteps(self, actions)
(private)
source code
 
setPeriod(self, period)
Set period for cycles, 0 to stop in place
source code
 
getPeriod(self)
Return the cycling period
source code
 
setFrequency(self, freq)
Set frequency for cycles, 0 to stop in place
source code
 
getFrequency(self)
Return the cycling frequency
source code
 
onCycles(self, cyc)
(default)
source code
 
moveToPhase(self, phi)
Move from the current phase (self.phase) to a new phase phi.
source code
 
_doActions(self, slc)
(private)
source code
 
resetPhase(self, phi0=0)
Reset phase to the specified value at the current time, without taking any actions
source code
 
behavior(self)
(final)
source code

Inherited from Plan: forDuration, isRunning, onEvent, onStart, onStop, push, start, step, stop, untilTime

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
bsearch(k, lst)
Binary search for k through the sorted sequence lst
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, app, actions, maxFreq=10.0, *arg, **kw)
(Constructor)

source code 

Instantiate a CyclePlan

INPUT:
  app -- JoyApp -- application containing this Plan instance
  actions -- dict -- mapping floating point phases in the range 0 to 1 to 
     python callable()-s that take no parameters.
  maxFreq -- float -- maximal cycling frequency allowed for this Plan.

Overrides: object.__init__

__initSteps(self, actions)

source code 

(private)

Scan actions table, construct lookup index and resolve bindings

bsearch(k, lst)
Static Method

source code 

Binary search for k through the sorted sequence lst

Returns the position of the first element larger or equal to k

onCycles(self, cyc)

source code 
(default)

Move forward or back several complete cycles, starting and
ending at phase 0

INPUT:
  cyc -- number of cycles; nonzero

The default implementation is to ignore complete cycles.
Override in subclasses if you need an accurate count of 
winding numbers.

moveToPhase(self, phi)

source code 

Move from the current phase (self.phase) to a new phase phi.

phi values larger than 1.0 will always cause forward cycling through 0.0 phi values smaller than 0.0 will cause reverse cycling though 1.0 Values in the range [0,1] will move via the shortest sequence of steps from current phase to new phase.

_doActions(self, slc)

source code 

(private)

Do the actions associated with action table entries in the specified slice

behavior(self)

source code 

(final)

CyclePlan behavior is to cycle through the actions at the period controlled by self.period

If period is set to 0, actions will only be called as consequence of calling .moveToPhase

Overrides: Plan.behavior