reb
Class Monnier_SFBM_II_TextureC

Object
  extended by common:Generic
      extended by common:ColorTrap
          extended by reb:Monnier_SFBM_II_TextureC

class 
ColorTrap:Monnier_SFBM_II_TextureC

This is an fBm color texture upon Sam Monnier's S.F.B.M. II ucl
Used with his permission.


Ultra Fractal Source

Toggle UF Source Code Display

 class Monnier_SFBM_II_TextureC(common.ulb:ColorTrap) {
  ; This is an fBm color texture upon Sam Monnier's S.F.B.M. II ucl <br>
  ; Used with his permission. <br>
  public:
    import "common.ulb"
 
     ; constructor
    func Monnier_SFBM_II_TextureC(Generic pparent)
      ColorTrap.ColorTrap(pparent)
    endfunc
 
   ; call this before each sequence of values to be trapped
   func Init(complex pz)
     ColorTrap.Init(pz)
     if !@init
        z = 0
        zc1 = 0
        zc2 = 0
        zc3 = 0
        zc4 = 0
        i = 0
        j = 0
        jmax = 0
        niter = 0
        a = 0
        sum = 0
        x = 0
        y = 0
        d1 = 0
        d2 = 0
        d3 = 0
        d4 = 0
        nindex = 0
        sindex = 0
        scale = 1
        cr1r = 0
        cr1i = 0
        cr2r = 0
        cr2i = 0
        cr3r = 0
        cr3i = 0
        cr4r = 0
        cr4i = 0
        crp1 = 0
        crp2 = 0
        crp3 = 0
        crp4 = 0
        norm = 1
 
        if @interp == 0
          niter = ceil(real(log(real(@fmm)-imag(@fmm))/log(1+@mstep)))
        else
          niter = ceil((real(@fmm)-imag(@fmm))/@mstep)
        endif
 
        if @mode == 0
          jmax = 1
        else
          jmax = 5
        endif
      endif
   endfunc
    
     ; call for each iterated point
    color func Iterate(complex pz)
     ColorTrap.Iterate(pz)
      if @init
       z = 0
       zc1 = 0
       zc2 = 0
       zc3 = 0
       zc4 = 0
       i = 0
       j = 0
       jmax = 0
       niter = 0
       a = 0
       sum = 0
       x = 0
       y = 0
       d1 = 0
       d2 = 0
       d3 = 0
       d4 = 0
       nindex = 0
       sindex = 0
       scale = 1
       cr1r = 0
       cr1i = 0
       cr2r = 0
       cr2i = 0
       cr3r = 0
       cr3i = 0
       cr4r = 0
       cr4i = 0
       crp1 = 0
       crp2 = 0
       crp3 = 0
       crp4 = 0
       norm = 1
 
       if @interp == 0
         niter = ceil(real(log(real(@fmm)-imag(@fmm))/log(1+@mstep)))
       else
         niter = ceil((real(@fmm)-imag(@fmm))/@mstep)
       endif
 
       if @mode == 0
         jmax = 1
       else
         jmax = 5
       endif
     endif
     while j < jmax
     z = pz/@size
     if @mode == 1 || @mode == 2
       if j == 0
         a = @cbl + @ctl + @cbr + @ctr + @cc;/20
       elseif j == 1
         z = z + @eps*(-1,-1)
         a = -@cbl
       elseif j == 2
         z = z + @eps*(-1,1)
         a = -@ctl
       elseif j == 3
         z = z + @eps*(1,-1)
         a = -@cbr
       elseif j == 4
         z = z + @eps*(1,1)
        a = -@ctr
       endif
     else
       a = 1
     endif
     j = j + 1
 
     i = 0
     while i < niter + 2
 
 
       if i == 2
         if @pptype == 0
           z = (real(@pp)*(1/sqrt(imag(@ppp))*x + 1i*sqrt(imag(@ppp))*y)^real(@ppp)+(1-real(@pp))*z)*imag(@pp)
         else
           z = (real(@pp)*x^real(@ppp)*exp(imag(@ppp)*1i*y)+(1-real(@pp))*z)*imag(@pp)
         endif
       elseif i == 0
         z = z/imag(@pp)
       endif
 
 
 
       z = z*exp(1i*pi/180*@rot) + 1 - 2i
 
       if i > 1
         if @interp == 0
           scale = (1+@mstep)^(i-2)*imag(@fmm)
         else
           scale = real(@fmm)-(i-1)*(@mstep+.001)
         endif
       endif
 
       i = i + 1
 
       zc = round(scale*z)/scale
 
       zc1 = zc + (.5,.5)/scale
       zc2 = zc + (-.5,.5)/scale
       zc3 = zc + (.5,-.5)/scale
       zc4 = zc + (-.5,-.5)/scale
 
       cr1r = ((real(zc1)-859-i)^5 % (132+i) - (imag(zc1)+328+i)^3 % (113+i))^2 %2 - 1
       if @noise != 6 && @noise != 8 && @noise != 10 && @noise != 12 && @noise != 14
         cr2r = ((real(zc2)-859-i)^5 % (132+i) - (imag(zc2)+328+i)^3 % (113+i))^2 %2 - 1
         cr3r = ((real(zc3)-859-i)^5 % (132+i) - (imag(zc3)+328+i)^3 % (113+i))^2 %2 - 1
         cr4r = ((real(zc4)-859-i)^5 % (132+i) - (imag(zc4)+328+i)^3 % (113+i))^2 %2 - 1
       endif
       if @noise == 0 || @noise == 5
         cr1i = ((real(zc1)-465+i)^3 % (120+i) - (imag(zc1)-756+i)^2 % (107+i))^2 %2 - 1
         cr2i = ((real(zc2)-465+i)^3 % (120+i) - (imag(zc2)-756+i)^2 % (107+i))^2 %2 - 1
         cr3i = ((real(zc3)-465+i)^3 % (120+i) - (imag(zc3)-756+i)^2 % (107+i))^2 %2 - 1
         cr4i = ((real(zc4)-465+i)^3 % (120+i) - (imag(zc4)-756+i)^2 % (107+i))^2 %2 - 1
       endif
 
       if @noise == 0
         v1 = (z - zc1)*scale
         v2 = (z - zc2)*scale
         v3 = (z - zc3)*scale
         v4 = (z - zc4)*scale
         crp1 = cr1r*real(v1) + cr1i*imag(v1)
         crp2 = cr2r*real(v2) + cr2i*imag(v2)
         crp3 = cr3r*real(v3) + cr3i*imag(v3)
         crp4 = cr4r*real(v4) + cr4i*imag(v4)
       elseif @noise == 1
         crp1 = cr1r
         crp2 = cr1r
         crp3 = cr1r
         crp4 = cr1r
         norm = .5
       elseif @noise == 2
         crp1 = cr1r
         crp2 = cr2r
         crp3 = cr1r
         crp4 = cr2r
         norm = .5
       elseif @noise == 3
         crp1 = cr1r
         crp2 = cr2r
         crp3 = cr3r
         crp4 = cr2r
         norm = .5
       elseif @noise == 4
         crp1 = -cr1r
         crp2 = cr2r
         crp3 = cr3r
         crp4 = -cr4r
         norm = .5
       elseif @noise == 5
         crp1 = cr1r*abs(real(z-zc)*scale)^real(@noisep) + cr1i*abs(imag(z-zc)*scale)^imag(@noisep)
         crp2 = cr2r*abs(real(z-zc)*scale)^real(@noisep) + cr2i*abs(imag(z-zc)*scale)^imag(@noisep)
         crp3 = cr3r*abs(real(z-zc)*scale)^real(@noisep) + cr3i*abs(imag(z-zc)*scale)^imag(@noisep)
         crp4 = cr4r*abs(real(z-zc)*scale)^real(@noisep) + cr4i*abs(imag(z-zc)*scale)^imag(@noisep)
         norm = .2
       elseif @noise == 6
         crp1 = (cabs(z-zc)*scale-imag(@noisep))^real(@noisep)
         norm = .4
       elseif @noise == 7
         crp1 = cr1r*(cabs(z-zc)*scale-imag(@noisep))^real(@noisep)
         crp2 = cr2r*(cabs(z-zc)*scale-imag(@noisep))^real(@noisep)
         crp3 = cr3r*(cabs(z-zc)*scale-imag(@noisep))^real(@noisep)
         crp4 = cr4r*(cabs(z-zc)*scale-imag(@noisep))^real(@noisep)
         norm = .4
       elseif @noise == 8
         arg = atan2(z-zc)
         arg = -round(arg/(2*pi)*4)/4*(2*pi)
         ztest = (z-zc)*exp(1i*arg)
         crp1 = (real(ztest)*scale-imag(@noisep))^real(@noisep)
         norm = .4
       elseif @noise == 9
         arg = atan2(z-zc)
         arg = -round(arg/(2*pi)*4)/4*(2*pi)
         ztest = (z-zc)*exp(1i*arg)
         crp1 = cr1r*(real(ztest)*scale-imag(@noisep))^real(@noisep)
         crp2 = cr2r*(real(ztest)*scale-imag(@noisep))^real(@noisep)
         crp3 = cr3r*(real(ztest)*scale-imag(@noisep))^real(@noisep)
         crp4 = cr4r*(real(ztest)*scale-imag(@noisep))^real(@noisep)
         norm = .4
       elseif @noise == 10
         arg = atan2(z-zc)
         arg = -round(arg/(2*pi)*8)/8*(2*pi)
         ztest = (z-zc)*exp(1i*arg)
         crp1 = (real(ztest)*scale-imag(@noisep))^real(@noisep)
         norm = .4
       elseif @noise == 11
         arg = atan2(z-zc)
         arg = -round(arg/(2*pi)*8)/8*(2*pi)
         ztest = (z-zc)*exp(1i*arg)
         crp1 = cr1r*(real(ztest)*scale-imag(@noisep))^real(@noisep)
         crp2 = cr2r*(real(ztest)*scale-imag(@noisep))^real(@noisep)
         crp3 = cr3r*(real(ztest)*scale-imag(@noisep))^real(@noisep)
         crp4 = cr4r*(real(ztest)*scale-imag(@noisep))^real(@noisep)
         norm = .4
       elseif @noise == 12
         ztest = z - zc
         if real(cr1r) > 0
           d1 = abs(cabs(ztest*scale+(.5,.5))-.5)
           d2 = abs(cabs(ztest*scale-(.5,.5))-.5)
           if d2 < d1
             d1 = d2
           endif
         else
           d1 = abs(cabs(ztest*scale+(.5,-.5))-.5)
           d2 = abs(cabs(ztest*scale-(.5,-.5))-.5)
           if d2 < d1
             d1 = d2
           endif
         endif
         crp1 = d1^real(@noisep)
         norm = .4
       elseif @noise == 13
         ztest = z - zc
         if real(cr1r) > 0
           d1 = abs(cabs(ztest*scale+(.5,.5))-.5)
           d2 = abs(cabs(ztest*scale-(.5,.5))-.5)
           if d2 < d1
             d1 = d2
           endif
         else
           d1 = abs(cabs(ztest*scale+(.5,-.5))-.5)
           d2 = abs(cabs(ztest*scale-(.5,-.5))-.5)
           if d2 < d1
             d1 = d2
           endif
         endif
         crp1 = cr1r*(d1^real(@noisep)-imag(@noisep))
         crp2 = cr2r*(d1^real(@noisep)-imag(@noisep))
         crp3 = cr3r*(d1^real(@noisep)-imag(@noisep))
         crp4 = cr4r*(d1^real(@noisep)-imag(@noisep))
         norm = .4
       elseif @noise == 14
         ztest = (z - zc)*scale
         if real(cr1r) > 0
           d1 = abs(real(ztest) - imag(ztest) -.5)
           d2 = abs(real(ztest) - imag(ztest) +.5)
           if d2 < d1
             d1 = d2
           endif
         else
           d1 = abs(real(ztest) + imag(ztest) -.5)
           d2 = abs(real(ztest) + imag(ztest) +.5)
           if d2 < d1
             d1 = d2
           endif
         endif
         crp1 = d1^real(@noisep)
         norm = .4
       elseif @noise == 15
         ztest = (z - zc)*scale
         if real(cr1r) > 0
           d1 = abs(real(ztest) - imag(ztest) -.5)
           d2 = abs(real(ztest) - imag(ztest) +.5)
           if d2 < d1
             d1 = d2
           endif
         else
           d1 = abs(real(ztest) + imag(ztest) -.5)
           d2 = abs(real(ztest) + imag(ztest) +.5)
           if d2 < d1
             d1 = d2
           endif
         endif
         crp1 = cr1r*(d1^real(@noisep)-imag(@noisep))
         crp2 = cr2r*(d1^real(@noisep)-imag(@noisep))
         crp3 = cr3r*(d1^real(@noisep)-imag(@noisep))
         crp4 = cr4r*(d1^real(@noisep)-imag(@noisep))
         norm = .4
       elseif @noise == 16
       endif
 
       if @noise == 6 || @noise == 8 || @noise == 10 || @noise == 12 || @noise == 14
 
         nindex = crp1
 
       else
 
         d1 = real(z - zc)*scale + 0.5
         d2 = (1 - d1)
         d3 = imag(z - zc)*scale + 0.5
         d4 = (1 - d3)
 
         d1 = (.5 + .5*sin(pi*d1-pi/2))^@power
         d2 = (.5 + .5*sin(pi*d2-pi/2))^@power
         d3 = (.5 + .5*sin(pi*d3-pi/2))^@power
         d4 = (.5 + .5*sin(pi*d4-pi/2))^@power
 
         nindex = crp1*d1*d3 + crp3*d1*d4 + crp2*d2*d3 + crp4*d2*d4
       endif
 
       if @f1 == 1
         nindex = real(sin(100*real(@fp1)*nindex+imag(@fp1)))/10
       elseif @f1 == 2
         nindex = real(@fp1)*10*nindex+2+imag(@fp1)
         if abs(nindex) > 1
           nindex = 1
         endif
         nindex = real(asin(nindex))/4
       elseif @f1 == 3
         nindex = 20*real(@fp1)*nindex+1+imag(@fp1)
         if abs(nindex) > 1
           nindex = 1
         endif
         nindex = real(acos(nindex))/4
       elseif @f1 == 4
         nindex = real(atanh(20*real(@fp1)*nindex+imag(@fp1)))/8
       elseif @f1 == 5
         nindex = (20*nindex+imag(@fp1))^(2+real(@fp1))/160
       elseif @f1 == 6
         nindex = real((15*nindex+imag(@fp1))^(.1*real(@fp1)))
       elseif @f1 == 7
         nindex = real(exp(10*real(@fp1)*nindex+imag(@fp1)-.5))/8
       elseif @f1 == 8
         nindex = real(round(5*real(@fp1)*nindex+imag(@fp1)/5))/4
       elseif @f1 == 9
         nindex = real(round(15*real(@fp1)*nindex+imag(@fp1)/5)^.1)/3
       elseif @f1 == 10
         nindex = (sin(5*sqrt(real(@fp1))*(real(z)+(4+imag(@fp1))*nindex))+cos(5*1/sqrt(real(@fp1))*(imag(z)+(4+imag(@fp1))*nindex)))/15
       endif
 
       if @f2 == 1
         nindex = real(sin(100*real(@fp2)*nindex+imag(@fp2)))/10
       elseif @f2 == 2
         nindex = real(@fp2)*10*nindex+2+imag(@fp2)
         if abs(nindex) > 1
           nindex = 1
         endif
         nindex = real(asin(nindex))/4
       elseif @f2 == 3
         nindex = 20*real(@fp2)*nindex+1+imag(@fp2)
         if abs(nindex) > 1
           nindex = 1
         endif
         nindex = real(acos(nindex))/4
       elseif @f2 == 4
         nindex = real(atanh(20*real(@fp2)*nindex+imag(@fp2)))/8
       elseif @f2 == 5
         nindex = (20*nindex+imag(@fp2))^(2+real(@fp2))/160
       elseif @f2 == 6
         nindex = real((15*nindex+imag(@fp2))^(.1*real(@fp2)))
       elseif @f2 == 7
         nindex = real(exp(10*real(@fp2)*nindex+imag(@fp2)-.5))/8
       elseif @f2 == 8
         nindex = real(round(5*real(@fp2)*nindex+imag(@fp2)/5))/4
       elseif @f2 == 9
         nindex = real(round(15*real(@fp2)*nindex+imag(@fp2)/5)^.1)/3
       elseif @f2 == 10
         nindex = (sin(5*sqrt(real(@fp2))*(real(z)+(4+imag(@fp2))*nindex))+cos(5*1/sqrt(real(@fp2))*(imag(z)+(4+imag(@fp2))*nindex)))/15
       endif
 
       nindex = real(nindex^@power2)
 
       if i == 1
         x = nindex
       elseif i == 2
         y = nindex
       else
         sindex = sindex + nindex/scale^@beta
       endif
 
 
     endwhile
 
     if @mode != 2
       sum = sum + a*sindex
     else
       sum = sum + a*abs(sindex)
     endif
     sindex = 0
     scale = 1
 
     endwhile
 
     if @mode == 2
       sum = 3*abs(sum)
     endif
 
     if @mode == 1
       sindex = sum/(10*@eps*(abs(@cbl + @ctl + @cbr + @ctr)+1))
     else
       sindex = sum
     endif
 
     if @interp == 0
       d = 2*norm*sindex/(niter)^.5
     else
       d = .4*norm*sindex
     endif
 
     color pat = rgba(0,0,0,0)
     if @flavorp == 0
       pz = exp(flip(2 * #pi * sqrt(2) * d))
       pat = compose(@pattern1,@pattern2,real(pz)/cabs(pz) * @strength)
     elseif @flavorp == 1
       pat = compose(@pattern1,@pattern2,abs(d)*@strength)
     elseif @flavorp == 2
       pz = exp(flip(2 * #pi * sqrt(2) * d)) * @strength
       pat = compose(gradient((cabs(pz)% @pmod)/@pmod),gradient((2*abs(sum)%@pmod)/@pmod),real(pz)/cabs(pz))
     endif
     return pat
    endfunc
 
    protected:
     complex z
     complex zc1
     complex zc2
     complex zc3
     complex zc4
     int i
     int j
     int jmax
     int niter
     float a
     float sum
     float x
     float y
     float d1
     float d2
     float d3
     float d4
     float nindex
     float sindex
     float scale
     float cr1r
     float cr1i
     float cr2r
     float cr2i
     float cr3r
     float cr3i
     float cr4r
     float cr4i
     float crp1
     float crp2
     float crp3
     float crp4
     float norm
      float d
 
  default:
   title = "Monnier's SFBM II Coloring Texture"
   int param v_monniersfbmc
     caption = "Version (Monnier's S.F.B.M. II Coloring Texture)"
     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_monniersfbmc < 100
   endparam
   param init
     caption = "Init with each iter"
     default = true
   endparam
   param noise
     caption = "Noise Function"
     default = 0
     enum = "Perlin" "Raw Gird" "Strips" "Corners" "Checkerboard" \
            "Soft Gird" "Circles" "Soft Circles" "Squares" "Soft Squares" \
            "Octogons" "Soft Octogons" "Roundy Truchet" "Soft Roundy Truchet" \
            "Squarry Truchet" "Soft Squarry Truchet"
   endparam
   heading
     caption = "Coloring parameters and Flavors"
   endheading
   color param pattern1
     caption = "Color 1"
     default = rgb(0.66,0.29,0.1)
     visible = @flavorp != "gradient"
   endparam
   color param pattern2
     caption = "Color 2"
     default = rgb(0.89,0.84,0.30)
     visible = @flavorp != "gradient"
   endparam
   param flavorp
     caption = "Coloring flavor"
     default = 0
     enum = "0" "1" "gradient"
   endparam
   float param strength
     caption = "Color strength"
     default = 1.0
   endparam
   int param pmod
     caption = "Color modulus"
     default = 2
     visible = @flavorp == "gradient"
   endparam
   heading
     caption = "SFBM parameters"
   endheading
   param noisep
     caption = "Noise F. Parameters"
     default = (.2,.5)
     hint = "Noise Function Parameters"
   endparam
 
   param f1
     caption = "flavor 1"
     default = 0
     enum = "Original" "Wavy" "Blobs" "Cut" "Messy" "Soft I" "Strings" "Soft II" "Sharp" "String-Sharp" "Random Phase"
   endparam
 
   param fp1
     caption = "flavor 1 Parameters"
     default = (1,0)
     hint = "flavor 1 Parameters"
   endparam
 
   param f2
     caption = "flavor 2"
     default = 0
     enum = "Original" "Wavy" "Blobs" "Cut" "Messy" "Soft I" "Strings" "Soft II" "Sharp" "String-Sharp" "Random Phase"
   endparam
 
   param fp2
     caption = "flavor 2 Parameters"
     default = (1,0)
     hint = "flavor 2 Parameters"
   endparam
 
   param mode
     caption = "Mode"
     default = 0
     enum = "Normal" "Convolution" "Absolute Convolution"
   endparam
 
   param beta
     caption = "Beta (Spectral Density Parameter)"
     default = 1.0
     hint = "Spectral Density Exponent"
   endparam
 
   param power
     caption = "Power"
     default = 2.0
   endparam
 
   param power2
     caption = "Post-Power"
     default = 1.0
   endparam
 
   param pp
     caption = "Pre-Processing"
     default = (0,1)
   endparam
 
   param pptype
     caption = "Pre-Processing Type"
     default = 0
     enum = "Cartesian" "Polar"
     hint = "Pre-Processing Type"
   endparam
 
   param ppp
     caption = "Pre-P. Power and Aspect"
     default = (1,1)
     hint = "Pre-Processing Power and Aspect"
   endparam
 
   param size
     caption = "Pattern Size"
     default = 0.1
   endparam
 
   param rot
     caption = "Rotation Step"
     default = 28.0
   endparam
 
   param mstep
     caption = "Frequency Separation"
     default = 1.0
     hint = "Frequency Separation"
   endparam
 
   param fmm
     caption = "Inv. of max/min Frequency"
     default = (40,1)
     hint = "Inverse of max/min Frequency"
   endparam
 
   param interp
     caption = "Frequency Interpolation"
     default = 0
     enum = "Logarithmic" "Linear"
     hint = "Frequency Interpolation"
   endparam
 
   param cc
     caption = "Center Extra Weight"
     default = 0.0
   endparam
 
   param cbl
     caption = "Bottom Left Weight"
     default = 1.0
   endparam
 
   param ctl
     caption = "Top Left Weight"
     default = 0.0
   endparam
 
   param cbr
     caption = "Bottom Right Weight"
     default = 0.0
   endparam
 
   param ctr
     caption = "Top Right Weight"
     default = 0.0
   endparam
 
   param eps
     caption = "Epsilon"
     default = 0.006
   endparam
  }
 


Constructor Summary
Monnier_SFBM_II_TextureC()
           
Monnier_SFBM_II_TextureC(Generic pparent)
          constructor
 
Method Summary
 void Init(complex pz)
          call this before each sequence of values to be trapped
 color Iterate(complex pz)
          call for each iterated point
 
Methods inherited from class common:ColorTrap
IterateSilent
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

Monnier_SFBM_II_TextureC

public Monnier_SFBM_II_TextureC(Generic pparent)
constructor


Monnier_SFBM_II_TextureC

public Monnier_SFBM_II_TextureC()
Method Detail

Init

public void Init(complex pz)
call this before each sequence of values to be trapped

Overrides:
Init in class ColorTrap

Iterate

public color Iterate(complex pz)
call for each iterated point

Overrides:
Iterate in class ColorTrap