|
1 | 1 | # Webgl Generative Particles <img src="https://github.com/react18-tools/webgl-generative-particles/blob/main/popper.png?raw=true" style="height: 40px"/> |
2 | 2 |
|
3 | | -[](https://github.com/react18-tools/webgl-generative-particles/actions/workflows/test.yml) [](https://codeclimate.com/github/react18-tools/webgl-generative-particles/maintainability) [](https://codecov.io/gh/react18-tools/webgl-generative-particles) [](https://www.npmjs.com/package/webgl-generative-particles) [](https://www.npmjs.com/package/webgl-generative-particles)  [](https://gitpod.io/from-referrer/) |
| 3 | +> This library is a Work In Progress... Feel free to request features, report bugs or contribute. |
| 4 | +> We will try to keep the APIs stable, however, some APIs might change. |
| 5 | +
|
| 6 | +[](https://github.com/react18-tools/webgl-generative-particles/actions/workflows/test.yml) [](https://codeclimate.com/github/react18-tools/webgl-generative-particles/maintainability) [](https://codecov.io/gh/react18-tools/webgl-generative-particles) [](https://www.npmjs.com/package/webgl-generative-particles) [](https://www.npmjs.com/package/webgl-generative-particles)  [](https://gitpod.io/from-referrer/) |
4 | 7 |
|
5 | 8 | "webgl-generative-particles" is an efficient WebGL-based generative particle system simulator designed for both React and vanilla JS applications. This system follows the mouse pointer, providing interactive and dynamic visual effects. It offers seamless integration with React (including React 18 and beyond) and Next.js, making it an ideal choice for modern frontend development. The simulator is customizable, compatible with various frameworks, and delivers high performance and real-time rendering for progressive web development. |
6 | 9 |
|
7 | | -✅ Fully Treeshakable (import from `webgl-generative-particles/client/loader-container`) |
| 10 | +✅ Fully Treeshakable (import from `webgl-generative-particles/react`) |
8 | 11 |
|
9 | 12 | ✅ Fully TypeScript Supported |
10 | 13 |
|
@@ -38,86 +41,60 @@ $ npm install webgl-generative-particles |
38 | 41 | $ yarn add webgl-generative-particles |
39 | 42 | ``` |
40 | 43 |
|
41 | | -## Want Lite Version? [](https://www.npmjs.com/package/webgl-generative-particles-lite) [](https://www.npmjs.com/package/webgl-generative-particles-lite) [](https://www.npmjs.com/package/webgl-generative-particles-lite) |
42 | | - |
43 | | -```bash |
44 | | -$ pnpm add webgl-generative-particles-lite |
45 | | -``` |
46 | | - |
47 | | -**or** |
48 | | - |
49 | | -```bash |
50 | | -$ npm install webgl-generative-particles-lite |
51 | | -``` |
52 | | - |
53 | | -**or** |
54 | | - |
55 | | -```bash |
56 | | -$ yarn add webgl-generative-particles-lite |
57 | | -``` |
58 | | - |
59 | | -> You need `r18gs` as a peer-dependency |
60 | | -
|
61 | | -### Import Styles |
| 44 | +## Usage |
62 | 45 |
|
63 | | -You can import styles globally or within specific components. |
| 46 | +```ts |
| 47 | +import { Particles } from "webgl-generative-particles/react"; |
64 | 48 |
|
65 | | -```css |
66 | | -/* globals.css */ |
67 | | -@import "webgl-generative-particles/dist"; |
| 49 | +<Particles |
| 50 | + fullScreenOverlay |
| 51 | + options={{ |
| 52 | + rgba: [0, 1, 0, 0.5], |
| 53 | + }} |
| 54 | +/> |
68 | 55 | ``` |
69 | 56 |
|
70 | | -```tsx |
71 | | -// layout.tsx |
72 | | -import "webgl-generative-particles/dist/index.css"; |
73 | | -``` |
74 | | - |
75 | | -For selective imports: |
76 | | - |
77 | | -```css |
78 | | -/* globals.css */ |
79 | | -@import "webgl-generative-particles/dist/client"; /** required if you are using LoaderContainer */ |
80 | | -@import "webgl-generative-particles/dist/server/bars/bars1"; |
81 | | -``` |
82 | | - |
83 | | -### Usage |
84 | | - |
85 | | -Using loaders is straightforward. |
86 | | - |
87 | | -```tsx |
88 | | -import { Bars1 } from "webgl-generative-particles/dist/server/bars/bars1"; |
89 | | - |
90 | | -export default function MyComponent() { |
91 | | - return someCondition ? <Bars1 /> : <>Something else...</>; |
| 57 | +### Simulator Options |
| 58 | + |
| 59 | +```ts |
| 60 | +export interface ParticlesOptions { |
| 61 | + /** particle Color @defaultValue [1, 0, 0, 1] -> red */ |
| 62 | + rgba?: [number, number, number, number]; |
| 63 | + /** @defaultValue 100_000 */ |
| 64 | + maxParticles?: number; |
| 65 | + /** @defaultValue 0.5 */ |
| 66 | + generationRate?: number; |
| 67 | + /** @defaultValue false */ |
| 68 | + overlay?: boolean; |
| 69 | + /** @defaultValue false */ |
| 70 | + mouseOff?: boolean; |
| 71 | + /** min and max Angles in radians: @defaultValue [-Math.PI, Math.PI] */ |
| 72 | + angleRage?: [number, number]; |
| 73 | + /** min and max age of particles in seconds */ |
| 74 | + ageRange?: [number, number]; |
| 75 | + /** [minSpeed, maxSpeed] */ |
| 76 | + speedRange?: [number, number]; |
| 77 | + /** Initial origin -> Will update as per mouse position when mouse moved if mouseOff is not set. |
| 78 | + * @defaultValue [0, 0] |
| 79 | + */ |
| 80 | + origin?: [number, number]; |
| 81 | + /** todo */ |
| 82 | + /** todo: WIP constant force [fx, fy] or a force field texture */ |
| 83 | + forceField?: Vector2D; //| Vector[][] | string; |
92 | 84 | } |
93 | 85 | ``` |
94 | 86 |
|
95 | | -For detailed API and options, refer to [the API documentation](https://react18-tools.github.io/webgl-generative-particles). |
96 | | - |
97 | | -**Using LoaderContainer** |
98 | | - |
99 | | -`LoaderContainer` is a fullscreen component. You can add this component directly in your layout and then use `useLoader` hook to toggle its visibility. |
| 87 | +## Creadits |
100 | 88 |
|
101 | | -```tsx |
102 | | -// layout.tsx |
103 | | -<LoaderContainer /> |
104 | | - ... |
105 | | -``` |
| 89 | +I have learnt the concepts from the following blogs and tutorials. |
106 | 90 |
|
107 | | -```tsx |
108 | | -// some other page or component |
109 | | -import { useLoader } from "webgl-generative-particles/dist/hooks"; |
110 | | - |
111 | | -export default MyComponent() { |
112 | | - const { setLoading } = useLoader(); |
113 | | - useCallback(()=>{ |
114 | | - setLoading(true); |
115 | | - ...do some work |
116 | | - setLoading(false); |
117 | | - }, []) |
118 | | - ... |
119 | | -} |
120 | | -``` |
| 91 | +- https://experiments.withgoogle.com/search?q=particles |
| 92 | +- https://nullprogram.com/blog/2014/06/29/ |
| 93 | +- https://gpfault.net/posts/webgl2-particles.txt.html |
| 94 | +- https://umbcgaim.wordpress.com/2010/07/01/gpu-random-numbers/ |
| 95 | +- https://www.youtube.com/playlist?list=PLjcVFFANLS5zH_PeKC6I8p0Pt1hzph_rt |
| 96 | +- https://stackoverflow.com/q/15215968/23175171 |
| 97 | +- https://stackoverflow.com/q/71021772/23175171 |
121 | 98 |
|
122 | 99 | ## License |
123 | 100 |
|
|
0 commit comments