{"id":13406842,"url":"https://github.com/malerba118/react-particle-image","last_synced_at":"2025-04-04T10:08:41.140Z","repository":{"id":42087420,"uuid":"234668674","full_name":"malerba118/react-particle-image","owner":"malerba118","description":"Render images as interactive particles","archived":false,"fork":false,"pushed_at":"2023-03-01T02:03:05.000Z","size":4857,"stargazers_count":460,"open_issues_count":13,"forks_count":20,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-01T10:33:47.214Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://malerba118.github.io/react-particle-image-demo/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malerba118.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-01-18T02:09:00.000Z","updated_at":"2024-09-17T11:52:49.000Z","dependencies_parsed_at":"2023-01-28T23:46:20.921Z","dependency_job_id":"92b2b200-7d62-4565-861d-49e88beac6cc","html_url":"https://github.com/malerba118/react-particle-image","commit_stats":{"total_commits":30,"total_committers":2,"mean_commits":15.0,"dds":"0.19999999999999996","last_synced_commit":"ee69f73bcf73bffc365879e8774733cbcd356f2a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malerba118%2Freact-particle-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malerba118%2Freact-particle-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malerba118%2Freact-particle-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malerba118%2Freact-particle-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malerba118","download_url":"https://codeload.github.com/malerba118/react-particle-image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157283,"owners_count":20893220,"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":[],"created_at":"2024-07-30T19:02:40.752Z","updated_at":"2025-04-04T10:08:41.113Z","avatar_url":"https://github.com/malerba118.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","UI Components"],"sub_categories":["Photo / Image"],"readme":"# react-particle-image\n\n\u003e Render images as interactive particles\n\n[![NPM](https://img.shields.io/npm/v/react-particle-image.svg)](https://www.npmjs.com/package/react-particle-image) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n![react-particles-demo-3](https://user-images.githubusercontent.com/5760059/74112617-d6741a00-4b63-11ea-9757-81c55fe8e9b5.gif)\n\n## Install\n\n```bash\nnpm install --save react-particle-image\n```\n\n## Links\n\n- [Demo](https://malerba118.github.io/react-particle-image-demo/) ([source](https://github.com/malerba118/react-particle-image-demo/blob/master/src/App.tsx))\n- [Docs](https://malerba118.github.io/react-particle-image/interfaces/_particleimage_particleimage_.particleimageprops.html)\n\n\n## Simple Usage\n[codesandbox](https://codesandbox.io/s/react-particle-image-simple-ei97k)\n```tsx\nimport * as React from \"react\";\nimport ParticleImage, { ParticleOptions } from \"react-particle-image\";\n\nconst particleOptions: ParticleOptions = {\n  filter: ({ x, y, image }) =\u003e {\n    // Get pixel\n    const pixel = image.get(x, y);\n    // Make a particle for this pixel if blue \u003e 50 (range 0-255)\n    return pixel.b \u003e 50;\n  },\n  color: ({ x, y, image }) =\u003e \"#61dafb\"\n};\n\nexport default function App() {\n  return (\n    \u003cParticleImage\n      src={\"/react-logo.png\"}\n      scale={0.75}\n      entropy={20}\n      maxParticles={4200}\n      particleOptions={particleOptions}\n    /\u003e\n  );\n}\n```\n\n## Complex Usage\n [codesandbox](https://codesandbox.io/s/react-particle-image-complex-pbzo9)\n```tsx\nimport * as React from \"react\";\nimport useWindowSize from \"@rooks/use-window-size\";\nimport ParticleImage, {\n  ParticleOptions,\n  Vector,\n  forces,\n  ParticleForce\n} from \"react-particle-image\";\nimport \"./styles.css\";\n\nconst particleOptions: ParticleOptions = {\n  filter: ({ x, y, image }) =\u003e {\n    // Get pixel\n    const pixel = image.get(x, y);\n    // Make a particle for this pixel if blue \u003e 50 (range 0-255)\n    return pixel.b \u003e 50;\n  },\n  color: ({ x, y, image }) =\u003e \"#61dafb\",\n  radius: () =\u003e Math.random() * 1.5 + 0.5,\n  mass: () =\u003e 40,\n  friction: () =\u003e 0.15,\n  initialPosition: ({ canvasDimensions }) =\u003e {\n    return new Vector(canvasDimensions.width / 2, canvasDimensions.height / 2);\n  }\n};\n\nconst motionForce = (x: number, y: number): ParticleForce =\u003e {\n  return forces.disturbance(x, y, 5);\n};\n\nexport default function App() {\n  const { innerWidth, innerHeight } = useWindowSize();\n\n  return (\n    \u003cParticleImage\n      src={\"/react-logo.png\"}\n      width={Number(innerWidth)}\n      height={Number(innerHeight)}\n      scale={0.75}\n      entropy={20}\n      maxParticles={4000}\n      particleOptions={particleOptions}\n      mouseMoveForce={motionForce}\n      touchMoveForce={motionForce}\n      backgroundColor=\"#191D1F\"\n    /\u003e\n  );\n}\n```\n\n## Performance Tips\n`ParticleImage` has a target frame rate of 30fps, but with thousands of particles updating positions and repainting 30 times per second, performance can be a problem.\n\nIf animations are choppy try:\n- Reducing the number of distinct particle colors (particles of the same color will be batched while painting)\n- Reducing the number of particles (less than 6000 is ideal)\n- Reducing the resolution of the src image.\n\nHere's a [codesandbox of a good boy](https://codesandbox.io/s/react-particle-image-multicolor-dp8up) to show what I mean. Note the `round` function to reduce the number of colors painted on the canvas.\n\n\nMIT © [malerba118](https://github.com/malerba118)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalerba118%2Freact-particle-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalerba118%2Freact-particle-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalerba118%2Freact-particle-image/lists"}