common
Class Generator

Object
  extended by common:Generic
      extended by common:Generator
Direct Known Subclasses:
DMJ_GeneratorRandom, DMJ_TrapSelect

class 
Generic:Generator

Generator base class.

This is a generic generator class. Its purpose is to take an arbitrary initial value and produce a sequence of values of indeterminate length. This roughly corresponds to UF's native fractal formula type, except that it starts with and produces real values, not complex values. Compare this to the Formula base class.

Note that by convention, values produced from a Generator class should be in the range [0,1]. If you adhere to this convention, other classes that use Generator objects will know what range to expect.


Ultra Fractal Source

Toggle UF Source Code Display

 class Generator(Generic) {
   ; Generator base class.
   ; <p>
   ; This is a generic generator class. Its purpose is to take
   ; an arbitrary initial value and produce a sequence of
   ; values of indeterminate length. This roughly corresponds
   ; to UF's native fractal formula type, except that it starts
   ; with and produces real values, not complex values. Compare
   ; this to the Formula base class.
   ; <p>
   ; Note that by convention, values produced from a Generator
   ; class should be in the range [0,1]. If you adhere to this
   ; convention, other classes that use Generator objects will
   ; know what range to expect.
 
 public:
   ; Constructor
   ;
   ; @param pparent a reference to the object creating the new object; typically, 'this'
   func Generator(Generic pparent)
     Generic.Generic(pparent)
   endfunc
   
   ; Set up for a sequence of values
   ; <p>
   ; This function will be called at the beginning of each
   ; sequence of values (e.g. at the beginning of each fractal
   ; orbit).
   ;
   ; @param pz seed value for the sequence
   ; @return first value in the sequence
   float func Init(float pz)
     ; Base class implementation flags the sequence to end
     ; immediately. As long as you provide your own implementation
     ; of IsBailedOut(), this is irrelevant. We also clear the
     ; iteration counter.
     m_Iterations = 0
     m_BailedOut = true
     return pz
   endfunc
 
   ; Set up for a sequence of values
   ; <p>
   ; This alternate form of Init will cause the Generator to
   ; start with its "default" sequence. This can be used if a
   ; generator allows a user to select a "seed" value itself.
   ; Such Generator classes should override this function.
   ;
   ; @return first value in the sequence
   float func InitDefault()
     return Init(0)
   endfunc
   
   ; Produce the next value in the sequence
   ; <p>
   ; As long as the sequence has not bailed out, this function
   ; will be continually called to produce sequence values.
   ;
   ; @param pz previous value in the sequence. Note that you should always use this value for computing the next iteration, rather than a saved value, as the calling code may modify the returned value before passing it back to the next Iterate() call.
   ; @return the next value in the sequence
   float func Iterate(float pz)
     ; Base class implentation automatically updates the
     ; iteration counter and returns an unmodified pz
     ; (that is, the default sequence is the same value
     ; repeated infinitely).
     m_Iterations = m_Iterations + 1
     return pz
   endfunc
 
   ; Test whether the formula has bailed out (i.e. the sequence is complete)
   ; <p>
   ; This is typically called once per iteration to test whether
   ; the sequence has completed. If producing this result is
   ; difficult to do separately from the Iterate() processing,
   ; you should produce the result in Iterate() and set the
   ; m_BailedOut flag appropriately, and leave IsBailedOut()
   ; unimplemented in your class to inherit this behavior.
   ;
   ; @param pz last sequence value to test; this should be the value returned from the previous Iterate() call. Note that it is acceptable to ignore pz and use m_BailedOut, but any code calling IsBailedOut() should pass in the correct pz for Generator classes which do not use m_BailedOut.
   ; @return true if the sequence has bailed out (i.e. should be terminated)
   bool func IsBailedOut(float pz)
     return m_BailedOut
   endfunc
 
 protected:
   int m_Iterations    ; count the number of iterations
   bool m_BailedOut    ; flag indicating whether sequence has bailed out or not
 
 default:
   int param v_generator
     caption = "Version (Generator)"
     default = 100
     hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
     visible = @v_generator < 100
   endparam
 }
 


Constructor Summary
Generator()
           
Generator(Generic pparent)
          Constructor
 
Method Summary
 float Init(float pz)
          Set up for a sequence of values
 float InitDefault()
          Set up for a sequence of values
 boolean IsBailedOut(float pz)
          Test whether the formula has bailed out (i.e.
 float Iterate(float pz)
          Produce the next value in the sequence
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

Generator

public Generator(Generic pparent)
Constructor

Parameters:
pparent - a reference to the object creating the new object; typically, 'this'

Generator

public Generator()
Method Detail

Init

public float Init(float pz)
Set up for a sequence of values

This function will be called at the beginning of each sequence of values (e.g. at the beginning of each fractal orbit).

Parameters:
pz - seed value for the sequence
Returns:
first value in the sequence

InitDefault

public float InitDefault()
Set up for a sequence of values

This alternate form of Init will cause the Generator to start with its "default" sequence. This can be used if a generator allows a user to select a "seed" value itself. Such Generator classes should override this function.

Returns:
first value in the sequence

Iterate

public float Iterate(float pz)
Produce the next value in the sequence

As long as the sequence has not bailed out, this function will be continually called to produce sequence values.

Parameters:
pz - previous value in the sequence. Note that you should always use this value for computing the next iteration, rather than a saved value, as the calling code may modify the returned value before passing it back to the next Iterate() call.
Returns:
the next value in the sequence

IsBailedOut

public boolean IsBailedOut(float pz)
Test whether the formula has bailed out (i.e. the sequence is complete)

This is typically called once per iteration to test whether the sequence has completed. If producing this result is difficult to do separately from the Iterate() processing, you should produce the result in Iterate() and set the m_BailedOut flag appropriately, and leave IsBailedOut() unimplemented in your class to inherit this behavior.

Parameters:
pz - last sequence value to test; this should be the value returned from the previous Iterate() call. Note that it is acceptable to ignore pz and use m_BailedOut, but any code calling IsBailedOut() should pass in the correct pz for Generator classes which do not use m_BailedOut.
Returns:
true if the sequence has bailed out (i.e. should be terminated)