Module: XRVG::Samplable

Includes:
FloatFunctor
Included in:
Array, Range, Bezier, Circle, Filter, InterBezier, Interpolator, Line, Palette, Roller
Defined in:
lib/samplation.rb

Overview

Samplable module, based on FloatFunctor

Concept

Basically allows advanced item computations from an continuous “Interval” object. Is used by :

  • Range for computing float values

  • Curve for computing points

  • Palette for computing colors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FloatFunctor

#addfilter, #alternate, #apply, #applyhash, #compute, #filter, #generate, #geo, #geofull, #modify, #process, #random, #shuffle, #sin, #ssort, #transform, #transforms, #trigger

Class Method Details

.build(value) ⇒ Object

method to transform any object into samplable object

used to add Attribute type :samplable



234
235
236
237
238
239
240
241
242
# File 'lib/samplation.rb', line 234

def Samplable.build( value )
  if value.is_a? Array
    return Roller[*value]
  elsif value.is_a? Samplable
    return value
  else
    return Roller[value]
  end
end

Instance Method Details

#apply_sample(abs, container = nil) ⇒ Object

to be overloaded if needed



227
228
229
# File 'lib/samplation.rb', line 227

def apply_sample( abs, container=nil )
  return abs
end

#apply_samples(inputs, &block) ⇒ Object

to be overloaded if needed

called by FloatFunctor apply method



215
216
217
218
219
220
221
222
223
224
# File 'lib/samplation.rb', line 215

def apply_samples( inputs, &block )
  if not block
    return inputs.map {|abs| self.apply_sample( abs ) }
  else
    if inputs.length > 0
	container = self.apply_sample( inputs[0] ); yield container;
	inputs[1..-1].each {|abs| yield self.apply_sample( abs, container ) }
    end
  end
end

#meanObject Also known as: middle

alias for sample( 0.5 )



205
206
207
# File 'lib/samplation.rb', line 205

def mean()
  return self.sample( 0.5 )
end

#sample(abs) ⇒ Object

shortcut method to call float processing for one input

is basically .samples().pop



199
200
201
202
# File 'lib/samplation.rb', line 199

def sample( abs )
  type = :sample
  return self.apply( self.modify( [abs], type ), type ).pop
end

#samples(nsamples, &block) ⇒ Object

fundamental method of the module

call the FloatFunctor trigger method, with type :sample

(0.0..1.0).samples( 3 ) => [0.0, 0.5, 1.0]


192
193
194
# File 'lib/samplation.rb', line 192

def samples( nsamples, &block )
  return self.trigger( nsamples, :sample, &block )
end