Class: XRVG::AttributeMotifIterator
- Inherits:
-
BezierBuilder
- Object
- BezierBuilder
- XRVG::AttributeMotifIterator
- Defined in:
- lib/bezierbuilders.rb
Overview
Attribute Motif Iterator
Content
More advanced motif iterator than SimilarMotifIterator, and also more expensive, AttributeMotifIterator samples a curvesampler and foreach pair build a new bezier motif, with varying attributes
Attributes
attribute :curvesampler, nil, Splittable
attribute :motifclass
attribute :nmotifs, 10
attribute :attributes, [], Array
attribute :closed, false
:motifclass is a BezierBuilder class, as ArcBezier, PicBezier, or even AttributeMotifIterator…
:attributes is of the form [attribute1, specification1, :attribute2, specification, …] with
-
attribute1, attribute2 attributes of the :motifclass
-
specification can be :
-
single value
-
sampler
-
:closed attribute state if each subbezier computed for each point pair must be closed with the corresponding subbezier of the :curvesampler
Example
motif = PicBezier[ :support, [V2D::O, V2D::X], :height, -1.0 ]
curvesampler = bezier.geo( 3.0 )
result = AttributeMotifIterator[ :curvesampler, curvesampler, :motifclass, ArcBezier, :attributes, [:height, (-2.0..0.0).random], :nmotifs, 30, :closed, true ]
WARNING
Only works with BezierMotif defined by two points
Instance Method Summary collapse
-
#compute ⇒ Object
BezierBuilder overloading.
Methods inherited from BezierBuilder
Instance Method Details
#compute ⇒ Object
BezierBuilder overloading
See AttributeMotifIterator class description for details
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/bezierbuilders.rb', line 140 def compute result = [] attrvalues = [] self.attributes.foreach do |name, spec| attrvalues += [name, Samplable.build( spec ).samples( self.nmotifs )] end self.curvesampler.splits( self.nmotifs ).each_with_index do |subbezier,index| pair = [subbezier.firstpoint, subbezier.lastpoint] p1, p2 = pair args = [:support, pair] attrvalues.foreach do |name, values| args += [name, values[index]] end newbezier = self.motifclass[ *args ] if self.closed newbezier = newbezier + subbezier.reverse end result += newbezier.data end return result end |