0.0.30 • Published 6 years ago
template-blocks v0.0.30
Template Blocks
Examples
Basic example
// Timestamp generator
const ts = new Timestamp();
// A snapshot of the current timestamp
const snapshot = ts.get();
// A constant containing the previous snapshot
const now = new Const(snapshot);
// The time since the code was executed
const delta = new Diff(ts, now);
setInterval(function() {
console.log(delta.get());
}, 500);Basic example - compact writing
// Timestamp generator
const ts = new Timestamp();
// The time since the code was executed
const delta = ts.pipe(Diff, ts.toConst());
setInterval(function() {
console.log(delta.get());
}, 500);Advanced example
const loop = new Loop();
const mousePosition = new GetMousePosition();
const mousePositionSnapshot = mousePosition.toVar();
const mouseMoving = new Var(false)
.execute(function() {
const snapshot = mousePosition.toConst();
const equal = snapshot.pipe(Equals, mousePositionSnapshot);
mousePositionSnapshot.set(snapshot);
return equal;
})
.evaluatePeriodically(loop);
const lightIntensity = new Var(0)
.execute(function(ref) {
return ref
.pipe(
Add,
new If(mouseMoving, new Const(1), new Const(-1))
.pipe(Mul, new Const(4))
.pipe(Mul, loop.dt)
)
.pipe(Clamp, new Const(0), new Const(1));
})
.observe(console.log)
.evaluatePeriodically(loop);0.0.30
6 years ago
0.0.29
6 years ago
0.0.28
6 years ago
0.0.27
7 years ago
0.0.26
7 years ago
0.0.25
7 years ago
0.0.24
7 years ago
0.0.23
7 years ago
0.0.22
7 years ago
0.0.21
7 years ago
0.0.20
7 years ago
0.0.19
7 years ago
0.0.18
7 years ago
0.0.15
7 years ago
0.0.14
7 years ago
0.0.13
7 years ago
0.0.12
7 years ago
0.0.10
7 years ago
0.0.11
7 years ago
0.0.7
7 years ago
0.0.6
7 years ago
0.0.5
7 years ago
0.0.4
7 years ago
0.0.3
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago