Babelsberg-js

A JavaScript/LivelyKernel implementation of Babelsberg

View the Project on GitHub babelsberg/babelsberg-js

Babelsberg/JS

Build Status

Overview

Babelsberg/JS is a JavaScript implementation of the Babelsberg family of object constraint programming languages, which augments standard JavaScript with the ability to state constraints that should be automatically maintained. Here is a simple example:

z3 = new ServerZ3()
z3.reset()
a = lively.morphic.Morph.makeRectangle(0, 0, 10, 10)
b = lively.morphic.Morph.makeCircle(pt(0,0), 10)
always: {
    solver: z3
    a.getPosition().dist(b.getPosition()) == 200
}
a.getPosition() // lively.pt(0.5,-200.0)
b.getPosition() // lively.pt(0.0,0.0)

a.setPosition(pt(100, 100))
a.getPosition() // lively.pt(100.0,100.0)
b.getPosition() // lively.pt(99.9,300.0)

It allows the programmer to write constraints using the always primitive that you always want to hold using existing object-oriented abstractions. (The above example uses the methods getPosition and dist.) The system will then attempt to satisfy the constraints at the time they are asserted, and maintain them as further statements perturb the system. The extent to which the system is able to keep constraints satisfied depends on the solver that is used. This implementation provides Z3, DeltaBlue, and Cassowary.

We have used this to implement electrical simulations, a simulation of the Lively Engine, and some graphical layouting examples. The implementation is available to try at lively-web.org. At any given time it may be broken, though, because the code is changing fairly often.

Download

A JavaScript/LivelyKernel implementation of Babelsberg licensed under 3-clause BSD

Download minified version of Babelsberg/JS. (includes Prototype.js)

If you already use Prototype.js you can download a smaller version of Babelsberg/JS without Prototype.js.

Examples

A page with additional examples is at lively-kernel.org.

Publications

Documentation

Contribute

Report issues on the issues page.

See also

Babelsberg in other languages:

timfel also presented this work at the CRAFT conference. A video of his talk is available here.

HPI Logo Created under a grant from the Hasso Plattner Institute, with additional support from SAP and the Communications Design Group.