Giter VIP home page Giter VIP logo

barionleg / numpbarg_to_coloris_austereich Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bouvens/number-to-color

0.0 0.0 0.0 521 KB

https://xperiments.xyz/number-to-color/ High-performance number to bright color converter https://www.npmjs.com/package/number-to-color

Home Page: https://barionleg.github.io/numpbarg_to_coloris_Austereich/

License: MIT License

JavaScript 100.00%

numpbarg_to_coloris_austereich's Introduction

JavaScript Number to Color converter

image

npm npm GitHub issues

An example of number to color conversion

This small and fast library maps a range of numbers to a circular palette of colors. It varies hue (with saturation and lightness equal to 1) and returns RGB in different formats.

import { numberToColor } from 'number-to-color'
// numberToColor(number from 0 to max โˆ’ 1, max)
const tenthColorOfSixteen = numberToColor(10, 16) // equals to { r: 0, g: 64, b: 255 }

Demo

You can see a live demo at https://bouvens.github.io/number-to-color. The source code of the demo is also available.

An example of usage is Griffeath's machine.

Usage and Formats

Run in a console:

npm i number-to-color

Include and call it in a wanted way:

// with memoization
import { numberToColor } from 'number-to-color'

const tenthColorOfSixteen = numberToColor(10, 16) // equals to { r: 0, g: 64, b: 255 }
// without memoization for numbers [0, 1)
import { mapColor } from 'number-to-color/map-color'

const tenthColorOfSixteen = mapColor(10 / 16) // equals to { r: 0, g: 64, b: 255 }
// convert a color you got to hex format
import { rgbToHex } from 'number-to-color/rgbToHex'

const tenthColorOfSixteen = rgbToHex({ r: 0, g: 64, b: 255 }) // equals to '#0040ff'

numberToColor

numberToColor(number, colors, shuffled, defaultColor)

The function calculates a color for every number and memoizes these values for each quantity of colors it was called with. number should be equal to or greater than 0 but less than colors.

Arguments

Name Type Default Description
number Number An integer number to convert
colors Number Number of colors, colors > number
shuffled Boolean false If true, shuffle memoized colors
defaultColor { r: Number, g: Number , b: Number } { r: 0, g: 0, b: 0 } A color to be returned for incorrect numbers

Returns

{ r: Number, g: Number, b: Number }

It's a color that corresponds to the number argument (0 <= r, g, b <= 255).

Sizes

With all (0) dependencies, minified and gzipped:

  • require('number-to-color') 358 B
  • require('number-to-color/map-color') 172 B
  • require('number-to-color/rgbToHex') 131 B

How to Run the Demo Locally

Run in a console:

git clone [email protected]:bouvens/number-to-color.git
cd number-to-color
npm install
npm run start

Then open http://localhost:8080 in a browser.

References

  • Check out an example of usage in Greffeath Machine cellular automata: demo, source code.
  • This library is inspired by Nano ID.

numpbarg_to_coloris_austereich's People

Contributors

barionleg avatar bouvens avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.