-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use procs in derived nodes and animations (#468)
In order to optimize the number of nodes attached I decided to use proc node in many possible places
- Loading branch information
Showing
12 changed files
with
200 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { cond, lessThan, multiply } from '../base'; | ||
import { cond, lessThan, multiply, proc } from '../base'; | ||
|
||
export default function abs(a) { | ||
export default proc(function abs(a) { | ||
return cond(lessThan(a, 0), multiply(-1, a), a); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { set, add } from '../base'; | ||
import { set, add, proc } from '../base'; | ||
import AnimatedValue from '../core/InternalAnimatedValue'; | ||
|
||
const procAcc = proc(function(v, acc) { | ||
return set(acc, add(acc, v)); | ||
}); | ||
|
||
export default function acc(v) { | ||
const acc = new AnimatedValue(0); | ||
return set(acc, add(acc, v)); | ||
return procAcc(v, acc); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { sub, round } from '../base'; | ||
import { sub, round, proc } from '../base'; | ||
|
||
export default function ceil(a) { | ||
export default proc(function ceil(a) { | ||
return sub(1, round(sub(0.5, a))); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import { cond, block, defined, sub, set } from '../base'; | ||
import { cond, block, defined, sub, set, proc } from '../base'; | ||
import AnimatedValue from '../core/InternalAnimatedValue'; | ||
|
||
export default function diff(v) { | ||
const stash = new AnimatedValue(0); | ||
const prev = new AnimatedValue(); | ||
const procDiff = proc(function(v, stash, prev) { | ||
return block([ | ||
set(stash, cond(defined(prev), sub(v, prev), 0)), | ||
set(prev, v), | ||
stash, | ||
]); | ||
}); | ||
|
||
export default function diff(v) { | ||
const stash = new AnimatedValue(0); | ||
const prev = new AnimatedValue(); | ||
return procDiff(v, stash, prev); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import { cond, defined, set, add } from '../base'; | ||
import { cond, defined, set, add, proc } from '../base'; | ||
import AnimatedValue from '../core/InternalAnimatedValue'; | ||
import min from './min'; | ||
import max from './max'; | ||
import diff from './diff'; | ||
|
||
export default function diffClamp(a, minVal, maxVal) { | ||
const value = new AnimatedValue(); | ||
const procAcc = proc(function(a, minVal, maxVal, value) { | ||
return set( | ||
value, | ||
min(max(add(cond(defined(value), value, a), diff(a)), minVal), maxVal) | ||
); | ||
}); | ||
|
||
export default function diffClamp(a, minVal, maxVal) { | ||
const value = new AnimatedValue(); | ||
return procAcc(a, minVal, maxVal, value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { block, cond, defined, neq, not, set } from '../base'; | ||
import { block, cond, defined, neq, not, set, proc } from '../base'; | ||
import AnimatedValue from '../core/InternalAnimatedValue'; | ||
|
||
export default function onChange(value, action) { | ||
const prevValue = new AnimatedValue(); | ||
const procOnChange = proc(function(value, action, prevValue) { | ||
return block([ | ||
cond(not(defined(prevValue)), set(prevValue, value)), | ||
cond(neq(value, prevValue), [set(prevValue, value), action]), | ||
]); | ||
}); | ||
|
||
export default function onChange(value, action) { | ||
const prevValue = new AnimatedValue(); | ||
return procOnChange(value, action, prevValue); | ||
} |