Class: Arbol::Documentation

Inherits:
Object
  • Object
show all
Defined in:
lib/documentation.rb,
lib/functions/add.rb,
lib/functions/max.rb,
lib/functions/min.rb,
lib/functions/const.rb,
lib/functions/gamma.rb,
lib/functions/minus.rb,
lib/functions/noise.rb,
lib/functions/scale.rb,
lib/functions/times.rb,
lib/functions/choose.rb,
lib/functions/divide.rb,
lib/functions/lookup.rb,
lib/functions/modulo.rb,
lib/functions/phasor.rb,
lib/functions/feedback.rb,
lib/functions/triangle.rb,
lib/functions/crossfade.rb,
lib/functions/less_than.rb,
lib/functions/add_modulo.rb,
lib/functions/analog_pin.rb,
lib/functions/lamp_phase.rb,
lib/functions/lfo_square.rb,
lib/functions/noise_pixel.rb,
lib/functions/greater_than.rb,
lib/functions/lfo_triangle.rb,
lib/functions/add_constrain.rb,
lib/functions/feedback_offset.rb,
lib/functions/less_than_equals.rb,
lib/functions/greater_than_equals.rb

Instance Method Summary collapse

Instance Method Details

#addObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/add.rb', line 49

def add   
%{--
### add(op1, op2)

* **op1** - operator1
* **op2** - operator2

Adds op1 and op2. can also be used in the form `op1 + op2`.

}
end

#add_constrainObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/add_constrain.rb', line 49

def add_constrain    
%{--
### add\_constrain(op1, op2)

* **op1** - operator1
* **op2** - operator2

Adds op1 and op2, then constrains the result between 0.0-~1.0.

}
end

#add_moduloObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/add_modulo.rb', line 49

def add_modulo   
%{--
### add\_modulo(op1, op2)

* **op1** - operator1
* **op2** - operator2

Adds op1 and op2, then returns the result modulo 1.0.

}
end

#analog_pinObject



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/functions/analog_pin.rb', line 190

def analog_pin
%{--
### analog\\_pin(pin, in\\_lo, in\\_hi, out\\_lo, out\\_hi, threshold, window, feedback)

* **pin** - arduino pin to use as input.. either a number or A0, A1, etc...
* **in\\_lo** - scale and constrain.. lo value for input range
* **in\\_hi** - scale and constrain.. hi value for input range
* **out\\_lo** - scale and constrain.. lo value for output range
* **out\\_hi** - scale and constrain.. hi value for output range
* **threshold** - edge detection.. outputs INTEGER_SCALE if >= threshold.. otherwise zero
* **window** - input will be averaged by frame across this many seconds
* **feedback** - feeback amount applied to the input

Once per frame the specified pin is sampled, then the data is run through a chain of optional processing to add usefulness to signals that can be noisy, incorrectly offset, or too fast or squirrely. 

The chain of processing is as follows:

* Pin is sampled once per frame.
* Scale and Constrain - Sampled value is scaled and constrained to the values specified by `in_lo`, `in_hi`, `out_lo`, `out_hi`. This functionality is enabled by specifying any one of these parameters, which default to 0.0, 1.0, 0.0, and 1.0 respectively. 
* Edge detection - If `threshold` is specified, the value outputs 1.0 if >= `threshold` and 0.0 otherwise.
* Averaging window - Specifying a `window` value (in seconds, as a float) allows for the input to be averaged across the time period. The averages are calculated using a buffer that stores 30 frames for each second specified. Averaging provides a less jerky, slower control signal.
* Feedback - Specifying `feedback` (float between 0-1) applies a simple feedback calculation. This creates a longer "tail" on the control signal.

The above processes are calculated in the order specified above, with each stage feeding into the next.. unless the process is disabled, meaning that no parameter value is specified to enable it.

`analog_pin` uses named parameters as shown in the various examples below.

```
sensor = analog_pin(
pin: 'A1'
);

sensor = analog_pin(
pin: 'A1',
in_lo: 0.1,
threshold: 0.4
);

sensor = analog_pint(
pin: 'A1',
window: 0.5,
feedback: 0.95
);
```
}
end

#chooseObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/functions/choose.rb', line 51

def choose   
%{--
### choose(choice, op1, op2)

* **choice** - selects the operator to be returned
* **op1** - operator1
* **op2** - operator2

Returns operator1 if choice < 0.5.. or operator2 if choice >= 0.5.

}
end

#constObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/functions/const.rb', line 24

def const   
%{--
### const(value)

* **value** - input value to be used as a constant.

You can specify a constant explicity:

```
const(0.4)

or

const([0.1, 0.2, 0.3])
```

..but generally you specify constants directly as values. There is no advantage in using the function.


```
0.4

or

[0.1, 0.2, 0.3]
```
}
end

#crossfadeObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/functions/crossfade.rb', line 50

def crossfade   
%{--
### crossfade(fader, channel1, channel2)

* **fader** - fade amount between channels
* **channel1** - channel1
* **channel2** - channel2

Returns a mix of channels 1 and 2 based on the fader amount between 0-~1.0.

}
end

#divideObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/divide.rb', line 49

def divide   
%{--
### divide(numerator, denominator)

* **numerator**
* **denominator**

Division. Also accepts the form `numerator / denominator`.

}
end

#feedbackObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/functions/feedback.rb', line 44

def feedback  
%{--
### feedback(input, feedback)

* **input**
* **feedback**

Returns the greatest of the input or the feedback value.

}
end

#feedback_offsetObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/functions/feedback_offset.rb', line 45

def feedback_offset   
%{--
### feedback\_offset(input, feedback, offset)

* **input**
* **feedback**
* **offset**

Returns the greatest of the input or the feedback value at the offset (0-~1.0) 
from the current pixel.

}
end

#gammaObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/functions/gamma.rb', line 42

def gamma  
%{--
### gamma(input)

* **input**

Returns gamma corrected input. This makes the colors look much better.

}
end

#greater_thanObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/greater_than.rb', line 48

def greater_than 
%{--
### greater\_than(left, right)

* **left** - left operand
* **right** - right operand

left > right as a logical operation returning 0 or 1.0.
Can be used in the form `left > right`.

}
end

#greater_than_equalsObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/greater_than_equals.rb', line 48

def greater_than_equals  
%{--
### greater\\_than\\_equals(left, right)

* **left** - left operand
* **right** - right operand

left >= right as a logical operation returning 0 or 1.0.
Can be used in the form `left >= right`.

}
end

#lamp_phaseObject



23
24
25
26
27
28
29
30
# File 'lib/functions/lamp_phase.rb', line 23

def lamp_phase 
%{--
### lamp\_phase

Returns current lamp number expressed as a phase 0-~1.0.

}
end

#less_thanObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/less_than.rb', line 48

def less_than  
%{--
### less\\_than(left, right)

* **left** - left operand
* **right** - right operand

left < right as a logical operation returning 0 or 1.0.
Can be used in the form `left < right`.

}
end

#less_than_equalsObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/less_than_equals.rb', line 48

def less_than_equals  
%{--
### less\\_than\\_equals(left, right)

* **left** - left operand
* **right** - right operand

left <= right as a logical operation returning 0 or 1.0.
Can be used in the form `left <= right`.

}
end

#lfo_squareObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/functions/lfo_square.rb', line 48

def lfo_square  
%{--
### lfo\\_square(cycle\\_ms)

* **cycle\\_ms** - cycle length expressed as milliseconds

Outputs a square wave. Note that the cycle length value is interpreted literally
as milliseconds, so you should use integer constants as input.

}
end

#lfo_triangleObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/functions/lfo_triangle.rb', line 52

