Skip to content

Commit 36f4499

Browse files
committed
Updates README.md
1 parent 0ca69ae commit 36f4499

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

README.md

+91-1
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,98 @@ You can advance them and they are guarantied to always stay in bounds.
5252
And they have a percentage-field that you may query, or even set and then query the value-field since the two of them are always kept in sync.
5353

5454
```C#
55-
Fader f = new Fader(0f, 500f);
55+
Fader f = new Fader(0f, 100f){value = 10};
56+
Assert.AreEqual(f.Value, 10, EPSILON);
57+
Assert.AreEqual(f.Percentage, 10, EPSILON);
58+
```
59+
60+
It can do the following:
61+
62+
* If you swap min and max in the constructor, those are switched back.
63+
* If you set the value outside the interval, the value is capped (constrained to the interval) automatically.
64+
* You can set or get the value using the Value property or the Percentage property. Those two correspond. Setting one corrects the other.
65+
* The boundaries are mutable after construction of the fader.
66+
* If you happen to cut your value while making the interval smaller, then the value (and the percentage) are corrected to point to the outer limits of the interval automatically.
67+
* You can invert the fader by setting the IsInverted property and reverse the direction while still adding values... Imagine you want to lerp from 0 to 50 and back to 0 again. You can now add 1 every update and add an if that will invert the fader if value > 50. Viola.
68+
69+
###### ValueChangedEvent
5670

71+
You may register a ValueChangedEvent to get notified if the value of that fader changes.
72+
73+
```c#
74+
[Test]
75+
public void ValueChangedEventIsThrownCorrectly()
76+
{
77+
double oldValue = 0;
78+
var f = new Fader(0, 100);
79+
f.ValueChanged += (sender, args) => { oldValue = args.OldValue; };
80+
81+
f.Value = 100;
82+
Assert.AreEqual(oldValue, 0, EPSILON);
83+
f.Value = 10;
84+
Assert.AreEqual(oldValue, 100, EPSILON);
85+
f.Value = 100;
86+
Assert.AreEqual(oldValue, 10, EPSILON);
87+
}
88+
```
89+
90+
91+
92+
###### Tweening
93+
94+
Faders can be used to do tweening. Therefore they provide accessors to get the value after some common formulas like so:
95+
96+
```c#
97+
[Test]
98+
public void QuadraticValueFadersWork()
99+
{
100+
var f = new Fader(20.0, 30.0) {Value = 25.0};
101+
Assert.IsTrue(f.QuadraticValue.Equals(22.5));
102+
Assert.AreEqual(f.QuadraticValue, 22.5, EPSILON);
103+
104+
f.QuadraticValue = 25.0;
105+
Assert.AreEqual(f.Value, 27.0710678118, EPSILON);
106+
}
107+
108+
[Test]
109+
public void CubicValueFadersWork()
110+
{
111+
var f = new Fader(20.0, 30.0) {Value = 25.0};
112+
Assert.AreEqual(f.CubicValue, 21.25, EPSILON);
113+
114+
f.CubicValue = 25.0;
115+
Assert.AreEqual(f.Value, 27.9370052598, EPSILON);
116+
}
117+
118+
[Test]
119+
public void ExponentialValueFadersWork()
120+
{
121+
var f = new Fader(20.0, 30.0) {Value = 25.0};
122+
Assert.AreEqual(f.ExponentialValue, 21.7360679775, EPSILON);
123+
124+
f.ExponentialValue = 25;
125+
Assert.AreEqual(f.Value, 28.0043710646, EPSILON);
126+
}
127+
128+
[Test]
129+
public void SlowStartValueFadersWork()
130+
{
131+
var f = new Fader(20.0, 30.0) {Value = 21.0};
132+
Assert.AreEqual(f.BidirectionalSlow, 20.24471741, EPSILON);
133+
134+
f.BidirectionalSlow = 28.0;
135+
Assert.AreEqual(f.Value, 27.0483276469, EPSILON);
136+
}
137+
138+
[Test]
139+
public void QuickStartValueFadersWork()
140+
{
141+
var f = new Fader(20.0, 30.0) {Value = 21.0};
142+
Assert.AreEqual(f.BidirectionalQuick, 22.44, EPSILON);
143+
144+
f.BidirectionalQuick = 28.0;
145+
Assert.AreEqual(f.Value, 29.2171633333, EPSILON);
146+
}
57147
```
58148

59149

0 commit comments

Comments
 (0)