|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Objectcommon:Generic
common:Formula
common:ConvergentDivergentFormula
mmf:MMF_SwitchConvergentDivergentFormula
mmf:MMF_SwitchFormulaWars2
class
Object version of the MMF Formula Wars 2 formula
Extended to allow the combination of up to 6 formulae
Note that for historical reasons this formula uses its own
zold and bailout values instead of those defined in the base class
doing so should not be taken as a model for other formulas.
class MMF_SwitchFormulaWars2(MMF_SwitchConvergentDivergentFormula) {
; Object version of the MMF Formula Wars 2 formula<br>
; Extended to allow the combination of up to 6 formulae<p>
; Note that for historical reasons this formula uses its own
; zold and bailout values instead of those defined in the base class
; doing so should not be taken as a model for other formulas.<br>
public:
import "common.ulb"
; @param pparent the parent, generally "this" for the parent, or zero
func MMF_SwitchFormulaWars2(Generic pparent)
MMF_SwitchConvergentDivergentFormula.MMF_SwitchConvergentDivergentFormula(pparent)
fFormula1=new @classFormula1(this)
fFormula2=new @classFormula2(this)
fFormula3=new @classFormula3(this)
fFormula4=new @classFormula4(this)
fFormula5=new @classFormula5(this)
fFormula6=new @classFormula6(this)
SetParams(fType,fConstant)
endfunc
complex func Init(complex pz)
m_Iterations = 0
m_BailedOut = false
fz[0] = fFormula1.Init(pz)
fz[1] = fFormula2.Init(pz)
if @p_NumFormulas=="3" || @p_NumFormulas=="4" || @p_NumFormulas=="5" \
|| @p_NumFormulas=="6"
fz[2] = fFormula3.Init(pz)
if @p_NumFormulas=="4" || @p_NumFormulas=="5" || @p_NumFormulas=="6"
fz[3] = fFormula4.Init(pz)
if @p_NumFormulas=="5" || @p_NumFormulas=="6"
fz[4] = fFormula5.Init(pz)
if @p_NumFormulas=="6"
fz[5] = fFormula6.Init(pz)
endif
endif
endif
endif
if fType
fConstant = pz
return fValue
else
return pz
endif
endfunc
func SetParams(bool f,complex v)
if !@p_manual
fType = f
fValue = fConstant = v
endif
if @classFormula1==MMF_SwitchFormula
MMF_SwitchFormula(fFormula1).SetParams(fType,fConstant)
elseif @classFormula1==MMF_SwitchDivergentFormula
MMF_SwitchDivergentFormula(fFormula1).SetParams(fType,fConstant)
elseif @classFormula1==MMF_SwitchConvergentFormula
MMF_SwitchConvergentFormula(fFormula1).SetParams(fType,fConstant)
elseif @classFormula1==MMF_SwitchConvergentDivergentFormula
MMF_SwitchConvergentDivergentFormula(fFormula1).SetParams(fType,fConstant)
endif
if @classFormula2==MMF_SwitchFormula
MMF_SwitchFormula(fFormula2).SetParams(fType,fConstant)
elseif @classFormula2==MMF_SwitchDivergentFormula
MMF_SwitchDivergentFormula(fFormula2).SetParams(fType,fConstant)
elseif @classFormula2==MMF_SwitchConvergentFormula
MMF_SwitchConvergentFormula(fFormula2).SetParams(fType,fConstant)
elseif @classFormula2==MMF_SwitchConvergentDivergentFormula
MMF_SwitchConvergentDivergentFormula(fFormula2).SetParams(fType,fConstant)
endif
if @p_NumFormulas=="3" || @p_NumFormulas=="4" || @p_NumFormulas=="5" \
|| @p_NumFormulas=="6"
if @classFormula3==MMF_SwitchFormula
MMF_SwitchFormula(fFormula3).SetParams(fType,fConstant)
elseif @classFormula3==MMF_SwitchDivergentFormula
MMF_SwitchDivergentFormula(fFormula3).SetParams(fType,fConstant)
elseif @classFormula3==MMF_SwitchConvergentFormula
MMF_SwitchConvergentFormula(fFormula3).SetParams(fType,fConstant)
elseif @classFormula3==MMF_SwitchConvergentDivergentFormula
MMF_SwitchConvergentDivergentFormula(fFormula3).SetParams(fType,fConstant)
endif
if @p_NumFormulas=="4" || @p_NumFormulas=="5" || @p_NumFormulas=="6"
if @classFormula4==MMF_SwitchFormula
MMF_SwitchFormula(fFormula4).SetParams(fType,fConstant)
elseif @classFormula4==MMF_SwitchDivergentFormula
MMF_SwitchDivergentFormula(fFormula4).SetParams(fType,fConstant)
elseif @classFormula4==MMF_SwitchConvergentFormula
MMF_SwitchConvergentFormula(fFormula4).SetParams(fType,fConstant)
elseif @classFormula4==MMF_SwitchConvergentDivergentFormula
MMF_SwitchConvergentDivergentFormula(fFormula4).SetParams(fType,fConstant)
endif
if @p_NumFormulas=="5" || @p_NumFormulas=="6"
if @classFormula5==MMF_SwitchFormula
MMF_SwitchFormula(fFormula5).SetParams(fType,fConstant)
elseif @classFormula5==MMF_SwitchDivergentFormula
MMF_SwitchDivergentFormula(fFormula5).SetParams(fType,fConstant)
elseif @classFormula5==MMF_SwitchConvergentFormula
MMF_SwitchConvergentFormula(fFormula5).SetParams(fType,fConstant)
elseif @classFormula5==MMF_SwitchConvergentDivergentFormula
MMF_SwitchConvergentDivergentFormula(fFormula5).SetParams(fType,fConstant)
endif
if @p_NumFormulas=="6"
if @classFormula6==MMF_SwitchFormula
MMF_SwitchFormula(fFormula6).SetParams(fType,fConstant)
elseif @classFormula6==MMF_SwitchDivergentFormula
MMF_SwitchDivergentFormula(fFormula6).SetParams(fType,fConstant)
elseif @classFormula6==MMF_SwitchConvergentFormula
MMF_SwitchConvergentFormula(fFormula6).SetParams(fType,fConstant)
elseif @classFormula6==MMF_SwitchConvergentDivergentFormula
MMF_SwitchConvergentDivergentFormula(fFormula6).SetParams(fType,fConstant)
endif
endif
endif
endif
endif
endfunc
complex func Iterate(complex pz)
fzt = pz
if m_Iterations==0
fZold = fzt = fz[0]
else
fZold = pz
endif
if @p_Method=="Alternate"
int i = m_Iterations%(@p_NumFormulas+2)
m_Iterations = m_Iterations + 1
if i==0
fzz = fFormula1.Iterate(fzt)
elseif i==1
fzz = fFormula2.Iterate(fzt)
elseif i==2
fzz = fFormula3.Iterate(fzt)
elseif i==3
fzz = fFormula4.Iterate(fzt)
elseif i==4
fzz = fFormula5.Iterate(fzt)
elseif i==5
fzz = fFormula6.Iterate(fzt)
endif
else; @p_Method!="Alternate"
m_Iterations = m_Iterations + 1
fzz = fzt = fFormula1.Iterate(fzt)
if @p_Method!="Mix All"
if m_Iterations==1
fzt = fz[1]
else
fzt = pz
endif
endif
fzt = fFormula2.Iterate(fzt)
CheckVals(1)
if @p_NumFormulas=="3" || @p_NumFormulas=="4" || @p_NumFormulas=="5" \
|| @p_NumFormulas=="6"
if @p_Method!="Mix All"
if m_Iterations==1
fzt = fz[2]
else
fzt = pz
endif
endif
fzt = fFormula3.Iterate(fzt)
CheckVals(2)
if @p_NumFormulas=="4" || @p_NumFormulas=="5" || @p_NumFormulas=="6"
if @p_Method!="Mix All"
if m_Iterations==1
fzt = fz[3]
else
fzt = pz
endif
endif
fzt = fFormula4.Iterate(fzt)
CheckVals(3)
if @p_NumFormulas=="5" || @p_NumFormulas=="6"
if @p_Method!="Mix All"
if m_Iterations==1
fzt = fz[4]
else
fzt = pz
endif
endif
fzt = fFormula5.Iterate(fzt)
CheckVals(4)
if @p_NumFormulas=="6"
if @p_Method!="Mix All"
if m_Iterations==1
fzt = fz[5]
else
fzt = pz
endif
endif
fzt = fFormula6.Iterate(fzt)
CheckVals(5)
endif
endif
endif
endif
if @p_Method=="Mix All"
fzz = fzt
endif
endif; @p_Method=="Alternate"
return fzz
endfunc
bool func IsBailedOut(complex pz)
if ((@p_BailType=="Divergent" || @p_BailType=="Both" \
|| @p_BailType=="Div.+Abs.Conv.") \
&& |pz|>=@p_Bailout) \
|| ((@p_BailType=="Convergent" || @p_BailType=="Both") \
&& |pz-fZold|<=@p_SmallBail) \
|| ((@p_BailType=="Absolute Convergence" \
|| @p_BailType=="Div.+Abs.Conv.") \
&& |pz-@p_root|<=@p_SmallBail )
m_BailedOut = true
endif
return m_BailedOut
endfunc
float func GetUpperBailout()
return @p_Bailout
endfunc
float func GetLowerBailout()
return @p_SmallBail
endfunc
private:
; Updates the z value to use according to the selected condition<br>
; @param i the formula number
func CheckVals(int i)
if @p_Method=="Minimum Magnitude"
if |fzt-@p_Coord|<|fzz-@p_Coord|
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Maximum Magnitude"
if |fzt-@p_Coord|>|fzz-@p_Coord|
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Minimum Abs. Real"
if abs(real(fzt)-real(@p_coord))<=abs(real(fzz)-real(@p_coord))
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Maximum Abs. Real"
if abs(real(fzt)-real(@p_coord))>abs(real(fzz)-real(@p_coord))
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Minimum Abs. Imaginary"
if abs(imag(fzt)-imag(@p_coord))<=abs(imag(fzz)-imag(@p_coord))
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Maximum Abs. Imaginary"
if abs(imag(fzt)-imag(@p_coord))>abs(imag(fzz)-imag(@p_coord))
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Minimum Real"
if real(fzt)-real(@p_coord)<=real(fzz)-real(@p_coord)
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Maximum Real"
if real(fzt)-real(@p_coord)>real(fzz)-real(@p_coord)
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Minimum Imaginary"
if imag(fzt)-imag(@p_coord)<=imag(fzz)-imag(@p_coord)
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Maximum Imaginary"
if imag(fzt)-imag(@p_coord)>imag(fzz)-imag(@p_coord)
fzz = fzt
if m_Iterations==1
fZold = fz[i]
endif
endif
elseif @p_Method=="Abs. Minima"
if abs(real(fzt)-real(@p_coord))<=abs(real(fzz)-real(@p_coord))
fzz = real(fzt) + flip(imag(fzz))
if m_Iterations==1
fZold = real(fz[i]) + flip(imag(fZold))
endif
endif
if abs(imag(fzt)-imag(@p_coord))<=abs(imag(fzz)-imag(@p_coord))
fzz = real(fzz) + flip(imag(fzt))
if m_Iterations==1
fZold = real(fZold) + flip(imag(fz[i]))
endif
endif
elseif @p_Method=="Abs. Maxima"
if abs(real(fzt)-real(@p_coord))>abs(real(fzz)-real(@p_coord))
fzz = real(fzt) + flip(imag(fzz))
if m_Iterations==1
fZold = real(fz[i]) + flip(imag(fZold))
endif
endif
if abs(imag(fzt)-imag(@p_coord))>abs(imag(fzz)-imag(@p_coord))
fzz = real(fzz) + flip(imag(fzt))
if m_Iterations==1
fZold = real(fZold) + flip(imag(fz[i]))
endif
endif
elseif @p_Method=="Minima"
if real(fzt)-real(@p_coord)<=real(fzz)-real(@p_coord)
fzz = real(fzt) + flip(imag(fzz))
if m_Iterations==1
fZold = real(fz[i]) + flip(imag(fZold))
endif
endif
if imag(fzt)-imag(@p_coord)<=imag(fzz)-imag(@p_coord)
fzz = real(fzz) + flip(imag(fzt))
if m_Iterations==1
fZold = real(fZold) + flip(imag(fz[i]))
endif
endif
elseif @p_Method=="Maxima"
if real(fzt)-real(@p_coord)>real(fzz)-real(@p_coord)
fzz = real(fzt) + flip(imag(fzz))
if m_Iterations==1
fZold = real(fz[i]) + flip(imag(fZold))
endif
endif
if imag(fzt)-imag(@p_coord)>imag(fzz)-imag(@p_coord)
fzz = real(fzz) + flip(imag(fzt))
if m_Iterations==1
fZold = real(fZold) + flip(imag(fz[i]))
endif
endif
endif
endfunc
Formula fFormula1
Formula fFormula2
Formula fFormula3
Formula fFormula4
Formula fFormula5
Formula fFormula6
complex fz[6]
complex fZold
complex fzt
complex fzz
default:
title = "Switch Formula Wars #2"
rating = recommended
int param v_mmfswitchformulawars2
caption = "Version (Switch Formula Wars #2)"
enum = "1.0"
default = 0
hint = "This field is to absolutely ensure backward compatibility, \
the default will always be set to the latest version, but \
there may be some cases where an older effect that you like \
is lost in an update and you could still use it by selecting \
the older version number."
visible = false
endparam
complex param p_power
visible = false
endparam
float param p_upperbailout
visible = false
endparam
float param p_lowerbailout
visible = false
endparam
bool param p_addpixel
visible = false
endparam
heading
caption = "Bailout Options"
text = "You should note that the bailout options and values you set \
here will override the bailout settings in the various formula \
parameters. This is because your chosen warring combination \
could produce either convergent or divergent results whereas \
some of your warring formulas may be convergent and others \
divergent."
endheading
int param p_BailType
caption = "Bailout Type"
enum = "Divergent" "Convergent" "Both" "Absolute Convergence" \
"Div.+Abs.Conv."
default = 0
hint = "If you get an empty or nearly empty fractal try switching \
from 'Divergent' to 'Convergent' or vice-versa or choosing \
'Both'. Note that in some cases if your fractal is a \
Mandelbrot you may need to ensure that the zstart value \
is non-zero."
endparam
complex param p_root
caption = "Convergence Value"
default = (1,0)
hint = "This is the value for testing for convergence to. For the \
'Magnet' formulas the value should be (1,0), if you don't \
know the value to use it's best to stick to the plain \
'Convergent' 'Bailout Type'. It's always worth trying (0,0)."
visible = @p_BailType>2
endparam
float param p_Bailout
caption = "Divergent Bailout"
default = 128.0
hint = "In general larger values will require higher iterations."
visible = @p_BailType==0 || @p_BailType==2 || @p_BailType==4
endparam
float param p_SmallBail
caption = "Convergent Bailout"
default = 1e-5
hint = "In general smaller values will require higher iterations."
visible = @p_BailType>0
endparam
heading
caption = "War Settings"
endheading
int param p_Method
caption = "Method of choice"
enum = "Minimum Magnitude" "Maximum Magnitude" "Minimum Abs. Real" \
"Maximum Abs. Real" "Minimum Abs. Imaginary" \
"Maximum Abs. Imaginary" "Minimum Real" "Maximum Real" \
"Minimum Imaginary" "Maximum Imaginary" "Abs. Minima" \
"Abs. Maxima" "Minima" "Maxima" "Mix All" "Alternate"
default = 0
endparam
complex param p_Coord
caption = "Centre"
default = (0,0)
hint = "Used as the centre for the testing to decide which \
formula to use on each iteration."
visible = @p_Method<6
endparam
int param p_NumFormulas
caption = "Number of Formulas"
enum = "2" "3" "4" "5" "6"
default = 0
endparam
heading
caption = "The Warring Formulas"
endheading
heading
caption = "Warring Formula #1"
endheading
heading
text = "'Fractal Formula #1' is not a switch formula and so will \
not switch using UFs built-in switch method."
visible = @classFormula1!=MMF_SwitchFormula \
&& @classFormula1!=MMF_SwitchDivergentFormula \
&& @classFormula1!=MMF_SwitchConvergentFormula \
&& @classFormula1!=MMF_SwitchConvergentDivergentFormula
endheading
Formula param classFormula1
caption = "Fractal Formula #1"
default = MMF_SwitchStandard
endparam
heading
caption = "Warring Formula #2"
endheading
heading
text = "'Fractal Formula #2' is not a switch formula and so will \
not switch using UFs built-in switch method."
visible = @classFormula2!=MMF_SwitchFormula \
&& @classFormula2!=MMF_SwitchDivergentFormula \
&& @classFormula2!=MMF_SwitchConvergentFormula \
&& @classFormula2!=MMF_SwitchConvergentDivergentFormula
endheading
Formula param classFormula2
caption = "Fractal Formula #2"
default = MMF_SwitchStandard
endparam
heading
caption = "Warring Formula #3"
visible = @p_NumFormulas>0
endheading
heading
text = "'Fractal Formula #3' is not a switch formula and so will \
not switch using UFs built-in switch method."
visible = @p_NumFormulas>0 && @classFormula3!=MMF_SwitchFormula \
&& @classFormula3!=MMF_SwitchDivergentFormula \
&& @classFormula3!=MMF_SwitchConvergentFormula \
&& @classFormula3!=MMF_SwitchConvergentDivergentFormula
endheading
Formula param classFormula3
caption = "Fractal Formula #3"
default = MMF_SwitchStandard
visible = @p_NumFormulas>0
endparam
heading
caption = "Warring Formula #4"
visible = @p_NumFormulas>1
endheading
heading
text = "'Fractal Formula #4' is not a switch formula and so will \
not switch using UFs built-in switch method."
visible = @p_NumFormulas>1 && @classFormula4!=MMF_SwitchFormula \
&& @classFormula4!=MMF_SwitchDivergentFormula \
&& @classFormula4!=MMF_SwitchConvergentFormula \
&& @classFormula4!=MMF_SwitchConvergentDivergentFormula
endheading
Formula param classFormula4
caption = "Fractal Formula #4"
default = MMF_SwitchStandard
visible = @p_NumFormulas>1
endparam
heading
caption = "Warring Formula #5"
visible = @p_NumFormulas>2
endheading
heading
text = "'Fractal Formula #5' is not a switch formula and so will \
not switch using UFs built-in switch method."
visible = @p_NumFormulas>2 && @classFormula5!=MMF_SwitchFormula \
&& @classFormula5!=MMF_SwitchDivergentFormula \
&& @classFormula5!=MMF_SwitchConvergentFormula \
&& @classFormula5!=MMF_SwitchConvergentDivergentFormula
endheading
Formula param classFormula5
caption = "Fractal Formula #5"
default = MMF_SwitchStandard
visible = @p_NumFormulas>2
endparam
heading
caption = "Warring Formula #6"
visible = @p_NumFormulas>3
endheading
heading
text = "'Fractal Formula #6' is not a switch formula and so will \
not switch using UFs built-in switch method."
visible = @p_NumFormulas>3 && @classFormula6!=MMF_SwitchFormula \
&& @classFormula6!=MMF_SwitchDivergentFormula \
&& @classFormula6!=MMF_SwitchConvergentFormula \
&& @classFormula6!=MMF_SwitchConvergentDivergentFormula
endheading
Formula param classFormula6
caption = "Fractal Formula #6"
default = MMF_SwitchStandard
visible = @p_NumFormulas>3
endparam
}
| Constructor Summary | |
|---|---|
MMF_SwitchFormulaWars2()
|
|
MMF_SwitchFormulaWars2(Generic pparent)
|
|
| Method Summary | |
|---|---|
float |
GetLowerBailout()
Determine the lower bailout boundary. |
float |
GetUpperBailout()
Determine the upper bailout boundary. |
complex |
Init(complex pz)
Note that here zold is initialised to initial z |
boolean |
IsBailedOut(complex pz)
Test whether the formula has bailed out (i.e. |
complex |
Iterate(complex pz)
Produce the next value in the sequence |
void |
SetParams(boolean f,
complex v)
|
| Methods inherited from class common:Formula |
|---|
GetPrimaryExponent |
| Methods inherited from class common:Generic |
|---|
GetParent |
| Methods inherited from class Object |
|---|
|
| Constructor Detail |
|---|
public MMF_SwitchFormulaWars2(Generic pparent)
pparent - the parent, generally "this" for the parent, or zeropublic MMF_SwitchFormulaWars2()
| Method Detail |
|---|
public complex Init(complex pz)
MMF_SwitchConvergentDivergentFormula
What it's initialised to is normally irrelevant unless the derived
formula uses zold in its main calculations in which case the user
should be given the choice of initialising zold to either the location,
the initial z value or a fixed constant.
Init in class MMF_SwitchConvergentDivergentFormulapz - the location (normally #pixel)
public void SetParams(boolean f,
complex v)
SetParams in class MMF_SwitchConvergentDivergentFormulaf - flag for Mandelbrot or Julia mode, is true for Mandelbrotsv - the value to be used as the start value or constantpublic complex Iterate(complex pz)
ConvergentDivergentFormulaAs long as the sequence has not bailed out, this function will be continually called to produce sequence values.
Iterate in class ConvergentDivergentFormulapz - previous value in the sequence; corresponds to #z in a fractal formula. Note that you should always use this value for computing the next iteration, rather than a saved value, as the calling code may modify the returned value before passing it back to the next Iterate() call.
public boolean IsBailedOut(complex pz)
ConvergentDivergentFormulaSince this is a divergent fractal, the test is easy: if it's bigger than the bailout, the sequence is done.
IsBailedOut in class ConvergentDivergentFormulapz - last sequence value to test; this should be the value returned from the previous Iterate() call. Note that it is acceptable to ignore pz and use m_BailedOut, but any code calling IsBailedOut() should pass in the correct pz for Formula classes which do not use m_BailedOut.
public float GetUpperBailout()
ConvergentDivergentFormula
GetUpperBailout in class ConvergentDivergentFormulapublic float GetLowerBailout()
ConvergentDivergentFormula
GetLowerBailout in class ConvergentDivergentFormula
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||