def lfo_triangle 
%{--
### lfo\\_triangle(cycle\\_ms)

* **cycle\\_ms** - cycle length expressed as milliseconds

Outputs a triangle wave. Note that the cycle length value is interpreted literally
as milliseconds, so you should use integer constants as input.

}
end

#lookupObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/functions/lookup.rb', line 49

def lookup 
%{--
### lookup(table\\_reference, index)

* **table\\_reference** - reference to a predefined table.
* **index** - index used to look up the value in the table.

Allows you to lookup values in a user defined table. Note that the table must be declared before it is referenced.

```
my_table = [0, 0.5, 0.6, 0.0, 0.9];

my_lookup = lookup(
my_table,
phasor(1000)
);
```
}
end

#maxObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/max.rb', line 49

def max
%{--
### max(left, right)

* **operator1**
* **operator2**

Maximum (greater) of the two operators.

}
end

#minObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/min.rb', line 49

def min 
%{--
### min(left, right)

* **operator1**
* **operator2**

Minimum (least) of the two operators.

}
end

#minusObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/minus.rb', line 49

def minus 
%{--
### minus(operator1, operator2)

* **operator1**
* **operator2**

Difference of the two operators. Can also be used with the form `operator1 - operator2`.

}
end

#modObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/modulo.rb', line 49

def mod 
%{--
### mod(operator1, operator2)

* **operator1**
* **operator2**

Modulo of the two operators. Can also be used with the form `operator1 % operator2`.

}
end

#noiseObject



33
34
35
36
37
38
39
40
# File 'lib/functions/noise.rb', line 33

def noise
%{--
### noise

Outputs a random value for RGB of each pixel.

}
end

#noise_pixelObject



33
34
35
36
37
38
39
40
# File 'lib/functions/noise_pixel.rb', line 33

def noise_pixel 
%{--
### noise\\_pixel

Outputs a random value for each pixel.

}
end

#output_all_documentationObject



3
4
5
6
7
8
9
# File 'lib/documentation.rb', line 3

def output_all_documentation
  (self.public_methods - Object.public_methods).sort.each do |m|
    unless [:output_all_documentation, :output_single_doc].include? m.to_sym
      output_single_doc(m) 
    end
  end   
end

#output_single_doc(func) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/documentation.rb', line 11

def output_single_doc(func)
  puts(
    self.send(
      func.to_sym
    )
  )
end

#phasorObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/functions/phasor.rb', line 47

def phasor 
%{--
### phasor(cycle_ms)

* **cycle_ms**

Outputs a ramp wave from 0-~1.0 over a period of cycle_ms milliseconds.

`phasor` is very important because it highlights a key way to bring motion into
the system. There are many ways of using phasor.

```
# go from 0-~1.0 over a period of 10 seconds:
phasor(10000)

# each of the three channels goes from 0-~1.0 at different millisecond intervals:
phasor([1000, 1100, 1200])

# phasor is input into a triangle function, which then creates a triangle
# wave that goes from 0-~1.0-0 over a period of 5 seconds specified
# to the phasor
tri = triangle(phasor(5000))

# multiple two triangles together to to get a pointy triangle
tri_squared = tri * tri

# using `lamp_phase` function in conjunction with `add_constrain` you can
# create motion in the lamps.

strip(
512, # 512 pixels
0,   # attached to pin 0
add_constrain(
  lamp_phase,
  phasor([1000, 1200, 1300])  
)
```

}
end

#scaleObject



52
53
54
55
56
57
# File 'lib/functions/scale.rb', line 52

def scale
%{--
### scale needs doc

}
end

#timesObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/times.rb', line 49

def times 
%{--
### times(operator1, operator2)

* **operator1**
* **operator2**

Multiplication of the two operators. Can also be used with the form `operator1 * operator2`.

}
end

#triangleObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/functions/triangle.rb', line 50

def triangle 
%{--
### triangle(phase)

* **phase**

`phase` input 0.0-1.0 input is transformed into a triangle.

}
end