reb
Class REB_ExponentialSmoothing

Object
  extended by common:Generic
      extended by common:Coloring
          extended by common:DirectColoring
              extended by reb:REB_ExponentialSmoothing

class 
DirectColoring:REB_ExponentialSmoothing

Based on the original 1994 algorithm of Ron Barnett.

This is a direct coloring formula that supports trap shape textures and colortrap coloring, including image import.


Ultra Fractal Source

Toggle UF Source Code Display

 class REB_ExponentialSmoothing(common.ulb:DirectColoring) {
 ; Based on the original 1994 algorithm of Ron Barnett. <br>
 ; <p>
 ; This is a direct coloring formula that supports trap shape textures and
 ; colortrap coloring, including image import.
 public:
   import "common.ulb"
   import "dmj5.ulb"
 
   ; constructor
   func REB_ExponentialSmoothing(Generic pparent)
     DirectColoring.DirectColoring(pparent)
     m_Texture = new @ftexture(this)
     m_MergeColor = new @f_colormerge(0)
     m_TrapColor = new @f_trapcolor(this)
   endfunc
   
   ; initialize the objects
   func Init(complex pz, complex ppixel)
     DirectColoring.Init(pz, ppixel)
     m_Texture.Init(pz)
     m_TrapColor.Init(pz)
     m_iterexp = 0
     m_zold = (0,0)
     m_empty = true
   endfunc
   
   ; call for each iterated point
   func Iterate(complex pz)
     DirectColoring.Iterate(pz)
     if (@mtile == "Fixed Iteration" && m_iterations == @iternum) || \
        (@mtile == "Cabs(z)" && cabs(pz) < @tcabs)|| @mtile == "none"
       ptexture = m_Texture.Iterate(pz)
       if @v_exponentialsmoothing < 101
         m_img = new @f_image(0)
         m_empty = m_img.GetEmpty()
       endif
       if @v_exponentialsmoothing >= 101
         if @f_trapcolor == ColorTrapNoColor
           m_empty = true
         else
           m_color = m_TrapColor.Iterate(pz)
           m_empty = false
         endif
       else
         if !m_empty
           complex m_zi = (0,1)^(@iangle/90.0)
           complex m_zs = (0,1)^(@sangle/90.0)
           complex pzi = pz
           ; aspect ratio
           pzi = real(pzi) + flip(imag(pzi)*@iaspect)
           ; rotation
           pzi = pzi*m_zi
           ; skew
           pzi = real(pzi)*m_zs + flip(imag(pzi))
           float width =  m_img.getWidth()
           float height = m_img.getHeight()
           complex pzi = (pzi+(100,100))*@scale*1000
           complex c = @adjx-2*((real(pzi) % (width-1))/width) + \
              flip(@adjy-2*((imag(pzi) % (height-1))/height))
           m_color = m_img.getColor(c)
         endif
       endif
     endif
     if (@converge > 0)
        m_iterexp = m_iterexp + exp(-cabs(pz))
     else
        m_iterexp = m_iterexp + exp(-1/(cabs(m_zold - pz)))
     endif
     m_zold = pz
   endfunc
 
   ; override the parent and call in the final section of the coloring formula. <br>
   color func Result(complex pz)
     color return_color = gradient(0.01*m_iterexp + ptexture*@txamt)
     if @v_exponentialsmoothing >= 103
       if @ahue
         m_color = hsla(hue(m_color), sat(m_color), lum(m_color), \
                       hue(m_color)/6*alpha(m_color))
       endif
       if @alum
         m_color = hsla(hue(m_color), sat(m_color), lum(m_color), \
                       lum(m_color)*alpha(m_color))
       endif
       if @asat
         m_color = hsla(hue(m_color), sat(m_color), lum(m_color), \
                       sat(m_color)*alpha(m_color))
       endif
     endif
     color temp = rgba(0,0,0,0)
     if !m_empty
       if @nmerge == 1
         temp = m_color
         m_color = return_color
         return_color = temp
       endif
       return_color = m_MergeColor.FullMerge(return_color, m_color, @opacity)
     endif
     if @v_exponentialsmoothing >= 104
       float br = (0.5-@p_bright)*2
       int sign = 0
       if br < 0
         sign = -1
       else
         sign = 1
       endif
       br = br^2*sign
       float cr = (@p_contrast-0.5)*2
       if cr < 0
         sign = -1
       else
         sign = 1
       endif
       cr = cr^2*sign+1
       float st = (0.5-@p_sat)*2
       if st < 0
         sign = -1
       else
         sign = 1
       endif
       st = st^2*sign*2
       float hu = @p_hue*6
       float rd = red(return_color)-br
       float gr = green(return_color)-br
       float bl = blue(return_color)-br
       if rd > 1
         rd = 1
       endif
       if gr > 1
         gr = 1
       endif
       if bl > 1
         bl = 1
       endif
       if rd < 0
         rd = 0
       endif
       if gr < 0
         gr = 0
       endif
       if bl < 0
         bl = 0
       endif
       return_color = rgba(rd,gr,bl,alpha(return_color))
       rd = red(return_color)^cr
       gr = green(return_color)^cr
       bl = blue(return_color)^cr
       return_color = rgba(rd,gr,bl,alpha(return_color))
       float satval = sat(return_color)-st
       if satval > 1
         satval = 1
       endif
       if satval < 0
         satval = 0
       endif
       return_color = hsla(hue(return_color), satval, lum(return_color), alpha(return_color))
       float hueval = (hue(return_color)+hu) % 6
       return_color = hsla(hueval, sat(return_color), lum(return_color), alpha(return_color))
       if @p_poster
         float rd = floor(red(return_color)*@p_chan)/@p_chan + 0.5/@p_chan
         float gr = floor(green(return_color)*@p_chan)/@p_chan + 0.5/@p_chan
         float bl = floor(blue(return_color)*@p_chan)/@p_chan  + 0.5/@p_chan
         return_color = rgba(rd,gr,bl,alpha(return_color))
       endif
       if @p_gray
          float gry = 0.3 * red(return_color)+ 0.59 * green(return_color) + 0.11 * blue(return_color)
          return_color = rgba(gry,gry,gry,alpha(return_color))
       endif
       if @p_solar
         float rd = red(return_color)
         float gr = green(return_color)
         float bl = blue(return_color)
         if rd > @p_thresh
           rd = 1-rd
         endif
         if gr > @p_thresh
           gr = 1-gr
         endif
         if bl > @p_thresh
           bl = 1-bl
         endif
         return_color = rgba(rd,gr,bl,alpha(return_color))
       endif
       if @p_bw
         float gry = 0.3 * red(return_color)+ 0.59 * green(return_color) + 0.11 * blue(return_color)
         if gry < @p_bwt
           return_color = rgba(0,0,0,alpha(return_color))
         else
           return_color = rgba(1,1,1,alpha(return_color))
         endif
       endif
     endif
     return return_color
   endfunc
 
 protected:
   float ptexture
   TrapShape m_Texture
   float m_iterexp
   complex m_zold
   ImageImport m_img
   bool m_empty
   color m_color
   ColorTrap m_TrapColor
   DefaultColorMerge m_MergeColor
 
 default:
   title = "Exponential Smoothing"
   int param v_exponentialsmoothing
     caption = "Version (Exponential Smoothing)"
     default = 104
     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_exponentialsmoothing < 104
   endparam
   heading
     text = "This is a direct coloring formula with textures and image import \
             capabilities"
   endheading
   param converge
     caption = "Fractal Type"
     default = 1
     enum = "Convergent" "Divergent"
     hint = "Mandelbrot is Divergent, Newton is Convergent."
   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 || @f_trapcolor != ColorTrapNoColor
   endheading
   param mtile
     caption = "Tile method"
     default = 1
     enum = "None" "Fixed Iteration" "Cabs(z)"
     visible = @fTexture != DMJ_TrapShapeFlat || @f_trapcolor != ColorTrapNoColor
   endparam
   int param iternum
     caption = "Iter number"
     default = 1
     hint = "Changes the texture/image mapping."
     visible = (@fTexture != DMJ_TrapShapeFlat || @f_trapcolor != ColorTrapNoColor) && \
               @mtile == "Fixed iteration"
   endparam
   float param tcabs
     caption = "Cabs limit"
     default = 1.0
     visible = @mtile == "Cabs(z)"
     hint = "Changes the texture/image mapping."
     visible = @fTexture != DMJ_TrapShapeFlat || @f_trapcolor != ColorTrapNoColor
   endparam
   TrapShape param fTexture
     caption = "Texture"
     default = DMJ_TrapShapeFlat
     hint = "Use TrapShape plugins as textures."
   endparam
   heading
     caption = "Images and Colorings"
   endheading
   ColorTrap param f_trapcolor
     caption = "Colors"
     default = ColorTrapNoColor
     expanded = false
     hint = "A trap shape that is used as a color or pattern."
     visible = @v_exponentialsmoothing >= 101
   endparam
   ImageImport param f_image
     caption = "Image"
     default = ImageImport
     visible = @v_exponentialsmoothing < 101
   endparam
   float param scale
     caption = "Image scale"
     default = 1
     min = 0
     hint = "Changes the scale of the image."
     visible = @v_exponentialsmoothing < 101
   endparam
   float param adjx
     caption = "Tile adj x"
     default = 0.99
     min = 0.9
     max = 1.1
     visible = @v_exponentialsmoothing < 101
   endparam
   float param adjy
     caption = "Tile adj y"
     default = 0.999
     min = 0.9
     max = 1.1
     visible = @v_exponentialsmoothing < 101
   endparam
   float param iaspect
     caption = "Image aspect"
     default = 1.0
     visible = @v_exponentialsmoothing < 101
   endparam
   float param iangle
     caption = "Image rotation"
     default = 0
     hint = "Rotates the image"
     visible = @v_exponentialsmoothing < 101
   endparam
   float param sangle
     caption = "Image skew"
     default = 0
     hint = "Skews the image"
     visible = @v_exponentialsmoothing < 101
   endparam
   DefaultColorMerge param f_colormerge
     caption = "Color Merge"
     default = DefaultColorMerge
     visible = @v_exponentialsmoothing < 101 || \
      (@f_trapcolor != ColorTrapNoColor && @v_exponentialsmoothing >= 101)
   endparam
   param nmerge
     caption = "Merge order"
     default = 0
     enum = "Image on Top" "Image on Bottom"
     visible = @v_exponentialsmoothing < 101 || \
      (@f_trapcolor != ColorTrapNoColor && @v_exponentialsmoothing >= 101)
   endparam
   float param opacity
     caption = "Merge Opacity"
     default = 0.2
     visible = @v_exponentialsmoothing < 101 || \
      (@f_trapcolor != ColorTrapNoColor && @v_exponentialsmoothing >= 101)
   endparam
   heading
     text = "Make image transparent by: "
     visible = @v_exponentialsmoothing >= 103 && @f_trapcolor != ColorTrapNoColor
   endheading
   bool param ahue
     caption = "Hue value"
     default = false
     visible = @v_exponentialsmoothing >= 103 && !@alum && !@asat && \
             @f_trapcolor != ColorTrapNoColor
   endparam
   bool param alum
     caption = "Luminance value"
     default = false
     visible = @v_exponentialsmoothing >= 103 && !@ahue && !@asat && \
             @f_trapcolor != ColorTrapNoColor
   endparam
   bool param asat
     caption = "Saturation value"
     default = false
     visible = @v_exponentialsmoothing >= 103 && !@alum && !@ahue && \
             @f_trapcolor != ColorTrapNoColor
   endparam
   heading
     caption = "Special Effects"
     visible = @v_exponentialsmoothing >= 103
   endheading
   float param p_bright
     caption = "Brightness"
     default = 0.5
     min = 0
     max = 1
     visible = @v_exponentialsmoothing >= 103
   endparam
   float param p_contrast
     caption = "Contrast"
     default = 0.5
     min = 0
     max = 1
     visible = @v_exponentialsmoothing >= 103
   endparam
   float param p_sat
     caption = "Saturation"
     default = 0.5
     min = 0
     max = 1
     visible = @v_exponentialsmoothing >= 103
   endparam
   float param p_hue
     caption = "Hue"
     default = 0.0
     min = 0
     max = 1
     visible = @v_exponentialsmoothing >= 103
   endparam
   bool param p_gray
     caption = "Grayscale"
     default = false
     visible = @v_exponentialsmoothing >= 103
   endparam
   bool param p_solar
     caption = "Solarize"
     default = false
     visible = @v_exponentialsmoothing >= 103
   endparam
   float param p_thresh
     caption = "Threshold"
     default = 0.5
     visible = @p_solar
     visible = @v_exponentialsmoothing >= 103
   endparam
   bool param p_poster
     caption = "Posterize"
     default = false
     visible = @v_exponentialsmoothing >= 103
   endparam
   int param p_chan
     caption = "Colors per channel"
     default = 4
     min = 2
     visible = @p_poster &&  @v_exponentialsmoothing >= 103
   endparam
   bool param p_bw
     caption = "Black and White"
     default = false
     visible = @v_exponentialsmoothing >= 103
   endparam
   float param p_bwt
     caption = "Threshold"
     default = 0.5
     min = 0
     max = 1
     visible = @p_bw && @v_exponentialsmoothing >= 103
   endparam
 
 }
 


Constructor Summary
REB_ExponentialSmoothing()
           
REB_ExponentialSmoothing(Generic pparent)
          constructor
 
Method Summary
 void Init(complex pz, complex ppixel)
          initialize the objects
 void Iterate(complex pz)
          call for each iterated point
 color Result(complex pz)
          override the parent and call in the final section of the coloring formula.
 
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

REB_ExponentialSmoothing

public REB_ExponentialSmoothing(Generic pparent)
constructor


REB_ExponentialSmoothing

public REB_ExponentialSmoothing()
Method Detail

Init

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

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)
call for each iterated point

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)
override the parent and call in the final section of the coloring formula.

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