{"id":16014708,"url":"https://github.com/pmonks/gravity","last_synced_at":"2026-01-21T14:08:40.667Z","repository":{"id":148948974,"uuid":"228110457","full_name":"pmonks/gravity","owner":"pmonks","description":"Mathematically dubious riffs on Newton's law of universal gravitation","archived":false,"fork":false,"pushed_at":"2025-08-18T03:07:23.000Z","size":3660,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-18T05:23:00.393Z","etag":null,"topics":["2d-graphics","clojure","gravity","newton","simulation"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmonks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"COPYING","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-12-15T00:55:29.000Z","updated_at":"2025-08-18T03:07:25.000Z","dependencies_parsed_at":"2023-07-22T05:36:11.628Z","dependency_job_id":"28aa5592-5595-4e52-8b15-28bd3b25f58d","html_url":"https://github.com/pmonks/gravity","commit_stats":{"total_commits":188,"total_committers":1,"mean_commits":188.0,"dds":0.0,"last_synced_commit":"f8c1cdafd81baa57d6ae5911875d3d4654052a30"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pmonks/gravity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmonks%2Fgravity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmonks%2Fgravity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmonks%2Fgravity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmonks%2Fgravity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmonks","download_url":"https://codeload.github.com/pmonks/gravity/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmonks%2Fgravity/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28634790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d-graphics","clojure","gravity","newton","simulation"],"created_at":"2024-10-08T15:04:51.261Z","updated_at":"2026-01-21T14:08:40.660Z","avatar_url":"https://github.com/pmonks.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gravity\n\n[![Build](https://github.com/pmonks/gravity/workflows/CI/badge.svg?branch=main)](https://github.com/pmonks/gravity/actions?query=workflow%3ACI+branch%3Amain)\n[![Dependencies](https://github.com/pmonks/gravity/workflows/dependencies/badge.svg?branch=main)](https://github.com/pmonks/gravity/actions?query=workflow%3Adependencies+branch%3Amain)\n[![Open Issues](https://img.shields.io/github/issues/pmonks/gravity.svg)](https://github.com/pmonks/gravity/issues)\n[![License](https://img.shields.io/github/license/pmonks/gravity.svg)](https://github.com/pmonks/gravity/blob/main/COPYING)\n![Maintained](https://badges.ws/badge/?label=maintained\u0026value=yes,+at+author's+discretion)\n\nA micro codebase that plays around with some mathematically dubious riffs on Newton's law of universal gravitation, in order to produce some pretty (though unrealistic) animations:\n\n![Demo](demo.gif?raw=true \"Demo\")\n\nNote: actual animation is smoother than what's shown in this screencap.\n\n## Trying it Out\nClone the repo, then run:\n\n```shell\n$ clj -i init.clj -r\n```\n\nLook for the Java GUI window and bring it into focus; an initial random simulation will be running in it.  Press the 'q' key to close the window, or use the OS controls.\n\nTo run another random simulation, with between 50 and 200 randomly located objects:\n\n```clojure\n(gg/simulate width height (gu/gen-random-objs 50 200 width height))\n```\n\n## Code Structure\n\nThe code is divided into 2 primary namespaces: `gravity.core` and `gravity.gui`, and one supplementary namespace: `gravity.util`.\n\n### gravity.core\n\nThis ns contains pure logic for calculating the pseudo-gravitational effects a sequence of 'objects' has on one another.  Objects are simple maps with these keys (all of which are unitless numerical values):\n\n  * `:x` - x location\n  * `:y` - y location\n  * `:x-vel` - velocity in the horizontal dimension (optional, defaults to 0)\n  * `:y-vel` - velocity in the vertical dimension (optional, defaults to 0)\n  * `:mass` - mass of the object (optional, defaults to 1)\n\nTo step the objects, based on the (fudged) forces they exert on one another, the function `gravity.core/step-simul` may be called.  The first, mandatory, parameter is the sequence of objects to use as input, and it returns an equivalent sequence with all of the objects' positions and velocities updated.\n\nThe remaining, optional, parameters allow the caller to specify that the objects \"bounce\" at the edge of a given bounding box.  These parameters are:\n\n  2. `merge-collided-objects?` - boolean indicating whether to merge objects that have collided or not\n  3. `bounce-at-edge?` - boolean indicating whether edge bouncing is enabled or not\n  4. `min-x` - the minimum value of the horizontal dimension of the bounding box\n  5. `min-y` - the minimum value of the vertical dimension of the bounding box\n  6. `max-x` - the maximum value of the horizontal dimension of the bounding box\n  7. `max-y` - the maximum value of the vertical dimension of the bounding box\n\n\n### gravity.gui\n\nThis ns contains the logic related to displaying a simulation in a GUI window, currently via the [`clojure2d` library](https://github.com/Clojure2D/clojure2d).  The primary function here is `gravity.gui/simulate`, which takes these parameters:\n\n  1. `width` - the width of the window, in pixels\n  2. `height` - the height of the window, in pixels\n  3. `objs` - the sequence of objects to use in the simulation\n  4. `:trails true/false` - an optional flag that indicates whether the visualisation should have object trails or not (defaults to `false`)\n\nThe window runs independently of the calling thread, and terminates when the window is closed via OS mechanisms, or when the 'q' key is pressed while the window has focus.\n\nNote that this also means you can have any number of independent simulation windows open concurrently.\n\n### gravity.util\n\nIncludes a `gen-random-objs` fn that will create a random number of randomly located objects, with random velocities.\nIt takes four mandatory parameters:\n\n  1. `mini` - the minimum number of objects to create (inclusive)\n  2. `maxi` - the maximum number of objects to create (inclusive)\n  3. `width` - the maximum x coordinate to generate\n  4. `height` - the maximum y coordinate to generate\n\n## Contributor Information\n\n[GitHub project](https://github.com/pmonks/gravity)\n\n[Bug Tracker](https://github.com/pmonks/gravity/issues)\n\n## License\n\nCopyright © 2019 Peter Monks\n\nThis work is licensed under the [GNU Affero General Public License v3.0 or later](http://www.gnu.org/licenses/agpl-3.0.html).\n\nSPDX-License-Identifier: [AGPL-3.0-or-later](https://spdx.org/licenses/AGPL-3.0-or-later.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmonks%2Fgravity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmonks%2Fgravity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmonks%2Fgravity/lists"}