## kcc5 Class KCC_PolygonTrap

```Object
common:Generic
common:TrapShape
kcc5:KCC_PolygonTrap
```

`class TrapShape:KCC_PolygonTrap`

The Polygon trap.

Ultra Fractal Source
``` class KCC_PolygonTrap( common.ulb:TrapShape ) {
; The Polygon trap.
; <p>
; For an example of what this trap looks like,
;
public:
import "common.ulb"

; constructor
func KCC_PolygonTrap( Generic pparent )
TrapShape.TrapShape( pparent )
endfunc

; call this before each sequence of values to be trapped
func Init( complex pz )
TrapShape.Init( pz )
endfunc

; call this for each iteration being trapped
float func Iterate( complex pz )
TrapShape.Iterate( pz )

pz = pz * exp( 1i * pi / 180 * ( @polygonRotation - @polygonSkew ) )
pz = real( pz ) / sqrt( @polygonSqueeze ) + 1i * imag( pz ) * sqrt( @polygonSqueeze )
pz = pz * exp( 1i * pi / 180 * @polygonSkew )

if( @shape == "Polygon" )
ztest2 = pz
arg = atan2( ztest2 )
widthPercent = abs(arg) / #pi
arg = -round( arg / (2 * pi) * @polygonOrder) / @polygonOrder * (2 * pi)
ztest2 = ztest2 * exp( 1i * arg )
elseif( @shape == "Rounded Polygon" )
arg = atan2(pz)
widthPercent = abs( arg ) / #pi
ztest2 = cabs( pz ) + @roundedAmount * sin( arg * @polygonOrder )
elseif( @shape == "Circle" )
widthPercent = abs( atan2( pz ) ) / #pi
ztest2 = cabs( pz )
endif

minDist = abs( real( ztest2 ) - @polygonSize )
trapWidth = @polygonWidth + (@polygonWidthDelta * widthPercent)

if( minDist < trapWidth )
m_LastChannel = m_Iterations
m_Texture = minDist / trapWidth
return minDist
endif

return 1e20
endfunc

float func GetTextureValue()
return m_Texture
endfunc

protected:
complex ztest2
float trapWidth
float arg
float widthPercent
float minDist
float m_Texture

default:
title = "Polygon Trap"

int param v_KCC_PolygonTrap
caption = "Version (KCC_PolygonTrap)"
default = 100
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_KCC_PolygonTrap < 100
endparam

param shape
caption = "Polygon Shape"
default = 0
enum = "Polygon" "Rounded Polygon" "Circle"
hint = "The type of polygon to draw."
endparam

int param polygonOrder
caption = "Order"
default = 6
hint = "The number of sides to the polygons.  While values of 1 and 2 \
are technically not valid polygons, these values may produce \
intersting results."
visible = (@shape != "Circle")
endparam

float param polygonSize
caption = "Size"
default = 0.5
hint = "Size of the polygons."
endparam

float param polygonWidth
caption = "Width"
default = 0.02
hint = "Width of the polygons."
endparam

float param polygonWidthDelta
caption = "Width Delta"
default = 0.0
hint = "Amount to vary the width around the polygons."
endparam

float param polygonRotation
caption = "Rotation"
default = 0.0
visible = (@shape != "Circle")
hint = "Amount to rotate the orientation of the polygons."
endparam

float param polygonSqueeze
caption = "Sqeezing"
default = 1.0
hint = "Polygon Squeezing Ratio"
endparam

float param polygonSkew
caption = "Skewing"
default = 0.0
hint = "Polygon Squeezing Angle"
endparam

float param roundedAmount
caption = "Corner Rounding Amount"
default = 0.1
hint = "Amount of rounding of the polygons."
visible = (@shape == "Rounded Polygon")
endparam
}
```

Constructor Summary
`KCC_PolygonTrap()`

`KCC_PolygonTrap(Generic pparent)`
constructor

Method Summary
` float` `GetTextureValue()`
Get texture value.
` void` `Init(complex pz)`
call this before each sequence of values to be trapped
` float` `Iterate(complex pz)`
call this for each iteration being trapped

Methods inherited from class common:TrapShape
`GetColorChannel, GetTransformedPoint, IterateSilent, SetThreshold`

Methods inherited from class common:Generic
`GetParent`

Methods inherited from class Object

Constructor Detail

### KCC_PolygonTrap

`public KCC_PolygonTrap(Generic pparent)`
constructor

### KCC_PolygonTrap

`public KCC_PolygonTrap()`
Method Detail

### Init

`public void Init(complex pz)`
call this before each sequence of values to be trapped

Overrides:
`Init` in class `TrapShape`

### Iterate

`public float Iterate(complex pz)`
call this for each iteration being trapped

Overrides:
`Iterate` in class `TrapShape`

### GetTextureValue

`public float GetTextureValue()`
Description copied from class: `TrapShape`
Get texture value.

Ordinarily, a trap shape does not have a native texture (it is flat). Some formulas may pair trap shapes with trap textures, and may need more information about trap textures when trap shapes are nested via TrapShapeMerge. This function provides support for accessing texture information.

Overrides:
`GetTextureValue` in class `TrapShape`
Returns:
the texture value for the last point used (i.e. call GetTextureValue() after calling Iterate(), not before)