reb
Class REB_ColorTrapModPerlin

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

class 
ColorTrap:REB_ColorTrapModPerlin

This is a Perlin coloring texture based upon the code of Damien Jones.

Provides Perlin coloring using either a binary coloring mix or a gradient.


Ultra Fractal Source

Toggle UF Source Code Display

 class REB_ColorTrapModPerlin(common.ulb:ColorTrap) {
 ; This is a Perlin coloring texture based upon the code of Damien Jones. <br>
 ; <p>
 ; Provides Perlin coloring using either a binary coloring mix or a gradient.
  public:
    import "common.ulb"
 
     ; constructor
    func REB_ColorTrapModPerlin(Generic pparent)
      ColorTrap.ColorTrap(pparent)
    endfunc
    
     ; call for each iterated point
    color func Iterate(complex pz)
     ColorTrap.Iterate(pz)
     int p[514]
     float g3[514, 3]
     int i = 0
     int j = 0
     int k = 0
     int seed = @seed
     pz = pz*@scale
 
     while i < 256
       p[i] = i
       j = 0
       while j < 3
         seed = random(seed)
         g3[i, j] = seed % 256
         j = j + 1
       endwhile
       float t0 = g3[i, 0]
       float t1 = g3[i, 1]
       float t2 = g3[i, 2]
       float s = sqrt(t0 * t0 + t1 * t1 + t2 * t2)
       g3[i, 0] = g3[i, 0] / s
       g3[i, 1] = g3[i, 1] / s
       g3[i, 2] = g3[i, 2] / s
       i = i + 1
     endwhile
     i = 0
     while i < 256
       k = p[i]
       j = abs(seed) % 256
       seed = random(seed)
       p[i] = p[j]
       p[j] = k
       i = i + 1
     endwhile
     i = 0
     while i < 256
       p[256 + i] = p[i]
       j = 0
       while j < 3
         g3[256 + i , j] = g3[i, j];
         j = j + 1
       endwhile
       i = i + 1
     endwhile
     int iter = 0
     float sum = 0
     float amplitude = 1.0, r = (0,1) ^ (1/3)
     while iter < @octaves
       float t = real(pz) % 4096 + 4096
       int bx0 = floor(t) % 256
       int bx1 = (bx0 + 1) % 256
       float rx0 = t - floor(t)
       float rx1 = rx0 - 1
       t = imag(pz) % 4096 + 4096
       int by0 = floor(t) % 256
       int by1 = (by0 + 1) % 256
       float ry0 = t - floor(t)
       float ry1 = ry0 - 1
       t =  4096
       int bz0 = floor(t) % 256
       int bz1 = (bz0 + 1) % 256
       float rz0 = t - floor(t)
       float rz1 = rz0 - 1
       int ii = p[bx0]
       int jj = p[bx1]
       int b00 = p[ii + by0]
       int b10 = p[jj + by0]
       int b01 = p[ii + by1]
       int b11 = p[jj + by1]
       float t = (rx0 * rx0 * (3.0 - 2.0 * rx0))
       float sy = (ry0 * ry0 * (3.0 - 2.0 * ry0))
       float sz = (rz0 * rz0 * (3.0 - 2.0 * rz0))
       float u = (rx0 * g3[b00 + bz0, 0] + ry0 * g3[b00 + bz0, 1] + rz0 * g3[b00 + bz0, 2])
       float v = (rx1 * g3[b10 + bz0, 0] + ry0 * g3[b10 + bz0, 1] + rz0 * g3[b10 + bz0, 2])
       float a = (u + t * (v - u))
       u = (rx0 * g3[b01 + bz0, 0] + ry1 * g3[b01 + bz0, 1] + rz0 * g3[b01 + bz0, 2])
       v = (rx1 * g3[b11 + bz0, 0] + ry1 * g3[b11 + bz0, 1] + rz0 * g3[b11 + bz0, 2])
       float b = (u + t * (v - u))
       float c = (a + sy * (b - a))
       u = (rx0 * g3[b00 + bz1, 0] + ry0 * g3[b00 + bz1, 1] + rz1 * g3[b00 + bz1, 2])
       v = (rx1 * g3[b10 + bz1, 0] + ry0 * g3[b10 + bz1, 1] + rz1 * g3[b10 + bz1, 2])
       a = (u + t * (v - u))
       u = (rx0 * g3[b01 + bz1, 0] + ry1 * g3[b01 + bz1, 1] + rz1 * g3[b01 + bz1, 2])
       v = (rx1 * g3[b11 + bz1, 0] + ry1 * g3[b11 + bz1, 1] + rz1 * g3[b11 + bz1, 2])
       b = (u + t * (v - u))
       float d = (a + sy *(b - a))
       sum = sum + real(@fun(c + sz *(d - c))) * amplitude
       amplitude = amplitude * @persistence
       pz = pz * r / @nfactorp
       iter = iter + 1
     endwhile
     color pat = rgba(0,0,0,0)
     if @flavorp == 0
       pz = exp(flip(2 * #pi * sqrt(2) * sum))
       pat = compose(@pattern1,@pattern2,real(pz)/cabs(pz) * @strength)
     elseif @flavorp == 1
       pat = compose(@pattern1,@pattern2,abs(sum)*@strength)
     elseif @flavorp == 2
       pz = exp(flip(2 * #pi * sqrt(2) * sum)) * @strength
       pat = compose(gradient((cabs(pz)% @pmod)/@pmod),gradient((2*abs(sum)%@pmod)/@pmod),real(pz)/cabs(pz))
     endif
     return pat
    endfunc
 
  default:
    title = "Modified Perlin Colors"
   int param v_colortrapmodperlin
     caption = "Version (Color Trap Modified Perlin Colors)"
     default = 101
     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_colortrapmodperlin < 101
   endparam
   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 = "Perlin flavor"
     default = 0
     enum = "0" "1" "gradient"
   endparam
   int param pmod
     caption = "Color modulus"
     default = 8
     visible = @flavorp == "gradient"
   endparam
   param octaves
     caption = "Octaves"
     default = 7
     min = 1
   endparam
   param persistence
     caption = "Persistence"
     default = 0.5
   endparam
   float param nfactorp
     caption = "Noise Factor"
     default = 0.5
   endparam
   func fun
     caption = "Noise Function"
     default = ident()
   endfunc
   param scale
     caption = "Scale"
     default = 10.0
   endparam
   float param strength
     caption = "Strength"
     default = 1.0
   endparam
   param @seed
     caption = "Random Seed"
     default = 1234567
   endparam
  }
 


Constructor Summary
REB_ColorTrapModPerlin()
           
REB_ColorTrapModPerlin(Generic pparent)
          constructor
 
Method Summary
 color Iterate(complex pz)
          call for each iterated point
 
Methods inherited from class common:ColorTrap
Init, IterateSilent
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

REB_ColorTrapModPerlin

public REB_ColorTrapModPerlin(Generic pparent)
constructor


REB_ColorTrapModPerlin

public REB_ColorTrapModPerlin()
Method Detail

Iterate

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

Overrides:
Iterate in class ColorTrap