npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sandy-image

v1.0.3

Published

Create a mesmerizing sand animation effect by drawing an `<img>` tag in grayscale using sand grains

Downloads

27

Readme

Sandy Image Library

The Sandy Image Library is a JavaScript library that creates a mesmerizing sand animation effect by drawing an <img> tag in grayscale using sand grains. The sand grains are dynamically repelled from the mouse or touch input, creating an interactive and visually appealing experience.

Features

  • Converts an image into a grayscale sand animation
  • Sand grains are repelled from the mouse or touch input
  • Customizable options for grain size, animation steps, and more
  • Smooth and efficient animation using a worker thread
  • Adjustable wind effect for dynamic animations

Installation

You can install the Sandy Image Library via npm:

npm install sandy-image

Alternatively, you can include the library files directly in your project:

<script src="path/to/sandy.js"></script>
<!-- Make sure sandy-worker.js, sandy-image.js and sandy-image_bg.wasm is in the same directory -->

Usage

  1. Create an instance of the SandyImage class, passing the selector of the target image and any desired options:

    const sandyImage = new SandyImage('#myImage', {
        size: 6,
        steps: 5,
        // Other options...
    });
  2. The library will automatically replace the target image with a canvas and start the sand animation.

  3. Customize the animation by providing options during initialization. The available options include:

    • size: The pixel size of each sand grain (default: 5). Bigger sizes result in a faster animation but reduces the detail in the final image.
    • steps: The number of grayscale steps the image should be converted into (default: 5). Smaller steps result in a faster animation, but values lower than 5 tend to have clear grayscale steps.
    • stepDepth: The artificial "depth" added to each grayscale step (default: 3). This makes it possible to use bigger sizes and smaller steps by adding an artificial detail to the final image. It also helps grains to not be dislodged (by the mouse or breeze) from "deep" cuts easily. Values between 2 and 5 tend to work well.
    • targetFPS: The target frames per second for the animation (default: 30).
    • dampingFactor: The damping factor for sand movement (default: 0.95). Values should be between 0 and 1.
    • repelRadius: The radius within which sand particles are repelled by the mouse or touch input (default: 20).
    • createGrainFn: A custom function for creating sand grains. It takes an object with properties canvasWidth, canvasHeight, size, and index as input and should return an object with x, y, vx, and vy properties for the initial grain's position and velocity.
    • breezeFn: A custom function for applying a breeze effect to the animation. It takes an object with properties frame, globalVx, and globalVy as input and should return an object with updated globalVx and globalVy values.
    • debug: Enable debug mode for performance logging (default: false).
  4. The sand animation will automatically respond to mouse or touch input, repelling the sand particles within the specified repelRadius.

Performance Considerations

Keep the grain count less than 20,000 for optimal performance. This can be achieved by editing the image ahead of time to have as much white space as possible and clear constrast between objects in the image. Use the debug option during development to monitor the animation's performance and frames per second (FPS).

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License

This library is released under the MIT License.