A smoothing algorithm that works for both convergent and divergen fractals.
class REB_GeneralSmoothing(common.ulb:DirectColoring) {
; A smoothing algorithm that works for both convergent and divergen fractals. <br>
public:
import "common.ulb"
import "dmj5.ulb"
; constructor
func REB_GeneralSmoothing(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 = pz
m_empty = true
ptexture = 0
endfunc
; call for each iterated point
func Iterate(complex pz)
DirectColoring.Iterate(pz)
m_iterexp = m_iterexp + exp(-cabs(pz)-0.5/(cabs(m_zold - pz)))
if (@mtile == "Fixed Iteration" && m_iterations == @iternum) || \
(@mtile == "Cabs(z)" && cabs(pz) < @tcabs)|| @mtile == "none"
ptexture = m_Texture.Iterate(pz)
if @f_trapcolor == ColorTrapNoColor
m_empty = true
else
m_color = m_TrapColor.Iterate(pz)
m_empty = false
endif
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.2*m_iterexp + ptexture*@txamt)
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
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_generalsmoothing >= 101
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 = "General Smoothing"
int param v_generalsmoothing
caption = "Version (General Smoothing)"
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_generalsmoothing < 101
endparam
heading
text = "This is a direct coloring formula with textures and image import \
capabilities, and which works for both convergent and divergent \
fractals. It is highly recommended that the divergent bailout be \
set to at least 1e8 and the convergent bailout be set to no more than \
1e-8. If this is not done then the smoothing may be unsatisfactory. \
It works with fractals that have both divergent and convergent regions, \
such as the Magnet fractals."
endheading
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."
endparam
DefaultColorMerge param f_colormerge
caption = "Color Merge"
default = DefaultColorMerge
visible = @f_trapcolor != ColorTrapNoColor
endparam
param nmerge
caption = "Merge order"
default = 0
enum = "Image on Top" "Image on Bottom"
visible = @f_trapcolor != ColorTrapNoColor
endparam
float param opacity
caption = "Merge Opacity"
default = 0.2
visible = @f_trapcolor != ColorTrapNoColor
endparam
heading
text = "Make image transparent by: "
visible = @f_trapcolor != ColorTrapNoColor
endheading
bool param ahue
caption = "Hue value"
default = false
visible = @f_trapcolor != ColorTrapNoColor
endparam
bool param alum
caption = "Luminance value"
default = false
visible = @f_trapcolor != ColorTrapNoColor
endparam
bool param asat
caption = "Saturation value"
default = false
visible = @f_trapcolor != ColorTrapNoColor
endparam
heading
caption = "Special Effects"
visible = @v_generalsmoothing >= 101
endheading
float param p_bright
caption = "Brightness"
default = 0.5
min = 0
max = 1
visible = @v_generalsmoothing >= 101
endparam
float param p_contrast
caption = "Contrast"
default = 0.5
min = 0
max = 1
visible = @v_generalsmoothing >= 101
endparam
float param p_sat
caption = "Saturation"
default = 0.5
min = 0
max = 1
visible = @v_generalsmoothing >= 101
endparam
float param p_hue
caption = "Hue"
default = 0.0
min = 0
max = 1
visible = @v_generalsmoothing >= 101
endparam
bool param p_gray
caption = "Grayscale"
default = false
visible = @v_generalsmoothing >= 101
endparam
bool param p_solar
caption = "Solarize"
default = false
visible = @v_generalsmoothing >= 101
endparam
float param p_thresh
caption = "Threshold"
default = 0.5
visible = @p_solar && @v_generalsmoothing >= 101
endparam
bool param p_poster
caption = "Posterize"
default = false
visible = @v_generalsmoothing >= 101
endparam
int param p_chan
caption = "Colors per channel"
default = 4
min = 2
visible = @p_poster && @v_generalsmoothing >= 101
endparam
bool param p_bw
caption = "Black and White"
default = false
visible = @v_generalsmoothing >= 101
endparam
float param p_bwt
caption = "Threshold"
default = 0.5
min = 0
max = 1
visible = @p_bw && @v_generalsmoothing >= 101
endparam
}