0.0.30 • Published 6 years ago

template-blocks v0.0.30

Weekly downloads
105
License
-
Repository
github
Last release
6 years ago

Template Blocks

Build Status Coverage Status

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

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.10

6 years ago

0.0.11

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago