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

nice-waves

v1.0.1

Published

Beautiful animated waves

Downloads

1,347

Readme

nice-waves

Generate beautiful animated waves

What it does

nice-waves is a Vanilla JS library that makes creating waves a breeze

  • generates an svg with seamlessly looping wave paths based on passed options
  • animates flow and sway with pure javascript
  • provides a stop() / play() interface (with possibility to disable animation entierly)
  • allows randomization of most parameters, for unique waves on each render

Installation

npm

npm i nice-waves
import waves from 'nice-waves'

CDN

<script src="https://unpkg.com/nice-waves@latest"></script>

Usage

waves().mount()

Mount

mount((el = '#waves'))

Mounts waves at the specified mount point or (if none provided) first element element with id #waves

Expects el to be a query selector string or node element

Returns instance for chaining or false if couldn't mount

const mountPoint = document.getElementById('waves')
waves().mount(mountPoint)

// Equivalent to

waves().mount('#waves')

// Also equivalent to

waves().mount()

Animation

All animations are done in plain javascript with reqestAnimationFrame

There are two animation types: flow and sway

Flow is the x-axis scrolling motion

Sway is the up-down motion achieved by path morphing (each wave crest moves independently from the others, resulting in a more naturall and particularly nice effect)

Both can be disabled independently from each other by setting a corresponding rate to 0

All animation can be controlled with play() and stop() methods

stop()

Stops all animation if not already stopped

Returns instance

Waves will play by default after mount, so if you want them static, you can do this:

const myCoolWaves = waves().mount('#mountpoint').stop()

play()

Runs the animation if it's not yet running

If flowRate and swayRate are both set to 0, this will do nothing

Returns instance

Waves will play by default after mount

if (myCoolWaves && !myCoolWaves.animation.isPlaying) {
	myCoolWaves.play()
}

Options

You can customize waves by passing options like this:

waves({
	fills: ['rgba(73, 153, 147, 0.82)', 'rgba(57, 54, 109, 0.5)'],
	flowRate: 2,
	swayRate: 0.9,
	wavelength: 10,
	offset: 0.12
	// etc
})

For visual demonstration of what each option does, check out live demo

fills

Quantity and color of waves

If you want multiple waves of the same color, provide the same color multiple times

Array

Default value:

[ 'rgba(0, 0, 0, 0.65)',
  'rgba(0, 0, 0, 0.6)',
  'rgba(0, 0, 0, 0.5)' ]

flowRate

Speed of X-axis motion

Float, 0 - 50

Default value: 6

randomFlowRate

How much individual wave's flowRate is randomized

Float, 0 - 1

Default value: 0

swayRate

Speed of X-axis motion

Float, 0 - 5

Default value: 3.2

randomSwayRate

Coefficient of how much individual wave's swayRate is randomized

Float, 0 - 1

Default value: 0.4

swayVelocity

How far from initial shape the wave is allowed to sway

Float, 0 - 1

Default value: 0.5

wavelength

Length of one loop

Float, 1 - 20

Default value: 14

randomWavelength

Coefficient of how much individual wave's wavelength is randomized

Float, 0 - 1

Default value: 0

complexity

How many wave periods there are in one loop

Float, 1 - 10

Default value: 6

The more complex the wave is, the more oportunity for randomization For the same shape on every loop, set complexity to 1

randomHeight

How far from 100% amplitude each crest is allowed to go

Float, 0 - 1

Default value: 0.4

curviness

Fine-tune the wave curve

Float, 0 - 1

Default value: 0.8

offset

Offset each wave relative to previous one on the X-axis

Float, 0 - 1

Default value: 0

0 = all waves' crests are in sync, 1 = even spread

randomOffset

How much individual wave's offset is randomized

Float, 0 - 1

Default value: 0

License

MIT