Gravities - Serabe/rinzelight GitHub Wiki

Theory

A gravity is a function that calculates coordinates given two images (or their sizes).

They are useful for tasks like composing and cropping (cropping an image will be implemented in a near future).

The parameters take their names from composing. Destiny image is the one that will received the composition and the source is the one that is being added. For a deeper explanation, take a look at composing.

Practice

Imagine you want to compose an image in the upper border, but in the center. You would need a function that works out the proper coordinates. That function would be a gravity.

Defining a gravity.

The macro defgravity is provided in order to define new gravities. It needs the following parameters:

  • name: the name of the gravity.
  • params: a vector containing symbols for the width and height of both the destiny image and the source image, like [dw dh sw sh]
  • body: must return a new vector containing the coordinates like [x y].

Examples

Examples are provided in composition and cropping.

Composing gravities.

Two gravities can be composed. Composing gravities returns a new gravity whose first coordinated will be worked out by the first gravity and the second coordinate will be worked out by the second gravity.

Example

(compose-gravities north-east east north)

⚠️ **GitHub.com Fallback** ⚠️