dmj5
Class DMJ_TrapShapePolyCurve

Object
  extended by common:Generic
      extended by common:TrapShape
          extended by dmj5:DMJ_TrapShapePolyCurve

class 
TrapShape:DMJ_TrapShapePolyCurve



Ultra Fractal Source

Toggle UF Source Code Display

 class DMJ_TrapShapePolyCurve(common.ulb:TrapShape) {
 public:
   import "common.ulb"
 
   func DMJ_TrapShapePolyCurve(Generic pparent)
     TrapShape.TrapShape(pparent)
 
     m_Handles = new @f_handles(this)
     m_Handles.SetScreenRelative(0)
     m_PolyCurve = new DMJ_PolyCurve()
     m_Selector = new @f_selector(this)
     m_Selector.SetCurve(m_PolyCurve)
     m_PolyCurve.Rasterize(0)
 
     m_Selector.SetHandles(m_Handles)
   endfunc
 
   func Init(complex pz)
     TrapShape.Init(pz)
     
     m_Handles.Init(pz)
   endfunc
   
   float func Iterate(complex pz)
     TrapShape.Iterate(pz)
 
     ; check if point is inside the polycurve or not
     bool isinside = m_PolyCurve.IsInside(pz)
 
     ; check handles
     bool inhandle = false
     if (m_Iterations == 1)
       complex cz = m_Handles.Iterate(pz)
       inhandle = m_Handles.IsSolid()
     endif
 
     if (@p_edgemode > 0)
       float d
       float t
       float to
       bool issolid = false
 
       ; get distance from curve edge and apply correct sign
       m_PolyCurve.ClosestPoint(pz, t, to, d)
       d = sqrt(d)
       if (isinside)
         d = -d
       endif
 
       ; apply sharp edge modes now
       if (@p_edgemode < 4)
         isinside = false
         if (@p_edgemode == 1)
           if (d < -@p_edgegrow)
             isinside = true
           endif
         elseif (@p_edgemode == 2)
           if (d < @p_edgegrow)
             isinside = true
           endif
         elseif (@p_edgemode == 3)
           if (d < @p_edgegrow && d > -@p_edgegrow)
             isinside = true
           endif
         endif
 
         ; apply handle state
         if (inhandle)
           isinside = !isinside
         endif
 
         ; return result
         if (isinside)
           return 0
         else
           return @p_edgevalue*2
         endif
       endif
 
       ; limit distance to edge if necessary
       if (@p_edgelimit)
         if (d < -@p_edgewidth)
           d = -@p_edgewidth
         elseif (d > @p_edgewidth)
           d = @p_edgewidth
           issolid = true
         endif
       endif
 
       ; apply edge mode      
       if (@p_edgemode == 4)
         if (d > 0)
           d = 0
           issolid = true
         endif
       elseif (@p_edgemode == 5)
         if (d < 0)
           d = 0
         endif
       elseif (@p_edgemode == 7)
         d = abs(d)
         if (@p_edgelimit && d >= @p_edgewidth)  ; inside needs clipping too
           issolid = true
         endif
       endif
 
       ; return result
       if (issolid)
         if (inhandle)
           return 0
         else
           return 1e20
         endif
       else
         if (inhandle)
           return 1e20
         else
           return @p_edgevalue + d/@p_edgesoftness
         endif
       endif
       
     else
       ; sharp edges
 
       ; apply handle state
       if (inhandle)
         isinside = !isinside
       endif
 
       ; return result
       if (isinside)
         return 0
       else
         return @p_edgevalue*2
       endif
     endif
   endfunc
   
 protected:
   Handles m_Handles
   DMJ_PolyCurve m_PolyCurve
   DMJ_PolyCurveSelector m_Selector
 
 default:
   title = "PolyCurve Family"
 
   int param v_dmj_trapshapepolycurve
     caption = "Version (DMJ_TrapShapePolyCurve)"
     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_dmj_trapshapepolycurve < 100
   endparam
 
   DMJ_PolyCurveSelector param f_selector
     caption = "Curve Definition"
     default = DMJ_SelectorArbitraryPolygon
     hint = "Sets the method by which you will define your curve or polygon."
   endparam
   float param p_edgevalue
     caption = "Assumed Edge Distance"
     default = 0.5
     hint = "PolyCurve objects don't have a central point from which distance is measured; instead, they have a precise edge that marks the boundary between inside and outside. To make a PolyCurve work like a trap shape, we treat the edge as being a particular 'distance' and then measure the distance to the edge to get the 'real' distance. If your edge is set to sharp, points 'inside' will have distance 0 and points 'outside' will have double this edge distance. Otherwise, the distance used will be the distance from the edge added to this value."
   endparam
   int param p_edgemode
     caption = "Edge Style"
     default = 0
     enum = "sharp" "sharp (shrink)" "sharp (grow)" "sharp (edge only)" "soft (inside only)" "soft (outside only)" "soft (both sides)" "soft (edge only)"
     hint = "Sets whether sharp edges or soft edges will be used. Sharp edges are faster to calculate and will remain sharp no matter how much you zoom in. Soft edges are slower but allow different effects."
   endparam
   float param p_edgegrow
     caption = "Grow/Shrink Edge"
     default = 0.1
     hint = "Sets the amount to grow or shrink the edge."
     visible = (@p_edgemode > 0 && @p_edgemode < 4)
   endparam
   float param p_edgesoftness
     caption = "Edge Softness"
     default = 1.0
     hint = "Sets the softness of the edge. Larger values will result in a softer edge."
     visible = (@p_edgemode >= 4)
   endparam
   bool param p_edgelimit
     caption = "Limit Edge"
     default = true
     hint = "If set, the soft edge will be clipped to all points within a set distance of the edge. This produces more consistent trap shapes."
     visible = (@p_edgemode >= 4)
   endparam
   float param p_edgewidth
     caption = "Edge Width"
     default = 0.1
     hint = "Sets the maximum distance from the curve edge for the soft edge."
     visible = (@p_edgemode >= 4)
   endparam
 
   heading
     caption = "Handle Options"
     expanded = false
   endheading
   Handles param f_handles
     caption = "Handle Options"
     selectable = false
   endparam
 
 }
 


Constructor Summary
DMJ_TrapShapePolyCurve()
           
DMJ_TrapShapePolyCurve(Generic pparent)
           
 
Method Summary
 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, GetTextureValue, GetTransformedPoint, IterateSilent, SetThreshold
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

DMJ_TrapShapePolyCurve

public DMJ_TrapShapePolyCurve(Generic pparent)

DMJ_TrapShapePolyCurve

public DMJ_TrapShapePolyCurve()
Method Detail

Init

public void Init(complex pz)
Description copied from class: TrapShape
call this before each sequence of values to be trapped

Overrides:
Init in class TrapShape

Iterate

public float Iterate(complex pz)
Description copied from class: TrapShape
call this for each iteration being trapped

Overrides:
Iterate in class TrapShape