reb
Class REB_FibersThings_Gradient

Object
  extended by common:Generic
      extended by common:Coloring
          extended by common:GradientColoring
              extended by reb:REB_FibersThings_Gradient

class 
GradientColoring:REB_FibersThings_Gradient

Based upon the divergent formula code of Jussi Härkönen, but for convergent formulas.

Gradient Coloring method that looks like triange inequality average or curvature average but which works specifically for convergent fractals like Cayley Julia and Cayley Mandelbrot. The smoothing code is modified from Linas Vepstas and Damien Jones. Some of the code ideas came from the work of Jussi Härkönen. Corrections to the fractional iteration count made by Jussi Härkönen. The class supports trapshape textures and colortrap coloring, including image import.


Ultra Fractal Source

Toggle UF Source Code Display

 class REB_FibersThings_Gradient(common.ulb:GradientColoring) {
 ; Based upon the divergent formula code of Jussi Härkönen, but for convergent formulas. <br>
 ; <p>
 ;  Gradient Coloring method that looks like triange inequality average
 ; or curvature average but which works specifically for convergent
 ; fractals like Cayley Julia and Cayley Mandelbrot. The smoothing code is
 ; modified from Linas Vepstas and Damien Jones. Some of the code ideas came
 ; from the work of Jussi Härkönen. Corrections to the fractional iteration
 ; count made by Jussi Härkönen. The class supports trapshape textures and
 ; colortrap coloring, including image import.
 public:
   import "common.ulb"
   import "dmj5.ulb"
 
   ; constructor
   func REB_FibersThings_Gradient(Generic pparent)
     GradientColoring.GradientColoring(pparent)
     m_Texture = new @ftexture(this)
   endfunc
   
   ; initialize the objects
   func Init(complex pz, complex ppixel)
     GradientColoring.Init(pz, ppixel)
     m_Texture.Init(pz)
     ci = (0,1)
     rot = ci^(@ang/90)
     skew = ci^(@skew/90)
     prot = ci^(@prot/90)
     z2 = 0
     zold = (0,0)
     zold2 = (0,0)
     i = 0
     a = 0
     a2 = 0
     f = 0
     ztype = (0,0)
     if @zmod == "point" || @zmod == "rot point"
       ztype = @spoint
     endif
     power = 0
   endfunc
   
   func Iterate(complex pz)
     GradientColoring.Iterate(pz)
     if (@mtile == "Fixed Iteration" && m_iterations == @iternum) || \
        (@mtile == "Cabs(z)" && @bailout < 1 && cabs(zold-pz) > @tcabs) || \
        (@mtile == "Cabs(z)" && @bailout > 1 && cabs(pz) < @tcabs) || @mtile == "None"
       ptexture = m_Texture.Iterate(pz)
     endif
     a2 = a
     if @flavor != "smooth"
       z2 = real(pz)*skew + flip(imag(pz))
       z2 = z2*rot
     else
       z2 = pz
     endif
     if @zmod == "rot point" && |ztype| != 0
       ztype = ztype*prot
     endif
     if @flavor == "Standard"
       a = a + cabs(fn1(@density*(atan2(fn2(z2-zold-ztype)))+@colorshift*#pi))
     elseif @flavor == "Curvature"
       a = a + cabs(fn1(@density*(atan2(fn2((z2-zold)/(zold-zold2)-ztype)))+@colorshift*#pi))
     elseif @flavor == "Decomposition"
       a = a + cabs(fn1(@density*(atan2(fn2(z2-ztype)))+@colorshift*#pi))
     elseif @flavor == "Decomp multiply"
       a = a + cabs(fn1(@density*(atan2(fn2(z2*zold-ztype)))+@colorshift*#pi))
     elseif @flavor == "Decomp divide"
       a = a + cabs(fn1(@density*(atan2(fn2(z2/zold-ztype)))+@colorshift*#pi))
     elseif @flavor == "Magnitude"
       a = a + cabs(fn1(@density*(cabs(fn2(z2-ztype)))+@colorshift*#pi))
     elseif @flavor == "Magnitude 2"
       a = a + cabs(fn1(@density*(cabs(fn2(z2-zold-ztype)))+@colorshift*#pi))
     elseif @flavor == "Magnitude 3"
       a = a + cabs(fn1(@density*(|fn2(z2-ztype)|)+@colorshift*#pi))
     elseif @flavor == "Magnitude 4"
       a = a + cabs(fn1(@density*(|fn2(z2-zold-ztype)|)+@colorshift*#pi))
     endif
     zold2 = zold
     zold = z2
     i = i + 1
   endfunc
 
   float func ResultIndex(complex pz)
     power = log(|pz - zold|) / log(|zold - zold2|)
     z2 = real(pz)*skew + flip(imag(pz))
     z2 = z2*rot
     f = (log(log(@bailout)) - log(log(1/(|(zold - z2)|))))/log(power)
     a = a/i
     a2 = a2/(i-1)
     if @flavor == "Smooth"
       return (0.05*(m_iterations+f) + ptexture*@txamt)
     else
       return (a2 + (a-a2)*(f+1) + ptexture*@txamt)
     endif
   endfunc
 
 protected:
   TrapShape m_Texture
   float ptexture
   complex ci
   complex rot
   complex skew
   complex prot
   complex z2
   complex zold
   complex zold2
   int i
   float a
   float a2
   float f
   complex ztype
   float power
 
 default:
   title = "Fibers and Things Gradient"
   int param v_fibersandthingsgrad
     caption = "Version (Fibers And Things)"
     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_fibersandthingsgrad < 100
   endparam
   heading
     text = "This coloring method was designed for use with convergent fractals. \
            It was specifically designed for the convergent formulas in reb.ufm \
            and may not work with all convergent fractals. The bailout should \
            be the same for both the coloring formula and the ufm. Some coding ideas \
            came from the work of Jussi Härkönen as did corrections \
            to the convergent smoothing algorithm."
   endheading
   param bailout
     caption = "bailout"
     default = 1e-12
   endparam
   param flavor
     caption = "flavor"
     default = 0
     enum = "standard" "curvature" "decomposition" "decomp multiply" \
            "decomp divide" "magnitude" "magnitude 2" "magnitude 3" \
            "magnitude 4" "smooth"
   endparam
   param zmod
     caption ="z modifier"
     enum = "none" "point" "rot point"
     default = 0
     visible = @flavor != "smooth"
   endparam
   float param prot
     caption = "point rotation"
     default = 0
     visible = @flavor != "smooth"&&@zmod == "rot point"
   endparam
   complex param spoint
     caption = "point val"
     default = (1,-1)
     visible = @flavor != "smooth"&&(@zmod == "point" || @zmod == "rot point")
   endparam
   float param ang
     caption ="z rotation"
     default = 0
     visible = @flavor != "smooth"
   endparam
   float param skew
     caption ="z skew"
     default = 0
     visible = @flavor != "smooth"
   endparam
   func fn1
     caption = "fiber function #1"
     default = cos()
     visible = @flavor != "smooth"
   endfunc
   func fn2
     caption = "fiber function #2"
     default = ident()
     visible = @flavor != "smooth"
   endfunc
   complex param density
     caption = "fiber density"
     default = 10.0
     visible = @flavor != "smooth"
   endparam
   float param colorshift
     caption = "color shift"
     default = 0.0
     min = 0
     max = 1
     visible = @flavor != "smooth"
   endparam
   float param txamt
     caption = "Texture amount"
     default = 0.0
     visible = @fTexture != DMJ_TrapShapeFlat
   endparam
   heading
     text = "The 'Tile method' applies to both textures and images. Fixed Iteration \
             will give a smoother tiling, while 'Cabs(z)' will more consistently \
             follow the fractal shape."
     visible = @fTexture != DMJ_TrapShapeFlat
   endheading
   param mtile
     caption = "Tile method"
     default = 1
     enum = "None" "Fixed Iteration" "Cabs(z)"
     visible = @fTexture != DMJ_TrapShapeFlat
   endparam
   int param iternum
     caption = "Iter number"
     default = 1
     hint = "Changes the texture/image mapping."
     visible = @fTexture != DMJ_TrapShapeFlat &&  @mtile == "Fixed iteration"
   endparam
   float param tcabs
     caption = "Cabs limit"
     default = 0.5
     visible = @mtile == "Cabs(z)"
     hint = "Changes the texture/image mapping."
     visible = @fTexture != DMJ_TrapShapeFlat
   endparam
   TrapShape param fTexture
     caption = "Texture"
     default = DMJ_TrapShapeFlat
     hint = "Use TrapShape plugins as textures."
   endparam
 }
 


Constructor Summary
REB_FibersThings_Gradient()
           
REB_FibersThings_Gradient(Generic pparent)
          constructor
 
Method Summary
 void Init(complex pz, complex ppixel)
          initialize the objects
 void Iterate(complex pz)
          Process the next value in the sequence
 float ResultIndex(complex pz)
          Produce a resulting color index after a sequence is finished
 
Methods inherited from class common:GradientColoring
IsGradient, IsSolid, Result
 
Methods inherited from class common:Coloring
GetPixel
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

REB_FibersThings_Gradient

public REB_FibersThings_Gradient(Generic pparent)
constructor


REB_FibersThings_Gradient

public REB_FibersThings_Gradient()
Method Detail

Init

public void Init(complex pz,
                 complex ppixel)
initialize the objects

Overrides:
Init in class GradientColoring
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: GradientColoring
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 GradientColoring
Parameters:
pz - next value in the sequence; corresponds to #z in a coloring formula

ResultIndex

public float ResultIndex(complex pz)
Description copied from class: GradientColoring
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:
ResultIndex in class GradientColoring
Returns:
the gradient index (corresponding to #index in a coloring formula)