Grav: Imbuing Webpages with a Sense of Gravity

In the digital universe, the laws of physics are but a script away. The GitHub open-source project Grav, curated by glomadrian, is a JavaScript library that gifts webpages with the enigmatic force of gravity. Leveraging the power of TypeScript and Canvas, Grav ensures a simple and user-friendly experience to those wishing to add a gravitational touch to their web environments.

At its core, Grav's capabilities include:

  1. Gravity Emulation: Grav's main spectacle is the emulation of gravity effects within a webpage.
  2. Versatile Gravity Modes: Catering to different artistic visions, Grav supports multiple gravity modes.
  3. Customizable Gravity Parameters: Tailoring gravity to one's whim is made possible with adjustable gravity parameters.

The journey to implementing Grav begins with adding the following dependency to your webpage:

<script src="https://cdnjs.cloudflare.com/ajax/libs/grav/1.2.0/grav.min.js"></script>

Here’s a snippet of how Grav might be employed:

// Creating a gravitational field
const gravity = new Grav(canvas);

// Setting gravity mode
gravity.setMode(Grav.MODE_VERTICAL);

// Customizing gravity parameters
gravity.setGravity(1000);

// Adding an object to feel the force
gravity.addObject(new Object(100, 100));

Upon executing the above, a gravitational field is established on the canvas, with an object added to it, now subject to the whims of gravity.

Grav's versatility shines through its different gravity modes. Whether the force pulls objects vertically, drags them horizontally, or lets them roam freely is a matter of a simple mode switch:

// The object now falls vertically
gravity.setMode(Grav.MODE_VERTICAL);

// Or perhaps horizontally
gravity.setMode(Grav.MODE_HORIZONTAL);

// Or maybe it moves freely
gravity.setMode(Grav.MODE_FREE);

Customizing gravity’s pull is as straightforward as:

// Setting a stronger gravitational pull
gravity.setGravity(1000);

// Or maybe defying gravity
gravity.setGravity(-1000);

Grav stands as a robust and versatile library, letting your creative ideas descend or ascend in the digital space, bound only by the gravitational parameters you set.