Saturday, April 21, 2012

Movimentum - Design of the language - Notation

Thinking a little bit about the implementation, the vector constraints we have written are actually constraints on scalar variables. For example,

    Crank.Q = Crank.P + [_,0];

actually means

    Crank.Q.x = Crank.P.x + _;
    Crank.Q.y = Crank.P.y;

Here, we can view .x and .y as predefined operators. Similiarly, the .rotate in

    Crank.Q = Crank.P + [c,0].rotate(180° * t)

is a predefined operator. From this meager data, I infer that I want "predefined things" to have the form dot-identifier. Therefore, I change the integral operator such that the "braking constraint" reads

    w = .integral(b) + 180;

Similarly, we can define additional operators:

    .angle(vector,vector)
    .differential(scalar)
    .differential(vector)
    .length(vector)

For lazyness, I would also allow single-letter abbreviations for the most important operators: .a for angle, .i for integral, .d for differential, .l for length.

In the same vein, I also change t to .t:

    Crank.Q = Crank.P + [c,0].rotate(180° * .t)

When I thought about more things that should be animated, I found that I might want to change the color of something over time - e.g. to show that somthing gets hotter. A simple idea is to give each object something like

    .red
    .green
    .blue

which are scalars that are added to or subtracted from each (non-transparent) pixel in a picture. Or maybe there's a different way to change the color - e.g. along a line of rainbow colors. For the simulation, this is simply another variable that takes part in the constraint satisfaction machinery.

A last  problem: We will need some sort of initial parameters - e.g., the number of frames per time unit or a unit for angles (when we use trigonometric functions). For this, I define a construct

.config(12, // number of  frames per time unit
        °); // unit of angles

The order of the parameters is fixed, and there are no keywords. This is as inconvenient as it gets, but for a construct used only once per animation, I don't care.

No comments:

Post a Comment