Skip to content

fantasyui-com/decrement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

decrement

Decrement random value in array. Image below demonstrates random decrements in rgb(255,255,255) structure.

Distribution Example

(See sample output test.html for full dataset)

// install decrement
npm i -S decrement

// load
const decrement = require("decrement");

// cap at range of 0..255
const control = decrement({min:0, max:255});

// helper rate change
const rnd = function (min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// insert objects
control.insert ( { kind: 'red'   , value: 255 } ) ;
control.insert ( { kind: 'green' , value: 255 } ) ;
control.insert ( { kind: 'blue'  , value: 255 } ) ;

// while above 0
while( control.total() > 0){

  // find blue and change by a random value in range -2..1
  control.change({kind: 'blue'},  rnd(-2,1));

  // find green and change by a random value in range -2..1
  control.change({kind: 'green'}, rnd(-2,1));

  // find red and change by a random value in range -2..1
  control.change({kind: 'red'},   rnd(-2,1));

  // print some html
  console.log( '<div style="background: rgb(' + control.data().map(i=>i.value).join() + '); height:1px;"></div>' );
}

About

Auto decrement value at preset rate. [Library, Algorithm, CSS]

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published