{"id":16858986,"url":"https://github.com/liabru/matter-attractors","last_synced_at":"2025-04-09T09:07:43.349Z","repository":{"id":50279261,"uuid":"81725731","full_name":"liabru/matter-attractors","owner":"liabru","description":"an attractors plugin for matter.js","archived":false,"fork":false,"pushed_at":"2023-03-30T15:09:50.000Z","size":7017,"stargazers_count":140,"open_issues_count":10,"forks_count":31,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T11:15:11.884Z","etag":null,"topics":["attractors","matter-js","physics","plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liabru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-02-12T12:54:53.000Z","updated_at":"2024-04-12T21:34:29.000Z","dependencies_parsed_at":"2023-10-03T04:32:40.764Z","dependency_job_id":null,"html_url":"https://github.com/liabru/matter-attractors","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liabru%2Fmatter-attractors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liabru%2Fmatter-attractors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liabru%2Fmatter-attractors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liabru%2Fmatter-attractors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liabru","download_url":"https://codeload.github.com/liabru/matter-attractors/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008630,"owners_count":21032556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["attractors","matter-js","physics","plugin"],"created_at":"2024-10-13T14:15:49.860Z","updated_at":"2025-04-09T09:07:43.326Z","avatar_url":"https://github.com/liabru.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# matter-attractors\n\n\u003e An attractors plugin for [matter.js](https://github.com/liabru/matter-js/)\n\n[![Build Status](https://travis-ci.org/liabru/matter-attractors.svg?branch=master)](https://travis-ci.org/liabru/matter-attractors)\n\nThis plugin makes it easy to apply continual forces on bodies.\nIt's possible to simulate effects such as wind, \n[gravity](https://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation) and \n[magnetism](https://en.wikipedia.org/wiki/Magnetism).\n\n## Demo\n\nSee the [demo](http://liabru.github.io/matter-attractors).\n\n[![matter-attractors](docs/demo.gif)](http://liabru.github.io/matter-attractors)\n\n## Install\n\nGet the [matter-attractors.js](build/matter-attractors.js) file directly or get it via npm:\n\n    npm install matter-attractors\n\n### Dependencies\n\n- [matter.js](https://github.com/liabru/matter-js/)\n\n## Usage\n\n```js\nMatter.use('matter-attractors');\n// or\nMatter.use(MatterAttractors);\n```\n\nSee [Using Plugins](https://github.com/liabru/matter-js/wiki/Using-plugins#using-plugins) for more information.\n\n### Custom attractors\n\nAttractors are just functions that are pushed to `body.plugin.attractors`.\nAn attractor function accepts two bodies `bodyA` and `bodyB`, where `bodyA` is \nalways the attracting body and `bodyB` is the body being attracted.\n\nThe attractor will be called against every other body in the engine in the place of `bodyB`,\non every engine update. If a force is returned, it will be applied to `bodyB` only.\n\n#### Basic usage\n\nAn example of a body that attracts other bodies to it:\n\n```js\nvar body = Matter.Bodies.circle(0, 0, 10, {\n  plugin: {\n    attractors: [\n      function(bodyA, bodyB) {\n        return {\n          x: (bodyA.position.x - bodyB.position.x) * 1e-6,\n          y: (bodyA.position.y - bodyB.position.y) * 1e-6,\n        };\n      }\n    ]\n  }\n);\n```\n\nIt's possible here to use collision filters too if needed, by using [Detector.canCollide](http://brm.io/matter-js/docs/classes/Detector.html#method_canCollide)\nand returning `null` to skip the pair.\n\n#### Advance usage\n\nIn advance usage, e.g. where forces apply to both bodies, instead of returning the force it can instead \nbe applied manually to both bodies inside the function using `Body.applyForce`.\n\n```js\nvar body = Matter.Bodies.circle(0, 0, 10, {\n  plugin: {\n    attractors: [\n      function(bodyA, bodyB) {\n        var force = {\n          x: (bodyA.position.x - bodyB.position.x) * 1e-6,\n          y: (bodyA.position.y - bodyB.position.y) * 1e-6,\n        };\n\n        // apply force to both bodies\n        Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));\n        Body.applyForce(bodyB, bodyB.position, force);\n      }\n    ]\n  }\n);\n```\n\n### Built in attractors\n\nThere are some attractors you can push to `body.plugin.attractors`:\n\n- `MatterAttractors.Attractors.gravity` - uses Newton's gravitational laws to apply an attractive force on both bodies\n\n## Documentation\n\nSee the [API docs](API.md).\n\n## Examples\n\nCheck out the [examples](docs/examples) or try them out first:\n\n- [Basic](http://liabru.github.io/matter-attractors#basic)\n- [Gravity](http://liabru.github.io/matter-attractors#gravity)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliabru%2Fmatter-attractors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliabru%2Fmatter-attractors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliabru%2Fmatter-attractors/lists"}