0.0.30 • Published 5 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
5 years ago
0.0.29
5 years ago
0.0.28
5 years ago
0.0.27
5 years ago
0.0.26
5 years ago
0.0.25
5 years ago
0.0.24
5 years ago
0.0.23
5 years ago
0.0.22
5 years ago
0.0.21
5 years ago
0.0.20
5 years ago
0.0.19
5 years ago
0.0.18
5 years ago
0.0.15
5 years ago
0.0.14
5 years ago
0.0.13
5 years ago
0.0.12
5 years ago
0.0.10
5 years ago
0.0.11
5 years ago
0.0.7
5 years ago
0.0.6
5 years ago
0.0.5
5 years ago
0.0.4
5 years ago
0.0.3
5 years ago
0.0.2
5 years ago
0.0.1
5 years ago