The Mjølner System: Bifrost
Bifrost is an interactive object-oriented graphics system
based on the Stencil & Paint imaging model. Bifrost
models computer graphics images by abstracting the geometric and
color properties of graphical objects. The important new concept
introduced in Bifrost is that there is one basic drawing
primitive, the graphical object. The graphical object unite
interaction, graphics modelling and graphics context. Bifrost
includes extensive support for various kinds of interaction:
interactive creation, reshaping, translation, scaling, and
rotation of graphical objects. The object-oriented approach makes
extensibility and tailorability a simple task, and facilitates
object-oriented drawing applications. One of the main goals of the
development of Bifrost was to make the graphics system independent
of underlying graphics and hardware systems.
Important concepts of Bifrost
- Canvas
-
Representation of the drawing surface, and the connection
between the display device and Bifrost. The canvas contains a
picture, and all graphics shown in the canvas must be in the canvas
picture.
- Shape
-
The shape describes the outline of the image, you want to display,
A shape is described by menas of segments. A segment is either a
straight line segment or a spline segment. Spline segments are
used to describe curves. The shape is analogous to the stencil in
the Stencil & Paint imaging model.
- Paint
-
The paint of Bifrost represent the color or raster to be pushed
through a shape, thus making the corresponding graphical object
appear on a canvas. The Paint can be simple solid colors using a
predefined name of the color or relative to some color space, e.g.
RGB, HSV, CMY. Tiles and rasters, e.g. scanned images, can also
be used as paint.
- Graphical Object
-
The graphical object concept constitute the composition of two
concepts shape and paint. The graphical object is the smallest unit
that can be displayed on a canvas.
- Picture
-
A picture is a collection of graphical objects, and realizes the
concept of graphics modelling. The graphical object is the
smallest possible entity that can be drawn, and is complete in the
sense, that it contains all necessary information about how the
graphical object appears on the canvas, and is therefore
independent of any other graphical objects in a picture.
The basic imaging model of Bifrost is thus very simple: define a
shape that represents the outline of the object you want to draw,
select a paint as the color for the object, construct a graphical
object with the shape and paint just defined, and draw the object
in a canvas, i.e. insert the graphical object into the canvas
picture. If the object must have several different colors the
object must be split into more graphical objects and assembled in
a picture. The picture is a graphical object itself, and can thus
be drawn in a canvas.
Example
The following complete program is a small example showing how to
make a simple Shape consisting of Line- and SplineSegments, and
then filling the Shape with a pink SolidColor. The resulting graphical object can later be reshaped and moved.
ORIGIN '~beta/bifrost/Bifrost';
INCLUDE '~beta/bifrost/private/Impl/debug';
INCLUDE '~beta/bifrost/ColorNames';
-- program: descriptor --
bifrost
(# theWindow: @window
(# theCanvas: @BifrostCanvas
(# aGO: @GraphicalObject;
aSolidColor: @SolidColor;
myShape: @Shape
(#
do (100,100) -> open;
(100,150) -> lineto;
(125,200) -> splineto;
(200,170) -> splineto;
(195,100) -> splineto;
close;
#);
eventhandler::
(#
onOpen::
(#
do aSolidColor.init;
pink -> aSolidColor.name;
aGO.init;
myShape -> aGO.setShape;
aSolidColor[]-> aGO.setpaint;
aGO[] -> draw;
aGO[] -> hilite;
#);
onMouseDown::
close;
#);
eventhandler::
(#
onOpen::
(#
do aSolidColor.init;
pink -> aSolidColor.name;
aGO.init;
myShape -> aGO.setShape;
aSolidColor[]-> aGO.setpaint;
aGO[] -> draw;
aGO[] -> hilite;
#);
onMouseDown::
(# exactPos: ^point;
do mousePos -> DeviceToCanvas -> mousePos;
(aGO[], mousePos)-> HitControl -> exactpos[];
(if exactpos[] <> NONE then
aGO[] -> unhilite;
(aGO[], exactPos, NoModifier)
-> interactiveReshape;
aGO[] -> hilite;
else
(if (theCanvas[],mousePos) -> aGO.containsPoint then
aGO[] -> unhilite;
(aGO[], mousePos, NoModifier)
-> interactiveMove;
aGO[] -> hilite;
if);
if);
#);
onKeyDown:: (# do terminate #);
#);
open::
(# do theWindow.size->size; #);
#);
open::
(# do (300,300)->size; theCanvas.open; #);
#);
do theWindow.open;
#)
More Information
For further information, see
Mjølner System: Bifrost - Tutorial.
Mjølner System: Bifrost - Reference Manual.
Bifrost is the luminous bridge, the rainbow, that leads from
Midgaard to Asgaard. Midgaard is the place where the human beings
live. Asgaard is the habitat of the gods in the middle of the
world.