class MT_ConvolutionColoring(common.ulb:DirectColoring) {
;
; Mark Townsend, May 2008
;
public:
func MT_ConvolutionColoring(Generic pparent)
DirectColoring(pparent)
fHelper[0] = new @helperClass(this)
fHelper[1] = new @helperClass(this)
fHelper[2] = new @helperClass(this)
fHelper[3] = new @helperClass(this)
fHelper[4] = new @helperClass(this)
fHelper[5] = new @helperClass(this)
fHelper[6] = new @helperClass(this)
fHelper[7] = new @helperClass(this)
fHelper[8] = new @helperClass(this)
float dis = @p_distance / #magn
fAdd[0] = -dis + flip(-dis)
fAdd[1] = flip(-dis)
fAdd[2] = -dis + flip(-dis)
fAdd[3] = -dis
fAdd[4] = 0
fAdd[5] = dis
fAdd[6] = -dis + flip(dis)
fAdd[7] = flip(dis)
fAdd[8] = dis + flip(dis)
fKernel = new @kernel(this)
int i = 0
while i < 9
fSv[i] = fKernel.GetWeight(i)
i = i + 1
endwhile
endfunc
color func Result(complex pz)
color c
float alpha = 0
float red = 0
float green = 0
float blue = 0
int cIter = 0
float dv = 0
; Main loop goes through each of the sample points
while cIter < 9
if fSv[cIter] != 0 ; for speed we don't calculate if weight is zero
; initalize
dv = dv + fSv[cIter] ; summing weights
fHelper[cIter].Init(pz + fAdd[cIter])
int iter = 0
; Fractal iteration loop
repeat
fHelper[cIter].Iterate()
bool bail = fHelper[cIter].IsBailedOut()
if !bail
fHelper[cIter].IterateCol()
endif
iter = iter + 1
until iter == #maxiter || bail
if iter < #maxiter
c = fHelper[cIter].Result()
if fHelper[cIter].IsSolid()
c = @solid_color
endif
else
c = @inside_color
endif
red = red + fSv[citer] * red(c)
green = green + fSv[citer] * green(c)
blue = blue + fSv[citer] * blue(c)
alpha = alpha + fSv[citer] * alpha(c)
endif
cIter = cIter + 1
endwhile
if dv == 0 ; can't divide by zero, of course
dv = 1
endif
; Divide components with summed divisor
red = red / dv
green = green / dv
blue = blue / dv
alpha = alpha / dv
if @trans == "None"
return rgb(red, green, blue)
elseif @trans == "Gradient"
; use convoluted alpha
return rgba(red, green, blue, alpha)
elseif @trans == "Luminance"
; construct color from components
c = rgb(red, green, blue)
; grab the luminance
float alpha = lum(c)
; construct new color with luminance value used for alpha
return rgba(red, green, blue, alpha)
endif
return rgb(red, green, blue)
endfunc
private:
MT_ConvolutionHelper fHelper[9]
MT_Kernel fKernel
complex fAdd[9]
float fSv[9]
default:
title = "Convolution"
param p_distance
caption = "Sample distance"
default = 0.01
endparam
MT_Kernel param kernel
caption = "Kernel"
default = MT_CenterKernel
endparam
MT_ConvolutionHelper param helperClass
selectable = false
endparam
heading
caption = "Color parameters"
endheading
color param inside_color
caption = "Inside color"
default = rgb(0,0,0)
endparam
color param solid_color
caption = "Solid color"
default = rgb(0,0,0)
endparam
param trans
caption = "Opacity"
enum = "None" "Gradient" "Luminance"
endparam
}