mt
Class MT_SpriteTrap

Object
  extended by common:Generic
      extended by common:Coloring
          extended by common:DirectColoring
              extended by mt:MT_SpriteTrap

class 
DirectColoring:MT_SpriteTrap

Mark Townsend, May 2008


Ultra Fractal Source

Toggle UF Source Code Display

 class MT_SpriteTrap(common.ulb:DirectColoring) {
 ;
 ; Mark Townsend, May 2008
 ;
 public:
   func MT_SpriteTrap(Generic pparent)
     DirectColoring(pparent)
      fTrapTransform = new @p_traptransform(this)
     fImage = new @p_image(this)
    ; if !fImage.getEmpty()
    ;   fRatio = fImage.getWidth() / fImage.getHeight()
    ; else
    ;   fRatio = 1
    ; endif
   endfunc
 
   func Init(complex pz, complex ppixel)
     DirectColoring.Init(pz, ppixel)
     fTrapTransform.Init(pz)
     fTrapZ = 0
     fTrapped = false
     fTrapIter = 0
     fIter = 0
     fClr = rgb(0,0,0)
     fFirst = @firstiter - 1
     fLast = fFirst + @no_iters
   endfunc
 
   func Iterate(complex pz)
     DirectColoring.Iterate(pz)
     if !fTrapped && (fIter >= fFirst) && (fIter < fLast)
       complex zt = fTrapTransform.Iterate(pz)
 ;      fClr = fImage.getColor(real(zt) + flip(imag(zt) * fRatio))
       fClr = fImage.getColor(real(zt) + flip(imag(zt)))
 
       if alpha(fClr) > @threshold
         fTrapped = true
         fTrapIter = fIter
         fTrapZ = pz
       endif
     endif
     fIter = fIter + 1
   endfunc
 
   color func Result(complex pz)
     color c = rgb(0,0,0)
     if fTrapped
       if @color_mode == "Image"
         c = rgba(red(fClr), green(fClr),blue(fClr),1)
       elseif @color_mode == "Iteration"
         c = Gradient(0.1 * fTrapIter)
       elseif @color_mode == "Magnitude"
         c = Gradient(cabs(fTrapZ))
       elseif @color_mode == "Real"
         c = Gradient(abs(real(fTrapZ)))
       elseif @color_mode == "Imag"
         c = Gradient(abs(imag(fTrapZ)))
       elseif @color_mode == "Angle"
         float bb = atan2(fTrapZ)
         if bb < 0
           bb = bb + 2 * #pi
         endif
         bb = 1 / (2 * #pi) * bb
         c = Gradient(bb)
       elseif @color_mode == "Modulated Iter"
         c = Gradient((fTrapIter % 8) / 8)
       elseif @color_mode == "Gradient Index"
         c = gradient(0.3* red(fClr)+ 0.59 * green(fClr) + 0.11 * blue(fClr))
       elseif @color_mode == "Negative"
         c = rgba(1-red(fClr),1-green(fClr),1-blue(fClr),1)
       elseif @color_mode == "Greyscale"
         float y = 0.3* red(fClr)+ 0.59 * green(fClr) + 0.11 * blue(fClr)
         c = rgba(y, y, y, 1)
       endif
     else
       m_solid = true
     endif
     return c
   endfunc
 
 private:
   UserTransform fTrapTransform
   ImageWrapper fImage
   complex fTrapZ
   bool fTrapped
   int fTrapIter
   int fIter
   color fClr
   int fFirst
   int fLast
 default:
   title = "Sprite Trap"
   UserTransform param p_traptransform
     caption = "Trap Position"
     default = TrapTransform
     expanded = false
   endparam
   param color_mode
     caption = "Coloring Mode"
     enum = "Image" "Negative" "Greyscale" "Gradient Index" "Iteration" "Magnitude" "Real" \
             "Imag" "Angle" "Modulated Iter"
     hint = "Specifies how the trap will be colored."
   endparam
   float param threshold
      caption = "Alpha Threshold"
      default = 0.7
      min = 0
      max = 1
      hint = "Determines what level of opacity in the image will be considered inside the trap."
   endparam
   int param firstiter
     caption = "First Iteration"
     default = 1
     min = 1
     hint = "Sets the first iteration that will be looked at. Raising it will remove larger elements from the foreground."
   endparam
   int param no_iters
     caption = "No. of Iterations"
     default = 10000
     min = 1
     hint = "Sets the number of iterations to look at. Decreasing it can remove smaller elements from the background."
   endparam
   ImageWrapper param p_image
     caption = "Image"
     default = ImageImport
   endparam
 }
 


Constructor Summary
MT_SpriteTrap()
           
MT_SpriteTrap(Generic pparent)
           
 
Method Summary
 void Init(complex pz, complex ppixel)
          Set up for a sequence of values
 void Iterate(complex pz)
          Process the next value in the sequence
 color Result(complex pz)
          Produce a resulting color index after a sequence is finished
 
Methods inherited from class common:DirectColoring
IsSolid
 
Methods inherited from class common:Coloring
GetPixel, IsGradient
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

MT_SpriteTrap

public MT_SpriteTrap(Generic pparent)

MT_SpriteTrap

public MT_SpriteTrap()
Method Detail

Init

public void Init(complex pz,
                 complex ppixel)
Description copied from class: DirectColoring
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).

Overrides:
Init in class DirectColoring
Parameters:
pz - first value for the sequence; for a normal coloring formula, this will be #z
ppixel - seed value for the sequence; for a normal coloring formula, this will be #pixel

Iterate

public void Iterate(complex pz)
Description copied from class: DirectColoring
Process 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. Note that such processing generally will not know in advance precisely how long the sequence is, and should be prepared to deal with sequences of arbitrary length.

Your coloring may determine at some point that a solid color should be used rather than an index value.

Overrides:
Iterate in class DirectColoring
Parameters:
pz - next value in the sequence; corresponds to #z in a coloring formula

Result

public color Result(complex pz)
Description copied from class: DirectColoring
Produce a resulting color index after a sequence is finished

This corresponds to the final: section in a coloring formula. Once it is called, no further calls to Iterate() should be made without calling Init() first.

Overrides:
Result in class DirectColoring
Returns:
the gradient index (corresponding to #index in a coloring formula)