wishwash

1.0.5 • Public • Published

Wishwash

Wishwash takes 4 arguments: a value (usually an iterator), a min, a max, and an inclusive qualifier, and counts back and forth between the min and max to your value. Wishwash can be likened to the modulus operator but instead of being used as a single direction counter restarting at the beginning once reaching the max, Wishwash counts backwards once reaching the max, forwards again once reaching the min, and continues as such until reaching the value. This has various UI applications, including color animations and various motion demonstrations which otherwise wouldn't be possible without such an algorithm.


API

wishwash(number, number, number, boolean)

var wishwash = require('wishwash');

 


-- Example 1 --

for (i = 0; i < 30; i++) {
    console.log(wishwash(i, 6, 14, true))
}

Output will be:

6
7
8
9
10
11
12
13
14
13
12
11
10
9
8
7
6
7
8
9
10
11
12
13
14
13
12
11
10
9

   


-- Example 2 --

for (i = 0; i < 18; i++) {
    console.log(wishwash(i, 23, 28, false))
}

Output will be:

24
25
26
27
26
25
24
25
26
27
26
25
24
25
26
27
26
25

   


-- Example 3 --

randomArray = [...Array(90).keys()]
console.log(randomArray.map(i => wishwash(i, 134, 157, true)))

Output will be:

[134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,156,155,154,153,152,151,150,149,148,147,146,145,144,143,142,141,140,139,138,137,136,135,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,156,155,154,153,152,151,150,149,148,147,146,145,144,143,142,141,140,139,138,137]

 

Notes

Wishwash takes 4 arguments: a value (usually an iterator), a min, a max, and an inclusive qualifier, and counts back and forth between the min and max to your value. Wishwash can be likened to the modulus operator but instead of being used as a single direction counter restarting at the beginning once reaching the max, Wishwash counts backwards once reaching the max, forwards again once reaching the min, and continues as such until reaching the value. This has various UI applications, including color animations and various motion demonstrations which otherwise wouldn't be possible without such an algorithm.

Installation

With npm do

$ npm install wishwash

License

(MIT)

Copyright (c) 2019 David H. <email6@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i wishwash

Weekly Downloads

71

Version

1.0.5

License

MIT

Unpacked Size

9.96 kB

Total Files

4

Last publish

Collaborators

  • dvho