This is a Perlin coloring texture based upon the code of Mark Townsend.
Provides Martin, Popcorn, Vine and Gnarl coloring using either a binary
coloring mix or a gradient.
class ColorTrapGnarl(common.ulb:ColorTrap) {
; This is a Perlin coloring texture based upon the code of Mark Townsend. <br>
; <p>
; Provides Martin, Popcorn, Vine and Gnarl coloring using either a binary
; coloring mix or a gradient.
public:
import "common.ulb"
; constructor
func ColorTrapGnarl(Generic pparent)
ColorTrap.ColorTrap(pparent)
endfunc
; call for each iterated point
color func Iterate(complex pz)
ColorTrap.Iterate(pz)
float x = real(pz) * @scaleg
float y = imag(pz) * @scaleg
float xx = 0
int i = 0
while (i < @iters)
xx = x
if @formula == 0
; Martin
x = y - sin(x)
y = @a - xx
elseif @formula == 1
; Popcorn
x = x - @h * sin(y + tan(@a * y))
y = y - @h * sin(xx + tan(@a * xx))
elseif @formula == 2
; Vine
if @flavor == 0
x = x - @h * sin(y + sin(@a * y ))
y = y + @h * sin(xx + sin(@a * xx))
elseif @flavor == 1
x = x - @h * sin(y^@b + sin(@a * y))
y = y + @h * sin(xx^@b + sin(@a * xx))
elseif @flavor == 2
x = x - @h * sin(y + sin(@a * (y + sin(@a * y))))
y = y + @h * sin(xx + sin(@a * (xx + sin(@a * xx))))
else
float newx = y
float newy = x
int j = 0
while j < @flavor
j = j + 1
newx = y + sin(@a * newx)
newy = x + sin(@a * newy)
endwhile
x = x - @h * sin(newx)
y = y + @h * sin(newy)
endif
elseif @formula == 3
; Gnarl
x = x - @h * real(@gn1(y + @gn2(@a * (y + @gn3(@b * y)))))
y = y + @h * real(@gn1(xx + @gn2(@a * (xx + @gn3(@b * xx)))))
endif
i = i + 1
endwhile
x = (real(pz) - (@scaleg * x))
y = (imag(pz) - (@scaleg * y))
pz = x + flip(y)
if @flavorg == 2
pz = pz*@strengthg
endif
color pat = rgba(0,0,0,0)
float cindex = (@cscale*(cabs(@cfn(real(pz)/cabs(pz))))+ @rot) % 1
if @flavorg == 0
if @intype == "Bicolor"
pat = compose(@pattern1,@pattern2,abs(real(pz))/cabs(pz) * @strengthg*25)
else
if cindex < 0.25
pat = compose(@pattern4,@pattern1,cindex)
elseif cindex >= 0.25 && cindex > 0.5
pat = compose(@pattern1,@pattern2,cindex)
elseif cindex >= 0.5 && cindex > 0.75
pat = compose(@pattern2,@pattern3,cindex)
else
pat = compose(@pattern3,@pattern4,cindex)
endif
endif
elseif @flavorg == 1
if @intype == "Bicolor"
pat = compose(@pattern1,@pattern2,cabs(pz)*@strengthg)
else
if cindex < 0.25
pat = compose(@pattern4,@pattern1,cindex)
elseif cindex >= 0.25 && cindex > 0.5
pat = compose(@pattern1,@pattern2,cindex)
elseif cindex >= 0.5 && cindex > 0.75
pat = compose(@pattern2,@pattern3,cindex)
else
pat = compose(@pattern3,@pattern4,cindex)
endif
endif
elseif @flavorg == 2
pat = compose(gradient((cabs(pz)% @pmod)/@pmod),gradient((2*cabs(pz)%@pmod)/@pmod),abs(real(pz))/cabs(pz))
endif
return pat
endfunc
default:
title = "Gnarl Coloring"
int param v_colortrapgnarl
caption = "Version (Color Trap Gnarl Coloring)"
default = 102
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_colortrapgnarl < 102
endparam
color param pattern1
caption = "Color 1"
default = rgb(0.66,0.29,0.1)
visible = @flavorg != "gradient"
endparam
color param pattern2
caption = "Color 2"
default = rgb(0.89,0.84,0.30)
visible = @flavorg != "gradient"
endparam
color param pattern3
caption = "Color 3"
default = rgb(0.53,0.63,0.12)
visible = @flavorg != "gradient" && @intype == "Multicolor"
endparam
color param pattern4
caption = "Color 4"
default = rgb(0.89,0.45,0.30)
visible = @flavorg != "gradient" && @intype == "Multicolor"
endparam
param intype
caption = "Coloring type"
default = 0
enum = "Bicolor" "Multicolor"
visible = @flavorg != "gradient"
endparam
float param cscale
caption = "Color scale"
default = 1.0
visible = @flavorg != "gradient" && @intype == "Multicolor"
endparam
float param rot
caption = "Color rotation"
default = 0
min = 0
max = 1
visible = @flavorg != "gradient" && @intype == "Multicolor"
endparam
func cfn
caption = "Color Function"
default = ident()
visible = @flavorg != "gradient" && @intype == "Multicolor"
endfunc
param flavorg
caption = "Gnarl flavor"
default = 0
enum = "0" "1" "gradient"
endparam
int param pmod
caption = "Color modulus"
default = 1
visible = @flavorg == "gradient"
endparam
param formula
caption = "Formula"
enum = "Martin" "Popcorn" "Vine" "Gnarl"
default = 1
endparam
param a
caption = "Alpha"
default = 3.0
endparam
param b
caption = "Beta"
default = 2.0
visible = (@formula == 2 || @formula == 3)
endparam
param iters
caption = "Iterations"
default = 20
endparam
param flavor
caption = "Vine flavor"
default = 2
min = 0
visible = @formula == 2
endparam
param h
caption = "Step size"
default = 0.1
visible = (@formula == 1 || @formula == 2 || @formula == 3)
endparam
param scaleg
caption = "Scale"
default = 10.0
hint = "Changes the size of the shapes."
endparam
param strengthg
caption = "Strength"
default = 0.05
endparam
func gn1
caption = "Gnarl function #1"
default = sin()
visible = @formula == 3
endfunc
func gn2
caption = "Gnarl function #2"
default = tan()
visible = @formula == 3
endfunc
func gn3
caption = "Gnarl function #3"
default = cos()
visible = @formula == 3
endfunc
}